#include <sdl/sdl.h>
#include <GL/gl.h>
SDL_Surface *screen = NULL;
void demarre_opengl();
void creer_fenetre_opengl();
void init_opengl();
void stop_opengl();
void tourne_cube();
int main(int argc, char *argv[])
{
demarre_opengl();
tourne_cube();
stop_opengl();
}
void demarre_opengl()
{
creer_fenetre_opengl();
init_opengl();
}
void creer_fenetre_opengl()
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
perror("erreur init SDL\n");
exit(3);
}
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
screen = SDL_SetVideoMode(800,600,16,SDL_OPENGL | SDL_DOUBLEBUF | SDL_HWSURFACE);
}
void init_opengl()
{
glViewport(0,0,800,600);
glShadeModel(GL_SMOOTH);
glClearColor(0.0,0.0,0.0,1.0);
glClearDepth(1.0);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
void stop_opengl()
{
SDL_Quit();
}
void tourne_cube()
{
int i=1000;
while(--i)
{
SDL_Delay(30);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(1.0,0.0,0.0);
glVertex3d(-3.0,-3.0,-3.0);
glVertex3d(-3.0,-3.0,3.0);
glVertex3d(3.0,-3.0,3.0);
glVertex3d(3.0,-3.0,-3.0);
glColor3f(0.0,1.0,0.0);
glVertex3d(-3.0,-3.0,-3.0);
glVertex3d(-3.0,3.0,-3.0);
glVertex3d(3.0,3.0,-3.0);
glVertex3d(3.0,-3.0,-3.0);
glColor3f(1.0,0.0,0.0);
glVertex3d(-3.0,3.0,-3.0);
glVertex3d(-3.0,3.0,-3.0);
glVertex3d(3.0,3.0,3.0);
glVertex3d(3.0,3.0,-3.0);
glColor3f(0.0,1.0,0.0);
glVertex3d(-3.0,-3.0,3.0);
glVertex3d(-3.0,3.0,3.0);
glVertex3d(3.0,3.0,3.0);
glVertex3d(3.0,-3.0,3.0);
glColor3f(0.0,0.0,1.0);
glVertex3d(3.0,-3.0,-3.0);
glVertex3d(3.0,3.0,-3.0);
glVertex3d(3.0,3.0,3.0);
glVertex3d(3.0,-3.0,3.0);
glColor3f(0.0,0.0,1.0);
glVertex3d(-3.0,-3.0,-3.0);
glVertex3d(-3.0,3.0,-3.0);
glVertex3d(-3.0,3.0,3.0);
glVertex3d(-3.0,-3.0,3.0);
glEnd();
glFlush();
glRotated(5, 1.0, 1.0, 1.0);
SDL_GL_SwapBuffers();
}
}
Voici le code que j'ai piqué tel quel dans un tutorial de programmation pour SDL/OpenGL sous Linux et Windows. Personnellement, je développe sous Dev-C++ (4.9.8.0 si vous voulez savoir). Voila mon pb :
tout se compile normalement (j'ai deja mis un certain temps pour réussir a paramétrer le compileur, lignes de commandes et linker...) j'obtiens un .exe sans erreur apparente, mais quand je lance mon programme, je n'obtiens qu'un écran noir pendant 30 s. J'ai essayé d'autres sources disponibles sur ce forum, mais même problème. D'ou cela peut-il venir ? Quel peut être mon erreur et comment la réparer ?
Afficher la suite