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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <SDL/SDL.h>
#include <SDL/SDL_Image.h>
#include <GL/gl.h>
#include <GL/glu.h>
GLuint texture_name;
SDL_Surface *texture;
GLuint objet;
void LoadTextures()
{
// ---- 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_MAG_FILTER, GL_LINEAR);
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);
}
void DrawScreen()
{
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;
LoadTextures();
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = false;
}
glClear(GL_COLOR_BUFFER_BIT);
DrawScreen();
}
SDL_Quit();
return 0;
} |
Partager