Hello,
I am attempting to map a texture to a rectangular box. I am using texture.h, texture.cpp and texture1.bmp (in linux)from this tutorial (downloadable at the bottom):
http://www.spacesimulator.net/tut3_texturemapping.html
The code basically loads a bitmap file into memory that and lets openGL know it is there to use.
So, First i draw a box a solid green box then i try to map the texture over it. The problem is i only see a green box with no texture over it.
Am i doing this wrong? (do i even have to draw a box first?)
glColor3f( 0,0,1 );
glBegin( GL_POLYGON );
glVertex2f( 0.65, 0.55 ); //@@ bottom right
glVertex2f( 0.65, 0.6 ); //@@ top right
glVertex2f( 0.55, 0.6 ); //@@ top left
glVertex2f( 0.55, 0.55 ); //@@ bottom left
glEnd();
glEnable(GL_TEXTURE_2D);// turn on texture mapping
int textureId = LoadBitmap("texture1.bmp"); //id of the texture being loaded
glBindTexture(GL_TEXTURE_2D, textureId); // load the correct texture by it's id
glBegin( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.55f, 0.55f, 0.0f); //top left
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.65f, 0.6f, 0.0f); //top right
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.65f, 0.55f, 0.0f); //btm right
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.55f, 0.55f, 0.0f); //btm left
glEnd();
Any help is appreciated, thanks!