Reputation: 1889
I have a have following code which is supposed to display an image but the image never appears.
GLuint tex_2d = SOIL_load_OGL_texture (
"ImageName.tga",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
glColor3f(0.0f,1.0f,.50f);
glBindTexture(GL_TEXTURE_2D, tex_2d);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2d(0,0); glVertex3f(factor*BOARD_BREADTH/2,-factor*BOARD_LENGTH/2,0);
glTexCoord2d(0,1); glVertex3f(factor*BOARD_BREADTH/2,factor*BOARD_LENGTH/2,0);
glTexCoord2d(1,1); glVertex3f(-factor*BOARD_BREADTH/2,factor*BOARD_LENGTH/2,0);
glTexCoord2d(1,0); glVertex3f(-factor*BOARD_BREADTH/2,-factor*BOARD_LENGTH/2,0);
glEnd();
But I only get a green rectangle as output. There is no compilation error.
Upvotes: 2
Views: 2172
Reputation: 39370
SOIL_load_OGL_texture
returns correct OpenGL texture identifier if the loading succeeds, 0
if it fails. You should always check for that!
In your case, if the wrong path caused the problem, use relative paths. Here's example folder structure:
root/
--- data/
-------- music/
-------- images/
------------ texture.tga
--- bin/
-------- debug/
------------ program.exe
In that case, the relative path would be "../../data/images/texture.tga"
. Note how we go up twice (by ..
, to get to root/
, then go into data/images/
.
That way if you keep the folder structure, it doesn't matter where the root/
resides on disk.
Upvotes: 2