Soucis OpenGL en langage C
Bonsoir, je tente de me mettre vite fait a l'openGL (en ayant marre de la libX) et suivant un certain tuto j'ai code un programme simple.
Il sagit d'ouvrir une fenetre, et d'afficher un polygone avec des couleures varies et dans differents modes d'affichage (avec un key hook).
Le soucis: lors de l'execution la fenetre est transparente (et ne gere pas l'expose, c'est un detail (et c'est normal) mais tres moche).
Voici le code (Cela peu sembler evident aux habitues de l'OpenGL et de glut, merci d'avance pour votre attention):
Code:
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
|
#include <stdlib.h>
#include <GL/glut.h>
#define ESC 27
#define X_POS 142
#define Y_POS 142
#define WIDTH 640
#define HEIGHT 480
#define POINT_SIZE 2.0
int nWindowID;
void handle_key(unsigned char key, int x, int y)
{
switch (key) {
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_POINTS);
glutPostRedisplay();
break;
case ESC:
glutDestroyWindow(nWindowID);
exit(EXIT_SUCCESS);
default:
break;
}
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-0.5, -0.5);
glColor3f(0.0, 1.0, 0.0);
glVertex2f(0.5, -0.5);
glColor3f(0, 0, 1);
glVertex2f(0.5, 0.5);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(-0.5, 0.5);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(WIDTH, HEIGHT);
glutInitWindowPosition(X_POS, Y_POS);
nWindowID = glutCreateWindow("OpenGL is good ?");
glClearColor(0.0, 0.0, 0.0, 0.0);
glPointSize(POINT_SIZE);
glutDisplayFunc(display);
glutKeyboardFunc(handle_key);
glutMainLoop();
return (EXIT_SUCCESS);
} |
J'ai arrange le code en le postant pour le rendre plus presentable.
Ca devrait compiler, pour linker la lib: -L/path_to_libdir/ -lglut
Merci a tous.