PDA

View Full Version : Texture management and textures affecting colours



Stylus
01-07-2003, 10:01 PM
Howdy.

So, I've tried to find these answers in the red book, the superbible, and in a bazillion samples, I hope someone can help me out:

1) How do you unload textures? I couldn't find a way, so I made a texture manager that keeps a record of how many times a texture is referenced, and when it tries to load a new texture, if it finds a record with no more references, it glBind's to that texture, and replaces it with the new one. Is this in any way correct?Or do I just keep generating textures and hope my card has the memory :)

2) I set my glClear colour at the top of my render function, I draw a grid of light grey lines, and a blue cube on a dark gray background. Everything works fine until I texture map one triangle of the cube, then the lines and the block become black. What's weird is that when I change the texture, if eg: a colour on the border of the texture is red, everything becomes red. (and I haven't set a border value for the texture)

3) Also, I've seen on this website that you mustn't use GL_DECAL when describing a texture, but GL_MODULATE instead. When I use GL_MODULATE, the colours of my texture seem to swap from RGB to BGR, but if I use GL_DECAL, the colours are fine.

Thanks in advance, I know these are long questions, but I've really tried finding some of this myself, to no avail.

Stylus.

T
01-08-2003, 01:10 AM
1. You should create all the textures that you will need to render the scene at an initialisation stage - if you need too many textures that they won't all fit into texture memory, you will experience performance issues, but let opengl worry about "fitting" them into memory. As you are drawing the scene, you will bind the texture you need for the upcoming object. Binding to the texture doesn't occupy more memory (the texture already exists in memory). If you have a texture that will not be needed anymore for the duration of the application, you can delete the texture which will free the memory.

2. Are you remembering to disable texturing after you have finished drawing the textured object. If not, the next time through the render function will use texturing to draw the lines.

3. The choice between DECAL or MODULATE depends on your needs - both have their uses.

Stylus
01-08-2003, 01:26 AM
Dear T: thank you muchly man.

1) I am loading all the textures at initialisation, but say now I load a new level in my game, and I need to delete all the current textures, you say I just need to delete the texture... but using what gl* function? Because I delete the texture data I've read from file directly after I glTexImage2D, so what more should I be doing?

2) Ohkaaay, so I thought that by calling glEnable at the beginning was the end all say all, I didn't know you could toggle it on or off during the rendering process. Thank you so much!

3) Ok, agreed, but is the colour swapping all in my mind, or is it because GL_MODULATE is blending my texture and the colour of the polygon in the previous render even though I'm calling glClear?

Thanks again, you've been the most help so far.

T
01-08-2003, 01:51 AM
1. When you created the textures you would have used a glGenTextures to allocate a texture "name" and then uploaded your image to it. Using a glDeleteTextures will free the memory once more.

3. The combination of colour and texture colour when modulating has perhaps created the illusion of the colour swapping - it should not *actually* be happening.

Stylus
01-08-2003, 02:05 AM
Hey again,

1) Well duh. I don't know how I missed that one, geez, I swear I looked for it. Well, thank you for showing me how stupid I am. No seriously http://www.opengl.org/discussion_boards/ubb/smile.gif

3) Ok, cool. Maybe after I've sorted out my other mistakes it'll come right.

I know I'm sounding like an overkeen leg-attaching animal, but thanks a stack, 'cos no one else has yet helped me out anywhere else. Ta.

Oh, and I didn't know you could texture map a line. Sweet...