#include <GL/glut.h>
#include <string>
#include <strstream>
#include <vector>

#include "parametres.h"
#include "CPointChaud.h"
#include "globale.h"
#include "CWinStream.h"
#include "gl_run.h"

void RajoutePoint(int, int);


CWinStream wout;
float Temperatures[DIV_X][DIV_Y];
std::vector<CPointChaud> LesPoints;
const float MILIEU = (TEMPMAX + TEMPMIN) / 2;
const float DIFF = TEMPMAX - TEMPMIN;
int WIN_X = 500;
int WIN_Y = 500;
bool COULEUR = true;


void reshape(int w, int h)
{
	glViewport(0, 0, (GLsizei) w, (GLsizei) h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, DIV_X - 1, DIV_Y - 1, 0, -1.0, 1.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	wout.SetToWindow();
	WIN_X = w;
	WIN_Y = h;
}


void mouse(int button, int state, int x, int y)
{
	RajoutePoint(x * DIV_X / WIN_X, y * DIV_Y / WIN_Y);
}

void keyboard(unsigned char key, int x, int y)
{
	switch(key)
	{
	case (27) : exit(0); break;
	case ' ' : COULEUR ^= true; break;
	}
}


void init(void)
{
	glClearColor(0, 0, 0, 0);
	for (int i = 0; i < DIV_X; i++)
		for (int j = 0; j < DIV_Y; j++)
			Temperatures[i][j] = T0;

	glEnable(GL_POINT_SMOOTH);
	glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
}


int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(WIN_X, WIN_Y);
	glutInitWindowPosition((glutGet(GLUT_SCREEN_WIDTH) - WIN_X) >> 1,
						   (glutGet(GLUT_SCREEN_HEIGHT) - WIN_Y) >> 1);
	glutCreateWindow("Propagation de la chaleur");

	init();

	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutMouseFunc(mouse);
	glutDisplayFunc(display);
	glutIdleFunc(run);

	glutMainLoop();

	return 0;
}
