glEnable(GL_TEXTURE_2D) FAILS!

Started by
4 comments, last by fatak 17 years, 11 months ago
I am trying to texturemap a cube in opengl. I have initialised the texturing functionality by setting glEnable(GL_TEXTURE_2D). But when I test this, glIsEnabled(GL_TEXTURE_2D) return false, and glGenTextures(1, texture), where texture is declared as GLuint texture[1]; does not populate the texture name array. When queried, texture[1] carries junk data. All other functions, such as blending and lighting are working fine, even color shading. Texture mapping fails. please advise on what the issue may be, and what a possible solution would be. Thanks. Dhruva
Advertisement
maybe query texture[0]?
yes i tried that as well, and it didn't work, I even tried populating an array of 5 members, not just one....but still the same error.

Anyway, I have just found that glGenTextures populates the array in certain functions of my Setup Class, and not others. I basically have a setup class that carries out initialisation of the OpenGL API, and a mesh class that holds the geometry and the render function for each object.

Now, the glGenTextures function works fine when called in the Setup::Initialise function, but does not work when called in the Setup::registerTexture function, which the Mesh class calls when it loads the object geometry and texture. The Setup::registerTexture function is a static function, so that it can be called from the mesh class without the necessity of the Mesh class actually carrying an instance of the Setup Class.

Further, the glGenTextures function doesn't work in the Mesh class at all, so i can't include it in there either. I dont want to have to initialise the Mesh Class with an instance of its calling Setup class.

I could paste my code here for your consideration, since this description is unwieldy. How do i paste my code, should i just copy paste, or are there some tags that I can use.

Thanks...

Dhruva
And you're certain that Setup::Initialise is getting called before you call Setup::registerTexture?
Post source using the source tags.
[source]
source goes here
[/source]

And what Rick said was what I was thinking aswell; have you initialized OpenGL before trying to load textures?
Oh my god guys! Thats the problem. I was instancing the mesh before I initialised OpenGL. I dunno how i completely missed that. Sorry for wasting your time, and thanks a ton for your help.

Dhruva

This topic is closed to new replies.

Advertisement