Bonjour,
Alors voila le problème est simple, voici un code que j'utilise pour afficher une simple image 2d en utilisant OpenGl et SDL, mais celui ci ne m'affiche qu'un carré blanc...
#include <SDL/SDL.h>
#include <SDL/SDL_Image.h>
#include <GL/gl.h>
#include <GL/glu.h>
void DrawScreen()
{
GLuint texture_name;
SDL_Surface *texture;
GLuint objet;
// ---- Création d'un objet de texture. ------------------------------------------------
glGenTextures (1, & texture_name);
glBindTexture (GL_TEXTURE_2D, texture_name);
// Paramétrage de la texture.
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
texture = IMG_Load("Background.png");
// Jonction entre OpenGL et SDL.
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, texture->w, texture->h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, texture-> pixels);
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, texture_name);
glBegin(GL_QUADS);
glTexCoord2i (0, 0) ; glVertex2i(0,0);
glTexCoord2i (1, 0) ; glVertex2i(0,600);
glTexCoord2i (1, 1) ; glVertex2i(800,600);
glTexCoord2i (0, 1) ; glVertex2i(800,0);
glEnd();
glDisable (GL_TEXTURE_2D);
glFlush();
SDL_GL_SwapBuffers();
}
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("Mon premier programme OpenGL !",NULL);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
SDL_SetVideoMode(800, 600, 32, SDL_OPENGL);
gluOrtho2D(0, 800, 600, 0);
bool continuer = true;
SDL_Event event;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = false;
}
glClear(GL_COLOR_BUFFER_BIT);
DrawScreen();
}
SDL_Quit();
return 0;
}
Turok