| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 
 | #include <iostream>
#include <fstream>
 
#include"GL\glut.h"
 
using namespace std;
 
void LabyAffichage();
void LabyRedim();
void OuvrirNiveau(char* niveau);
void LibererMemoire();
void DessinerNiveau();
 
char** Matrice = NULL;
int NbColonnes = 10, NbLignes = 8;
 
 
void main(void)
{
	OuvrirNiveau("niveau.txt");
 
 
	glutInitWindowPosition(10,10);
	glutInitWindowSize(500,500);
	glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
	glutCreateWindow("Labyrinthe");
	glutDisplayFunc(LabyAffichage);
	glutReshapeFunc(LabyRedim);
	glutMainLoop();
 
}
 
void LabyAffichage()
{
	glClearColor(1.0, 1.0, 1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
 
	DessinerNiveau();
 
	glFlush();
}
 
void LabyRedim(int x, int y)
{
	glViewport(0, 0, x, y);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, (double)NbColonnes, (double)NbLignes, 0.0);
}
 
void OuvrirNiveau(char* niveau)
{
	ifstream fichier;
	fichier.open(niveau);
 
	if(!fichier) 
	{
		cout<<"Erreur lors de l'ouverture du ficher!" << endl;
		system("pause");
		exit(1);
	}
 
	fichier>> NbColonnes;
	fichier>> NbLignes;
 
	Matrice = new char*[NbColonnes];
	for(int i=0;i<NbColonnes; i++)
	{Matrice[i] = new char[NbLignes];}
 
	for(int i=0; i<NbColonnes; i++)
		for(int j=0; j<NbLignes; j++)
			Matrice[i][j] = '0';
 
	for(int j=0; j<NbLignes; j++)
		for(int i=0; i<NbLignes; i++)
			fichier >> Matrice[i][j];
 
	fichier.close();
}
 
void LibererMemoire()
{
	if(Matrice !=NULL)
	{
		for(int i=0; i<NbColonnes; i++)
			delete [] Matrice[i];
		delete [] Matrice;
	}
}
 
void DessinerNiveau()
{
	glColor3d(0.5,0.5,0.5);
 
	glBegin(GL_QUADS);
 
	for(int i=0; i<NbColonnes; i++)
		for(int j=0; j<NbLignes; j++)
			if(Matrice[i][j] == '0')
			{
				glVertex2d(i,   j);
				glVertex2d(i,   j+1);
				glVertex2d(i+1, j+1);
				glVertex2d(i+1, j);
			}
			glEnd();
} | 
Partager