static void Compute_Blend2(void)
{
	long unsigned int x;

	for(x=ARRAY_EL/2; x<ARRAY_EL; x++) {
        	output[x].red   = (input1[x].red + input2[x].red) / 2;
        	output[x].green = (input1[x].green + input2[x].green) / 2;
        	output[x].blue  = (input1[x].blue + input2[x].blue) / 2;
	}

}

static void Animate(void)
{

	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();

	//long unsigned int i;
	long unsigned int counter1, counter2, counter3;

double time3, time4;

gettimeofday(&stime1, NULL);

Compute_Blend();
//Compute_Blend2();

gettimeofday(&etime1, NULL);
time3=((double)(etime1.tv_sec*1000000-stime1.tv_sec*1000000+etime1.tv_usec-stime1.tv_usec))/1000000;

	//alpha();

//glEnable(GL_TEXTURE_2D);

//glBindTexture(GL_TEXTURE_2D, 1);
/*
glTexImage2D(GL_TEXTURE_2D,
    100,
    GL_RGBA,
    X,
    Y,
    0,
    GL_RGBA,
    GL_UNSIGNED_BYTE,
    &output);

//glDisable(GL_TEXTURE_2D);

glColor3f(255, 0 , 0);
glBegin(GL_QUADS);
   //glTexCoord2f( 500, 500);
   glVertex2f( 0, 0 );

   //glTexCoord2f( 1000, 0);
   glVertex2f( 500, 0);

   //glTexCoord2f( 1000, 1000);
   glVertex2f( 500, 500);

   //glTexCoord2f( 0,1000);
   glVertex2f( 0, 500);
glEnd();
*/

        //glColor3f( 1.0, 1.0, 0.0 );
        //glutSolidSphere( 500, 500, 0 );




//for(counter1=0; counter1 < Y; counter1++) {
/*
        glBegin(GL_POINTS);
        for(counter2=0; counter2 < Y; counter2++) {
                for(counter3=0; counter3 < X; counter3++) {

                        glColor3f(output[counter2*X+counter3].red, output[counter2*X+counter3].green, output[counter2*X+counter3].blue);
                        glVertex2f(counter3, counter2);           
                }
        }
        glEnd();	
//}
*/

counter3=0;
int calc;

for(counter1=0; counter1 < RES; counter1+=X) {
	glBegin(GL_POINTS);
	calc = counter3*X;
	for(counter2=0; counter2 < X; counter2++) {
		//if(output[counter2+calc].alpha != 255){
	 		glColor3f(output[counter2+calc].red, output[counter2+calc].green, output[counter2+calc].blue);
	 		glVertex2f( counter2, counter3);
		//}
	}
	glEnd();
	counter3++;
}


	glFlush();
	glutSwapBuffers();
	glutPostRedisplay();

	time2++;

//	gettimeofday(&endtime, NULL);
//	time1=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;

        if (time2 == 25)
        {
        gettimeofday(&endtime, NULL);
        time1=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;
                

                fps = time2 / time1;
		printf("Time of last opencl call: %lf\n", time3);
                printf("fps: %lf - %lf frames in %lf seconds\n", fps, time2, time1);
                gettimeofday(&starttime, NULL);
                time2 = 0;

	}
}

void OpenGLInit(void)           
{       
        glShadeModel( GL_FLAT );
        glClearColor( 0.0, 0.0, 0.0, 0.0 );
        glClear(GL_COLOR_BUFFER_BIT);
        glDisable( GL_DEPTH_TEST );

	//glClearDepth(100.0f);							// Depth Buffer Setup
	//glEnable(GL_DEPTH_BUFFER_BIT);
	//glEnable(GL_DEPTH_TEST);						// Enables Depth Testing
	//glEnable(GL_DEPTH_TEST);
	//glDepthMask(GL_TRUE);
	//glEnable(GL_TEXTURE_3D);

	//glDepthFunc(GL_LEQUAL);							// The Type Of Depth Test To Do

}
        
        
static void ResizeWindow(int w, int h)  
{
        float aspectRatio;
        h = (h == 0) ? 1 : h;
        w = (w == 0) ? 1 : w;
        glViewport( 0, 0, w, h );       // View port uses whole window
        aspectRatio = (float)w/(float)h;

        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
	//glOrtho(0,w,0,h,-100,100);
        glOrtho (0, w, h, 0, 0, 1);
        glMatrixMode( GL_MODELVIEW );
	
}       

void createGLUTMenus() { 
        
        int menu;

        // create the menu and
        // tell glut that "processMenuEvents" will
        // handle the events
        menu = glutCreateMenu(processMenuEvents);
        
        //add entries to our menu
        //glutAddMenuEntry("Settings",SETTINGS);
        glutAddMenuEntry("Restart",RESTART);
        glutAddMenuEntry("Pause",PAUSED);
        glutAddMenuEntry("Exit",EXIT);

        // attach the menu to the right button
        glutAttachMenu(GLUT_RIGHT_BUTTON);
}   

void processMenuEvents(int option) {
        
        switch (option) {
                        
                case RESTART :
			printf("nothing here!\n");
			break;
                case PAUSED : 
			printf("nothing here!\n");
                        break;
                case EXIT :
			free_memory();
                        exit (0);  
                        break;
        }
}

