Bonjour,

j'ai écrit en OpenGL/GLUT différentes fonctions qui devraient normalement m'afficher mon terrain mais la fenêtre reste noire.
J'ai fait un essai dans le cas de la création de 4 triangles pour voir si j'obtenais quelques choses avant de le faire sur plusieurs...
Pouvez-vous me dire ce qui ne va pas

Merci


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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include<GL/glut.h>
#include<stdio.h>
#include<stdlib.h>
#include <math.h>
#include"tree.h"
#define PI 3.1415926535897932384626433832795
 
int anglex = 0, angley = 0, press = 0, x, y, xold, yold;
char presse;
t_cellule *arbre;
static int prof;
static int trans;
 
 
void dessin(t_cellule *arbre)
{
  //l'arbre est vide on ne fait rien
  if(arbre == NULL)
    return;
 
  //On est dans une feuille=>on dessine les triangles
  if(arbre->NW==NULL && arbre->SW==NULL && arbre->SE==NULL && arbre->NE==NULL)
    {
      //On colorie en rouge
      glColor3f(1.0,0.0,0.0);
      glBegin(GL_TRIANGLE_FAN);
      //On commence par le vertex du centre
      glVertex3f(arbre->centre.x,arbre->centre.y,arbre->centre.z);
      //Vertex NW
      glVertex3f(arbre->nw.x,arbre->nw.y,arbre->nw.z);
      //Vertex SW
      glVertex3f(arbre->sw.x,arbre->sw.y,arbre->sw.z);
      //Vertex SE
      glVertex3f(arbre->se.x,arbre->se.z,arbre->se.z);
      //Vertex NE
      glVertex3f(arbre->ne.x,arbre->ne.y,arbre->ne.z);
      //On redessine le vertex NW car sinon le triangle C,NE,NW n'est pas crée
      glVertex3f(arbre->nw.x,arbre->nw.y,arbre->nw.z);
      glEnd();
    }
 
  //On descend recursivement
  if(arbre->NW) dessin(arbre->NW);
  if(arbre->SW) dessin(arbre->SW);
  if(arbre->SE) dessin(arbre->SE);
  if(arbre->NE) dessin(arbre->NE);
}
 
void affichage()
{
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  gluLookAt(-prof*cos(trans*PI/180.0),prof*sin(trans*PI/180.0),300,0.0,0.0,0.0,0.0,0.0,1.0);
  glRotatef(anglex,1.0,0.0,0.0);
  glRotatef(angley,0.0,1.0,0.0);
  glColor3f(1.0,0.0,0.0);
 
  dessin(arbre);
 
  glBegin(GL_TRIANGLE_FAN);
  glVertex3f(0.0,-0.5,0.0);
  glVertex3f(-0.5,-0.5,-0.5);
  glVertex3f(-0.5,-0.5,0.5);
  glVertex3f(0.5,-0.5,0.5);
  glVertex3f(0.5,-0.5,-0.5);
  glEnd();
 
  glFlush();
  glutSwapBuffers();
}
 
 
void init()
{
  glClearColor(0.0,0.0,0.0,0.0); 
  glEnable(GL_DEPTH_TEST);
  glPointSize(10.0);
  prof = 10.0;
  trans = 0.0;
}
 
static void kbdSpecialFunc(int key, int x, int y)
{
  /* sortie du programme si utilisation des touches ESC, */
  /* 'q' ou 'Q'*/
  switch(key)
    {
    case GLUT_KEY_UP :
      prof++;
      break;
    case GLUT_KEY_DOWN :
      prof--;
      break;
    case GLUT_KEY_LEFT :
      trans--;
      break;
    case GLUT_KEY_RIGHT :
      trans++;
      break;
    }
  glutPostRedisplay();
}
 
void reshape(int x,int y)
{  
  if(x<y)
    glViewport(0,(y-x)/2,x,x);
  else
    glViewport((x-y)/2,0,y,y);
}
 
 
void souris(int bouton,int etat, int x,int y)
{
  if((bouton==GLUT_LEFT_BUTTON) && (etat==GLUT_DOWN))
    {
      presse=1;
      xold=x;
      yold=y;
    }
 
  if((bouton==GLUT_LEFT_BUTTON) && (etat==GLUT_UP))
    {
      presse=0;
    }
}
 
void sourismotion(int x,int y){
  if(presse)
    {
      anglex = anglex+(x-xold);
      angley = angley+(y-yold);
    }
  xold = x;
  yold = y;
}
 
void clavier(unsigned char touche,int x,int y)
{
  switch(touche)
    {
    case 'p':glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
      glutPostRedisplay();
      break;
    case 'f':glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
      glutPostRedisplay();
      break;
    case 's':glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
      glutPostRedisplay();
      break;
    case 'd':glEnable(GL_DEPTH_TEST);
      glutPostRedisplay();
      break;
    case 'D':glDisable(GL_DEPTH_TEST);
      glutPostRedisplay();
      break;
    case 'q':exit(0);
    }
}
 
 
 
int main(int argc,char*argv[])
{
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
  glutInitWindowPosition(200,200);
  glutInitWindowSize(250,250);
  glutCreateWindow("Terrain");
  init();
  creer_arbre(&arbre);
  glutDisplayFunc(affichage);
  glutKeyboardFunc(clavier);
  glutSpecialFunc(kbdSpecialFunc);
  //glutReshapeFunc(reshape);
  //glutMouseFunc(souris);
  //glutMotionFunc(sourismotion);
  //glutIdleFunc(idle);
  glutMainLoop();
  return 0;
}