Salut, je débute en OpenGl(et glut) et je suis déjà bloquer, j'ai essayer de faire un cube, mais les faces ce chevauche. Je sais que pour éviter ce problème il faut utiliser le buffer-z, mais comment l'utiliser sans windows.h ?
Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
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
109
110
111
112
113
114
115
116
117
#include <gl/glut.h>
 
void Clavier(unsigned char touche,int x,int y);
void Reshape(int w, int h);  
void Affichage();  
 
int main( int argc, char** argv)
{   
    glutInit(&argc, argv);
 
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(250, 250); 
    glutInitWindowPosition(500, 300);  
 
    glutCreateWindow("OpenGL");
    glClearColor(0.0,0.0,0.0,0.0);
    glutReshapeFunc(Reshape);
    glutDisplayFunc(Affichage);
	glutKeyboardFunc(Clavier);
    glutMainLoop();
    return 0;
}
 
void Affichage()
{ 
 glClear(GL_COLOR_BUFFER_BIT);
 glMatrixMode(GL_MODELVIEW) ;
 glLoadIdentity();
 
 gluLookAt(7,7,-10,0,0,0,0,1,0);
 
			glBegin (GL_QUADS); 
			glColor3d(1.0f, 0.f, 0.0f);
				glVertex3i (-1,-1,1); // 1
			glColor3d(0.0f, 1.f, 0.0f);
				glVertex3i (-1,1,1);
			glColor3d(0.0f, 0.f, 1.0f);
				glVertex3i (1,1,1);
			glColor3d(1.0f, 1.f, 1.0f);
				glVertex3i (1,-1,1);
			glColor3d(1.0f, 0.f, 0.0f);
				glVertex3i (-1,-1,-1); // 2
			glColor3d(0.0f, 1.f, 0.0f);
				glVertex3i (-1,1,-1);
			glColor3d(0.0f, 0.f, 1.0f);
				glVertex3i (1,1,-1);
			glColor3d(1.0f, 1.f, 1.0f);
				glVertex3i (1,-1,-1);
			glColor3d(1.0f, 0.f, 0.0f);
				glVertex3i (-1,1,-1); // 3
			glColor3d(0.0f, 1.f, 0.0f);
				glVertex3i (1,1,-1);
			glColor3d(0.0f, 0.f, 1.0f);
				glVertex3i (1,1,1);
			glColor3d(1.0f, 1.f, 1.0f);
				glVertex3i (-1,1,1);
			glColor3d(1.0f, 0.f, 0.0f);
				glVertex3i (-1,-1,-1); // 4
			glColor3d(0.0f, 1.f, 0.0f);
				glVertex3i (1,-1,-1);
			glColor3d(0.0f, 0.f, 1.0f);
				glVertex3i (1,-1,1);
			glColor3d(1.0f, 1.f, 1.0f);
				glVertex3i (-1,-1,1);
			glColor3d(1.0f, 0.f, 0.0f);
				glVertex3i (-1,-1,-1); // 5
			glColor3d(0.0f, 1.f, 0.0f);
				glVertex3i (-1,-1,1);
			glColor3d(0.0f, 0.f, 1.0f);
				glVertex3i (-1,1,1);
			glColor3d(1.0f, 1.f, 1.0f);
				glVertex3i (-1,1,-1);
			glColor3d(1.0f, 0.f, 0.0f);
				glVertex3i (1,-1,-1); // 6
			glColor3d(0.0f, 1.f, 0.0f);
				glVertex3i (1,-1,1);
			glColor3d(0.0f, 0.f, 1.0f);
				glVertex3i (1,1,1);
			glColor3d(1.0f, 1.f, 1.0f);
				glVertex3i (1,1,-1);
			glEnd();
	glFlush();
	//glutFullScreen();
 
 glutSwapBuffers();
}
 
 
void Reshape(int w, int h) 
{
   glMatrixMode(GL_MODELVIEW); 
   glLoadIdentity();
   glViewport(0,0,w,h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluPerspective(45,(float) w/h,1.,500.);
}
 
void Clavier(unsigned char touche,int x,int y)
{
	switch (touche)
	{
		case 'd':
		glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
		glutPostRedisplay(); break;
		case 'w':
		glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
		glutPostRedisplay(); break;
		case 's' :
		glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
		glutPostRedisplay(); break;
		case 'a' :
		glutFullScreen(); break;
		case 'q' :
		exit(0);
	}
}