#include "ofUtils.h"



//--------------------------------------------------
int ofGetWidth(){
	return glutGet(GLUT_WINDOW_WIDTH);
}
//--------------------------------------------------
int ofGetHeight(){
	return glutGet(GLUT_WINDOW_HEIGHT);
}

//--------------------------------------
int ofGetElapsedTimeMillis(){
	return (int)(glutGet(GLUT_ELAPSED_TIME));
}

//--------------------------------------
float ofGetElapsedTimef(){
	return (float)(glutGet(GLUT_ELAPSED_TIME))/1000.0f;
}

//--------------------------------------------------
int ofGetSeconds(){
	time_t 	curr;
	tm 		local;
	time(&curr);
	local	=*(localtime(&curr)); 
	return local.tm_sec; 
}

//--------------------------------------------------
int ofGetMinutes(){
	time_t 	curr;
	tm 		local;
	time(&curr);
	local	=*(localtime(&curr)); 
	return local.tm_min; 
}

//--------------------------------------------------
int ofGetHours(){
	time_t 	curr;
	tm 		local;
	time(&curr);
	local	=*(localtime(&curr)); 
	return local.tm_hour; 
}


void ofHuntForBlendFunc(float period, int defaultSid, int defaultDid){
	
	// created by g. levin in a late-night moment of brilliance
	// sets all possible (24) combinations of blend functions,
	// changing modes every period seconds. 
	
	int sfact[] = {
		GL_DST_COLOR, 
		GL_ONE_MINUS_DST_COLOR, 
		GL_SRC_ALPHA_SATURATE
	};
		
	int dfact[] = {
		GL_ZERO,
		GL_ONE,
		GL_SRC_COLOR,
		GL_ONE_MINUS_SRC_COLOR,
		GL_SRC_ALPHA,
		GL_ONE_MINUS_SRC_ALPHA,
		GL_DST_ALPHA,
		GL_ONE_MINUS_DST_ALPHA
	};
	
	
	if ((defaultSid == -1) && (defaultDid == -1)) {

		int sid =  ((int)(ofGetElapsedTimef()*1000)/(8*(int)(period*1000)))%8;
		int did =  ( (int)(ofGetElapsedTimef()*1000)/(int)((period)*1000))%8;
		
		glEnable(GL_BLEND);
		glBlendFunc(dfact[sid], dfact[did]);
		printf("SRC %d	DST %d\n", sid, did);
		
	} else {
		glEnable(GL_BLEND);
		glBlendFunc(dfact[defaultSid], dfact[defaultDid]);
		
	}



}

