Jump to content
  • Advertisement
Sign in to follow this  
Mr_Twinkie

OpenGL Textures as members of a class

This topic is 4829 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

Does OpenGL care if a texture (specifically a GLuint array) is a member of a class? Like, class model { public: int x,y,z; Gluint textures[1]; }; The problem I am having is that the texture is rendered white. The image I am using is a 256 x 256 .bmp. The routine that loads textures is also a member of the "model" class, and the texture is accesed like this: glBindTexture(GL_TEXUTURE_2D,cube.texture[0]); As far as I can tell, the textures are indeed being generated, but there is no way of knowing whether they are generated *correctly*. Lighting is default (i.e., no lighting commands are given) and glEnable(GL_TEXTURE_2D) is called during the init routines.

Share this post


Link to post
Share on other sites
Advertisement
- OpenGL doesn't care where you store texture ID.
- White texture. Can be different reasons. Make sure you have a valid rendering context before creating texture object. Make sure you set your states (texturing, lighting, color, material, lights,...) right.
- Why on earth do you have array for texture ID if you only have one?

Share this post


Link to post
Share on other sites
You aren't storing a texture in your class. You are storing a texture id (or name, or handle, whatever you want to call it) which is a value you use to tell opengl which texture you are talking about.

White texture can also be caused by using a texture that is not of power of 2 dimensions, or by binding a texture that doesn't exist (but only if no others have been bound, otherwise binding 0 has no effect on the state).

Share this post


Link to post
Share on other sites
_DarkWing_: What do you mean by "valid rendering context"?
mrbastard: What do you mean by "binding a texture that doesn't exist (but only if no others have been bound, otherwise binding 0 has no effect on the state)."?

Thanks for offering help, this problem has been frustrating me and everyone else on my dev team for 2 weeks :(

Share this post


Link to post
Share on other sites
Rendering context is created usually in your init function (via wglCreateContext or something similar). Just think of it as a window you are rendering into for now*. The common mistake is to load textures before you create RC (like in objects constructor). First you have to create RC then load them. And same for any other gl-objects you have (DL, programs, shaders,...)

mrbastard was probably talking about using texture ID that are not associated with valid texture objects. Something like creating texutre ID but never uploading image data to it.

One more thing that can cause your texture not to be valid. They have to have full mipmap chain if you use mipmapping. So *all* levels of it have to be defined. You can either give them yourself, use function that loads all of them or use extension to do it for you.

(*don't flame me for this, I know it's not a window.)

Share this post


Link to post
Share on other sites
More likely than not, if you had texturing working before, then in the constructor of your class maybe, you are calling to set up the texture. Or maybe doing so anytime before OpenGL initializes, (rendering context). You have to make the init function that does OpenGL go before any other init functions of models/object/display lists/etc... anything that is done in OpenGL. I had that problem before but I learned how to fix it. An easy way is to not use class constructors except to initialize variables that aren't used by OpenGL in any way.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!