#include "type_image.h"

type_image* PtrImg;

#include <GL/glut.h>

void display(void);

void afficher(type_image& Img)
{
	int argc = 0;
	char **argv = new char*[1];
	argv[0] = new char[strlen("c:\\moi\\projets\\Image Process\\Debug\\Image Process.exe\0")];
	strcpy(argv[0], "c:\\moi\\projets\\Image Process\\Debug\\Image Process.exe\0");
	
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(Img.Width, Img.Height);
	glutInitWindowPosition( (glutGet(GLUT_SCREEN_WIDTH) - Img.Width)/ 2.0, (glutGet(GLUT_SCREEN_HEIGHT) - Img.Height)/2.0);
	glutCreateWindow("Martin is hot!");
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, Img.Width, -Img.Height, 0.0);	
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glutIdleFunc(NULL);
	glutDisplayFunc(display);

	PtrImg = &Img;
	glutMainLoop();
}

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
#if 0
	glBegin(GL_POINTS);
	for (int i = 0; i < PtrImg->Width; i++)
		for (int j = 0; j < PtrImg->Height; j++)
		{
			glColor3f((*PtrImg)(i, j, ROUGE), (*PtrImg)(i, j, VERT), (*PtrImg)(i, j, BLEU));
			glVertex2i(i, -j);
		}
	glEnd();

#else

	glBegin(GL_QUADS);
	for (int i = 0; i < PtrImg->Width; i++)
		for (int j = 0; j < PtrImg->Height; j++)
		{
			glColor3f((*PtrImg)(i, j, ROUGE), (*PtrImg)(i, j, VERT), (*PtrImg)(i, j, BLEU));
			glVertex2i(i, -j);
			glVertex2i(i+1, -j);
			glVertex2i(i+1, -j-1);
			glVertex2i(i, -j-1);
		}
	glEnd();
#endif
	glutSwapBuffers();
}
