Please help I am trying to get texture mapping to work but I can’t seem to get the image to display on to the screen. All I get is a white box the size of the image.
#include <SDL/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
int main(int argc, char *argv[]){
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);
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 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 480, 0, -1, 1);
glClearColor(0.0f,0.0f,0.0f,1.0f); // color to clear framebuffer to
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear framebuffer
glEnable(GL_TEXTURE_2D);
GLuint textureName;
AUX_RGBImageRec *image;
image = auxDIBImageLoad(“link.bmp”);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image->sizeX, image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data);
glGenTextures(1, &textureName);
glBindTexture(GL_TEXTURE_2D, textureName);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glTexCoord2f(0.0, 26.0);
glVertex3f(0.0, 26.0, 0.0);
glTexCoord2f(20.0, 26.0);
glVertex3f(20.0, 26.0, 0.0);
glTexCoord2f(20.0, 0.0);
glVertex3f(20.0, 0.0, 0.0);
glEnd();
SDL_GL_SwapBuffers();
glDisable(GL_TEXTURE_2D);
int done;
for(done = 0; !done;){
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_QUIT ){
done = 1;
}
if(event.key.keysym.sym == SDLK_ESCAPE){
done = 1;
}
}
}
SDL_Quit();
return(0);
}