Example de programme OpenGL (2)

previoustopnext

#include <GL/gl.h>
#include <GL/glut.h>

long v[8][3] = {
        {-1, -1, -1},
        {-1, -1,  1},
        {-1,  1,  1},
        {-1,  1, -1},
        { 1, -1, -1},
        { 1, -1,  1},
        { 1,  1,  1},
        { 1,  1, -1}
};
int path[16] = {
        0, 1, 2, 3,
        0, 4, 5, 6,
        7, 4, 5, 1,
        2, 6, 7, 3
};

void drawcube() {
        int i;

        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(0.0, 0.0, 0.0);

        glBegin(GL_LINE_STRIP);
        for (i=0; i < 16; i++)
                glVertex3i(v[path[i]][0], v[path[i]][1], v[path[i]][2]);
        glEnd();
        glFlush();
}

main(int argc, char **argv) {
        glutInit(&argc, argv);
        glutInitWindowSize(600, 400);
        glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
        glutCreateWindow("glLookat example");
 

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(30.0, 1.5, 0.1, 10.0);
        gluLookAt(5.0, 4.0, 6.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0);

        glMatrixMode(GL_MODELVIEW);

        glClearColor(1.0, 1.0, 1.0, 0.0);  /* white */
        glClear(GL_COLOR_BUFFER_BIT);

        glutDisplayFunc(drawcube);
        glutMainLoop();
        return 0;
}
 
 


Michel Buffa

ESSI