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
|
glBegin(GL_QUADS);
glColor3f(0,0.2,0);
fprintf(stderr,"OK1");
GLuint texture_name;
GLuint objet;
SDL_Surface * texture;
// ---- Création d'un objet de texture. ------------------------------------------------
glGenTextures (1, & texture_name);
glBindTexture (GL_TEXTURE_2D, texture_name);
// Paramétrage de la texture.
fprintf(stderr,"OK2");
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);
// Chargement du fichier.
texture = IMG_Load("Grass0053_19_S.jpg");
fprintf(stderr,"OK3");
// Jonction entre OpenGL et SDL.
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, texture->w, texture->h, 0,GL_RGBA, GL_UNSIGNED_BYTE, texture-> pixels);
// ---- Fin de création de l'objet de texture. -----------------------------------------
// ...
// Création d'un objet par l'utilisation d'une liste d'affichage.
fprintf(stderr,"OK4");
objet = glGenLists (1);
glNewList (objet, GL_COMPILE);
// Avant d'appeler les fonction glVertex..., on indique quelle texture va être associée à l'objet.
// On active l'application de texture...
glEnable (GL_TEXTURE_2D);
fprintf(stderr,"OK5");
// ... et on indique quelle texture utiliser (celle qui a été créée précédemment).
glBindTexture (GL_TEXTURE_2D, texture_name);
// On peut enfin créer un objet (ici un simple carré).
glTexCoord2d(0,1); glVertex3f(x*section_x,0,z*section_z);
glTexCoord2d(0,0); glVertex3f(x*section_x+section_x,0,z*section_z);
glTexCoord2d(1,0); glVertex3f(x*section_x+section_x,0,z*section_z+section_z);
glTexCoord2d(1,1); glVertex3f(x*section_x,0,z*section_z+section_z);
glEnd();
// Fin de l'application de la texture.
glDisable (GL_TEXTURE_2D);
// Fin de la liste d'affichage. |
Partager