salut a tous,je debute dans opengl en langage C sous GLUT.svp j'ai besoin d'aide,voila j'ai mon code d'essai sur les materiaux,lumieres,et les normales,c'est juste un cube applati pour un essai;après avoir parcouru presque tous les tutoriels du moins ce que j'ai pu avoir sur le net,je souhaite avoir vos lumieres sur mon bout de code ci dessous,voila mes preoccupations:
est ce que ma definition d'une fonction a part pour un materiau est bien (je veux dire sa joue pas sur la memoire et l'execution)?
mes normales sont-elles justes?
(malgré j'ai verifié et tout)
le paramètrage de la lumière sont-elles bonnes?
concernant l'attenuation de la lumiere,il y'en a 3:constant,linear,et quadratic_attenuation,on peut les utiliser tous les 3 a la fois? ou une seule a la fois?c'est quoi la difference entre les trois?
pour le chargement d'une texture,est ce possible de charger une texture avec GLUT?sinon puis-je faire le chargement avec SDL_image en C dans ce meme code(opengl/glut)?svp


svp merci d'avance de bien vouloir m'aider.



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
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
#include <GL/gl.h>
#include <GL/glut.h>
 
void silver()
{
    GLfloat mat_amb[]={0.19,0.19,0.19,1.00};
    GLfloat mat_diff[]={0.51,0.51,0.51,1.00};
    GLfloat mat_spec[]={0.51,0.51,0.51,1.00};
    GLfloat mat_emiss[]={0.00,0.00,0.00,1.00};
    GLfloat mat_shinn[]={25};
    glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mat_amb);
    glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diff);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_spec);
    glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,mat_emiss);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shinn);
}
 
 
 
void test()
{
        glEnable(GL_BLEND);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glShadeModel(GL_FLAT);
        glEnable(GL_SHADE_MODEL);
        //LUMIERE ET PARAMETRE D'ECLAIRAGES//
                GLfloat light_posi1[]={1.0,3.00,3.00,1.00};
                GLfloat light_amb[]={1.0,1.0,1.0,1.00};
                GLfloat light_diff[]={1.00,1.00,1.00,1.00};
                GLfloat light_spec[]={1.00,1.00,1.00,1.00};
 
                glLightfv(GL_LIGHT0,GL_POSITION,light_posi1);
                glLightfv(GL_LIGHT0,GL_AMBIENT,light_amb);
                glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diff);
                glLightfv(GL_LIGHT0,GL_SPECULAR,light_spec);
 
                glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,1);
 
                glEnable(GL_NORMALIZE);
            glEnable(GL_COLOR_MATERIAL);
                //surface//
                glBegin(GL_QUADS);
                glColor3f(1.0,1.0,0.0);
                glNormal3f(0.0,1.0,0.0);
                glVertex3f(-10.0,-5.0,-10.0);
                glVertex3f(-10.0,-5.0,10.0);
                glVertex3f(10.0,-5.0,10.0);
                glVertex3f(10.0,-5.0,-10.0);
                glEnd();
            glDisable(GL_COLOR_MATERIAL);
            //--liste--d'identifiant--5--//
 
            GLint liste1;
            liste1=glGenLists(5);
            glNewList(liste1,GL_COMPILE_AND_EXECUTE);
 
                    //----mon---objet----//
                    GLfloat  a1[3]={0.0,1.0,2.0};
                    GLfloat  a2[3]={2.0,1.0,2.0};
                    GLfloat  a3[3]={2.0,1.5,2.0};
                    GLfloat  a4[3]={0.0,1.5,2.0};
                    GLfloat  a5[3]={0.0,1.0,5.0};
                    GLfloat  a6[3]={2.0,1.0,5.0};
                    GLfloat  a7[3]={2.0,1.5,5.0};
                    GLfloat  a8[3]={0.0,1.5,5.0};
 
                    silver();
                    glBegin(GL_QUADS);
                    glNormal3f(0.0,0.0,1.0);
                    glVertex3fv(a1);
                    glVertex3fv(a2);
                    glVertex3fv(a3);
                    glVertex3fv(a4);
 
                    glNormal3f(1.0,0.0,0.0);
                    glVertex3fv(a2);
                    glVertex3fv(a6);
                    glVertex3fv(a7);
                    glVertex3fv(a3);
 
                    glNormal3f(0.0,-1.0,0.0);
                    glVertex3fv(a1);
                    glVertex3fv(a2);
                    glVertex3fv(a6);
                    glVertex3fv(a5);
 
                    glNormal3f(0.0,0.0,-1.0);
                    glVertex3fv(a5);
                    glVertex3fv(a6);
                    glVertex3fv(a7);
                    glVertex3fv(a8);
 
                    glNormal3f(0.0,1.0,0.0);
                    glVertex3fv(a4);
                    glVertex3fv(a3);
                    glVertex3fv(a7);
                    glVertex3fv(a8);
 
                    glNormal3f(-1.0,0.0,0.0);
                    glVertex3fv(a5);
                    glVertex3fv(a1);
                    glVertex3fv(a4);
                    glVertex3fv(a8);
                    glEnd();
 
            glEndList();
            glRotatef(45.0,1.0,0.0,0.0);
            glCallList(liste1);
 
            glTranslatef(3.0,0.0,0.0);
            glCallList(liste1);
 
}
void Affichage()
{
    glClearColor(0,1,1,1.0);
 
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
 
    glEnable(GL_DEPTH_TEST);
 
    test();
 
    glFlush();
}
void perspective(int w,int h)
{
 
    GLdouble a=(GLdouble)w/h;
    GLdouble n=0.5,f=50.0;
    GLdouble fovy=60.0;
    glViewport(20,20,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
 
    gluPerspective(fovy,a,n,f);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(
              5.0,2.0,15.0,
              3.0,1.0,0.0,
              0.0,1.0,0.0
              );
 
}
 
int main ( int argc, char * argv[] ) {
 
    /* initialize GLUT, using any commandline parameters passed to the
       program */
    glutInit(&argc,argv);
 
    /* setup the size, position, and display mode for new windows */
    glutInitWindowSize(1000,700);
    glutInitWindowPosition(0,0);
    glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_MULTISAMPLE);
    /* create and set up a window */
    glutCreateWindow("test");
 
    glutDisplayFunc(Affichage);
    //glutKeyboardFunc(keyboard);
    glutReshapeFunc(perspective);
    /* tell GLUT to wait for events */
    glutMainLoop();
 
    return 0;
}