Archived

This topic is now archived and is closed to further replies.

glGenTextures setting my texture name to 0?

This topic is 5383 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m new to OpenGL in C++, but I''ve done a few projects (for a graphics class) in java via gl4java. When I''m running the following code in the debugger, I can see that l_TexName is always being set to 0 instead of some non-zero integer. I think this is why my textures aren''t displaying. I know the function LoadBMP is working (ripped from the nehe tutorials) becuase when I check out l_pImage in the debugger it contains the correct dimensions of the image file that I''m reading in. Am I missing something stupid or is my problem somwhere else (I don''t think this is the case because I''m pretty sure that a texture ''name'' has to be non-zero). Anyway, thanks for any help you can give me. I can post more of my code if need be! // Load Bitmaps And Convert To Textures GLuint CModel::LoadGLTexture( const char *filename ) { AUX_RGBImageRec *l_pImage; GLuint l_TexName; l_pImage = NULL; l_TexName = NULL; if(pImage = LoadBMP( filename )) { glGenTextures(1, &l_TexName); glBindTexture(GL_TEXTURE_2D, l_TexName); glTexImage2D(GL_TEXTURE_2D, 0, 3, l_pImage->sizeX, l_pImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, l_pImage->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if(l_pImage) { if(l_pImage->data) { free(l_pImage->data); } free(l_pImage); } return l_TexName; }

Share this post


Link to post
Share on other sites
Did you enable 2D textures? glGenTextures should only fail if the number of textures you asked for was negative, or if you call it while drawing using glBegin() and glEnd().

Share this post


Link to post
Share on other sites
per your suggestion I''ve added glEnable(GL_TEXTURE_2D); in up after the declarations in this method... doesn''t seem to affect it (I had it enabled elsewhere, but this way I know for sure). Still shooting out zero every time.

For giggles I made l_TexName into an array of size 10 * GLuint, replacing the line in my original code with:

glGenTextures(10, l_TexName);

(my breakpoint is on the first glTexParameteri call, by the way).

When I run this new method in the debugger, all 10 elements of l_TexName are 0. Why?

Share this post


Link to post
Share on other sites