Bonjour à tous

Voilà, je me suis mis à l'opengl avec le red book, et j'essaye de mettre en aplication les divers chapîtres du livre, mais j'ai un petit problème avec l'éclairage.

Mon objectif est simple: dans une fenêtre, afficher une sphere, et l'éclairer avec deux lampe, l'une positionnée par l'utilisateur, et l'autre, verte en rotation dans le plan des x,z .

Le problème, c'est tout simplement que la lumière verte clignote Oo..
Je pense que ça vient de ma fonction idle, mais je ne suis pas sûr.

Si quelqu'un pouvait m'aider?

Merci d'avance.

Ps ah oui, existe-t-il une autre fonction du stryle glugKeyboardFunc qui gère plusieurs touches à la fois?

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
/**************************
 * Includes
 *
 **************************/
 
#include <stdlib.h>
#include <gl/glut.h>
#include <math.h>
 
void keyboard(unsigned char key, int x, int y);
void idle(void);
GLfloat xl=1.0, yl=1.0, zl=1.0, theta=0.0;
 
void init(void)
{
    GLfloat mat_specular[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_shininess[]={50};
    GLfloat light_position[]={xl, yl, zl, 1.0};
    GLfloat white_light[]={1.0, 1.0, 1.0, 1.0};
    GLfloat lmodel_ambient[]={0.1, 0.1, 0.1, 0.1};
 
    GLfloat mat_specular1[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_shininess1[]={25};
    GLfloat light_position1[]={0.0, 0.0, 0.0, 1.0};
    GLfloat white_light1[]={0.0, 1.0, 0.0, 1.0};
    GLfloat lmodel_ambient1[]={0.1, 0.1, 0.1, 0.1};    
 
 
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_SMOOTH);
 
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
    glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
 
    glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, white_light1);
    glLightfv(GL_LIGHT1, GL_SPECULAR, white_light1);
 
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
    glEnable(GL_DEPTH_TEST);
}
 
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    GLfloat light_position[]={xl, yl, zl, 1.0};
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
 
 
    glPushMatrix();
    glRotatef((GLfloat)theta, 0.0, 1.0, 0.0);
    glTranslatef(1.5, 0.0, 0.0);
    GLfloat light_position1[]={cos(theta), 0.0, 0.0, 1.0};
    glutSolidSphere(0.05, 20, 18);
    glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
    glPopMatrix();
 
    glutSolidSphere(1.0, 50, 50);
    glColor3f(1.0, 1.0, 1.0);
 
    glPushMatrix();
    glTranslatef(xl, yl, 1.0);
    glutSolidSphere(0.05, 20, 18);
    glPopMatrix();
 
    glutSwapBuffers();
}
 
 
void reshape(int w, int h)
{
     glViewport(0, 0, (GLsizei)w, (GLsizei)h);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     if(w<=h)
     glOrtho(-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
     else
     glOrtho(-1.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity(); 
}  
 
 
int main (int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("Q, Z, S, D, +, - pour déplacer la lampe");
    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyboard);
    glutIdleFunc(idle);
    glutMainLoop();
    return 0;
}
 
 
 
void keyboard(unsigned char key, int x, int y)
{
     switch (key)
     {
            case 'z':
                 yl+=0.1;
                 break;
            case 's':
                 yl-=0.1;
                 break;
            case 'q':
                 xl-=0.1;
                 break;
            case 'd':
                 xl+=0.1;
                 break;
            case '+':
                 zl-=0.1;
                 break;
            case '-':
                 zl+=0.1;
                 break;
            default:
                 break;
     }
                 glutPostRedisplay();
}                           
 
void idle(void)
{
     theta+=0.1;
     if (theta>360)theta-=360;
 
     glutPostRedisplay();
}