PDA

View Full Version : texture mapping - only see solid color no texture



pwonder
09-26-2004, 12:05 PM
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!

09-26-2004, 02:03 PM
How your lighting is setup and how your materials are setup will affect how textures look too.

I don't see any of that above.

pwonder
09-26-2004, 02:10 PM
Oh, I did not know you had to set up other things ... (from reading the tutorial).

do you have any example code?

pwonder
09-26-2004, 03:01 PM
Also... the bitmap image is 256x256 pixels, so there should not be a problem there.

pwonder
09-26-2004, 03:17 PM
ok... i found the problem.
It was the path of the image.

if i put the complete path.. like /home/user ...
then the texture works.

Does anyone know how to specify the path relative the the working directory?

like /images/texture1.bmp ?
instead of: /home/user/.../images/texture1.bmp

09-26-2004, 04:53 PM
If the image is in a folder relative to the executable (like /home/user/project/images/image.jpg) use:

./images/image.jpg

If the executable is in something like /home/.../project/bin and the image is in /home/.../project/images, use:

../images/image.jpg

pwonder
09-27-2004, 05:42 AM
Thanks a ton foo!