PDA

View Full Version : Texture coordinates & Display Lists



Sheepie
04-09-2001, 10:03 PM
I am sure I had seen this in a previous post, but I can not seem to find it now. Here's the problem.

I'm using display lists to draw multiple objects. One display list per object. The display list encapsulates everything, Texture binding, Texture UV's, Vertex Normals.

I have figured out how to switch textures by simply doing a glTexSubImage2d, however I now need to be able to slide the textures.

Redrawing the display list just to change the UV's is out of the question, and using a glTexSubImage2d would also seem to be wasteful. Is there any way to change the UV mapping for a single texture without the need to change the TexCoord values?

Sheepie
04-09-2001, 10:15 PM
Uhhh...nevermind, I should have tried my guess b4 posting :P. Just switch to texture Matrix mode and translate.

I guess this raises my next question however. Would it be faster to create one large texture and use the translate function to select the various frames of the animation AND the translate function seems to work well but, is it possible to use that at the same time as GL_REPEAT? This would seem to cause problems with One large texture containing all of the frames of animation.

Also, would specifying a translate of 1 be one whole texture length? I assume this would be the case, if so that would seem to indicate that the UV's would need to be changed.

Anyone feel like explaining this? please?

Olive
04-09-2001, 10:20 PM
Yep! You can change the texture matrix.
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(dS, dT, 0.f);

You can apply any kind of transformation to the texture coordinates. The texture matrix, just like the modelview and projection matrix, is a 4x4 matrix.

By the way, I don't really know what you're doing so this is probably a stupid question but, instead of changing you're texture with a glTexSubImage2D (slow) and keeping the bind in the display list wouldn't it be faster to take the bind out of the display list and change texture objects when you want to change the texture ?

Olive
04-09-2001, 10:27 PM
Ok. just saw you're answer came up just while submiting. Forget all that I said...

For small animations (frame size and number of frames) it should be way more efficient to define one very large texture and translate texture coordinates. But since textures are generally, on the best case, limited to 4096x4096, with a resolution of 256x256 this limits your animation to 256 frames.

To skip from frame to frame, a translation of 1 wont do because you wont change your frame since texture coordinates are all modulo 1. Anyway if you did that would suppose you originally used a quad with tex coords from 0 to 1 which would mean you would see all your frames mapped on you quad !
Of course what you need is to map your texture from 0 to 1/NbSFrames for S and 0 to 1/NbTFrames for T and then translate by these fractions for each frame.
And by the way, that would mean of course, that GL_REPEAT would be useless.
Finally, beware of texture filtering artifacts with something other than GL_LINEAR when using portions of textures like this. You may start seeing adjacent frames sort of "bleeding" on you frame edges.

[This message has been edited by Olive (edited 04-10-2001).]

Sheepie
04-10-2001, 09:16 AM
Thank you for the good explanation Olive. http://www.opengl.org/discussion_boards/ubb/smile.gif I didn't know if the texture coordinates were modulo 1. I assumed they were but not sure.
The reason I need to change the texture using glTexSubImage2D is that the objects that are contained within the display list contain many faces with each face being a possible different texture. I am creating a model editor for someone elses models, not my own. The fastest way I have found so far is Display list encapsulation of each object. This does of course mean that I would need to bind the texture in the display list with each face. http://www.opengl.org/discussion_boards/ubb/frown.gif

I'm really not sure if I am going to be able to use one very large texture as you mentioned artifacts and problems using GL_REPEAT. One of the difficulties regarding the models is that they can and often do have faces that utilize the UV mapping to repeat a texture across the face. If I were to use one large texture, it seems that it would be impossible to keep the repeat capability and seperate the frames.

It looks like I will be forced into the slower glTexSubImage2D call, with the Translate for sliding.

Since I have your attention Olive http://www.opengl.org/discussion_boards/ubb/wink.gif, would it be possible to mix paletted textures and RGBA textures on the same model? The reason I ask is that the models utilize Procedural textures. Currently, I believe that they use some form of Palette animation or similar. I have never used Paletted textures, so go easy on me.

And in case your curious, the model editor I am making is for Descent III. It is a 3D action game produced by Interplay. This is why some of the limitations are there. http://www.opengl.org/discussion_boards/ubb/smile.gif

Olive
04-10-2001, 11:31 PM
Originally posted by Sheepie:
Thank you for the good explanation Olive. http://www.opengl.org/discussion_boards/ubb/smile.gif
Purrrrrrrrr.... http://www.opengl.org/discussion_boards/ubb/smile.gif

I didn't know if the texture coordinates were modulo 1.
In fact, technically speaking, they're not modulo 1. Its just easy to think of them like this when you're working with GL_REPEAT. If you're using GL_CLAMP, they're not.

I must admit that I'm a bit confused now. Yes of course, putting everything in a DList is fast but if you're working on a modeler (is that right), chances are the user will modify your model often (vertices or texture) so putting everything in a DList obviously will need a recompilation of it, which slows down the rendering. There was a previous discussion on the overhead of DL compilation and from what Matt Craighead from nVidia said, it starts to be efficient if you don't change your DL every 10 frames or so if I remember well.
For your textures, couldn't you break up your single DL into one DL for each texture used in the object. Each one of these DLs would contain the geometry without the bind. With the bind out of the DL you can change it easily at each frame, keep the GL_REPEAT, etc. ?


Since I have your attention Olive http://www.opengl.org/discussion_boards/ubb/wink.gif, would it be possible to mix paletted textures and RGBA textures on the same model? The reason I ask is that the models utilize Procedural textures. Currently, I believe that they use some form of Palette animation or similar. I have never used Paletted textures, so go easy on me.

I think you can. ('cause I must admit I haven't used paletted textures myself. Ooops, just lost my shiny armor there http://www.opengl.org/discussion_boards/ubb/smile.gif !)


[This message has been edited by Olive (edited 04-11-2001).]

kieranatwork
04-11-2001, 02:11 AM
BTW, did you know that any manipulation of the texture matrix has no effect if texture_2d is NOT enabled?
I found this out the hard way...very odd, I'm sure there's a good reason for it.

Sheepie
04-11-2001, 11:33 AM
I apologize for not explaining more in depth about what the program does. http://www.opengl.org/discussion_boards/ubb/frown.gif
Basically, it allows people to add animation frames and Special Points to the models as well as changing the Parent/Sibling relationships. It doesn't allow them to change the Verts and/or Faces, or Textures which is why I used Display lists. I guess I should have explained more.

Textures are not modulo 1? http://www.opengl.org/discussion_boards/ubb/frown.gif I guess I'm wondering if I set a translate of 1, if it will always shift by 1 full texture width or height?

You have helped immensely Olive. http://www.opengl.org/discussion_boards/ubb/smile.gif I was kind of expecting someone to come in and tell me that this question had been asked a million times b4 and that I should go look it up. Instead, you answered quickly and informatively. http://www.opengl.org/discussion_boards/ubb/smile.gif Thank you.

Thank you kieran as well http://www.opengl.org/discussion_boards/ubb/smile.gif I only bind the texture when I change frames and it worked, but if you say it doesn't work without enabling textures then that indicates that some video cards will not work. http://www.opengl.org/discussion_boards/ubb/smile.gif I am quite sure that just saved me a lot of hair pulling.