y'a t'il quelqu'un avec de l'expérience en opengl dans la sa…

Startseite

Nachricht beantworten
Autor: Raphaël Jacquot
Datum:  
To: Guilde
Betreff: y'a t'il quelqu'un avec de l'expérience en opengl dans la salle
voila.
j'ai réalisé (apres avoir cherché dans plein de tutoriels en ligne) le
programme attaché.

probleme. dès que j'ajoute la lumiere, je perds les couleurs, ca passe
en niveaux de gris (effet voleurs de couleurs kodak ?)

qqun a une idée ?
#include <GL/glut.h>

GLfloat r = 0.0;

void init(void) {
     glShadeModel (GL_SMOOTH);
    glClearColor (0.0, 0.0, 0.0, 0.0);
     glEnable (GL_LIGHTING);
    glEnable (GL_LIGHT0); 
    glEnable(GL_DEPTH_TEST);
}


void update (int value) {
    r += 1.0;
    glutPostRedisplay();
    glutTimerFunc (1000/25, update, 0);
}


void display (void) {
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    
    glLoadIdentity ();
    gluLookAt (4.0, 3.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);


    glColor3f (1.0, 0.0, 0.0);
    glutSolidCube(1.0);
    glRotatef(r*2.0, 0, 1, 0);
    glTranslatef(0.0, 0.0, 1.0);
    glRotatef(r, 1, 0, 0);
    glRotatef(r, 0, 1, 0);
    glRotatef(r, 0, 0, 1);
    glColor3f (0.0, 1.0, 0.0);
    glutSolidSphere(0.5, 20, 15);


    glutSwapBuffers();
}


void reshape (int width, int height) {
    glViewport (0, 0, (GLsizei)width, (GLsizei)height);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective (60, (GLfloat)width/(GLfloat)height, 1.0, 100.0);
    glMatrixMode (GL_MODELVIEW);
}


int main (int argc, char* argv[]){
    glutInit (&argc, argv);
    glutInitWindowSize (768, 576);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutCreateWindow ("ex1");
    glutDisplayFunc (display);
    glutReshapeFunc (reshape);


    init();
    glutTimerFunc (1000/25, update, 0);
    glutMainLoop ();
    return 0;
}