PDA

View Full Version : GL_QUAD_STRIP + textures



Hylke Donker
06-23-2006, 02:19 AM
Hello,
If I render multiple quads using:
glBegin(GL_QUAD_STRIP);
[..]
glEnd();
Is it possible to have a different textures on each single quad?
Or is the only way to have different images on your quads to have one single quad, with different images on it, and then just have like this:

glBindTexture(GL_TEXTURE_2D, texindex);
glBegin(GL_QUAD_STRIP);
glTexCoord2f(0.0, 0.0); glVertex3fv(vertices[0]);
glTexCoord2f(1.0, 0.0); glVertex3fv(vertices[1]);
glTexCoord2f(0.0, 0.2); glVertex3fv(vertices[2]);
glTexCoord2f(1.0, 0.2); glVertex3fv(vertices[3]);
glTexCoord2f(0.0, 0.2); glVertex3fv(vertices[4]);
glTexCoord2f(1.0, 0.2); glVertex3fv(vertices[5]);
glTexCoord2f(0.0, 0.5); glVertex3fv(vertices[6]);
glTexCoord2f(1.0, 0.5); glVertex3fv(vertices[7]);
[..]
glEnd();Or are there any other ways to do it?

And how should I imagine 3D textures? Like a cube?
And is it a good idea to use a 3D texture for water?
And how can I make 3D textures?
Thanx in advance,
Hylke

k_szczech
06-23-2006, 12:59 PM
Using glBindTexture inside glBegin / glEnd block is not allowed, so you can use only one texture.

About 3D texture - you can think of it as a space filling a cube or as a set of 2D textures layered one on top of another.
Do not get confused - 3D texture is something different than cube texture.

So if you want to use multiple 2D textures inside one glBegin / glEnd block then you can create one 3D texture containing all of the 2D textures and use Z coordinate to select one of these 'layers'.

float z1 = 0.5f / (float)textureSizeZ;
float z2 = 1.5f / (float)textureSizeZ;
float z3 = 2.5f / (float)textureSizeZ;

glBindTexture(GL_TEXTURE_3D_EXT, texindex);
glBegin(GL_QUAD_STRIP);
/* first quad using first layer */
glTexCoord3DEXT(0.0f, 0.0f, z1); glVertex3f(...);
glTexCoord3DEXT(1.0f, 0.0f, z1); glVertex3f(...);
glTexCoord3DEXT(1.0f, 1.0f, z1); glVertex3f(...);
glTexCoord3DEXT(0.0f, 1.0f, z1); glVertex3f(...);
/* second quad using third layer */
glTexCoord3DEXT(0.0f, 0.0f, z3); glVertex3f(...);
glTexCoord3DEXT(1.0f, 0.0f, z3); glVertex3f(...);
glTexCoord3DEXT(1.0f, 1.0f, z3); glVertex3f(...);
glTexCoord3DEXT(0.0f, 1.0f, z3); glVertex3f(...);
/* third quad mixing layers 2 and 3 */
glTexCoord3DEXT(0.0f, 0.0f, z2); glVertex3f(...);
glTexCoord3DEXT(1.0f, 0.0f, z2); glVertex3f(...);
glTexCoord3DEXT(1.0f, 1.0f, z3); glVertex3f(...);
glTexCoord3DEXT(0.0f, 1.0f, z3); glVertex3f(...);
glEnd();

I'm not using 3D texture for water - 3D texture does not give 3D impression of waves. I simply move some vertices up and down to create waves, and use 2D texture to cover water surface.

You could use cube texture to simulate reflections on water, but that's a bit more complex topic. Besides, using 2D texture for reflections on water is more commonly used.

ZbuffeR
06-23-2006, 01:23 PM
or use multitexture

Hylke Donker
06-24-2006, 02:17 AM
Ok, thanks for the replies.
But one final question, how can I create 3D textures? Is there a special format for 3D images(something like gif)? Or do you have to generate it your self using multiple images?
Thanks in advance,
Hylke

k_szczech
06-24-2006, 07:54 AM
how can I create 3D textures?It actually depends on what you need this texture for.
In my example above 3D texture is used to store multiple 2D textures - in this case you just load separate 2D images into it.
If you need a file format that supports 3D textures then perhaps .dds is what you're looking for (I've never used .dds but I think it supports 3D textures).

Hylke Donker
06-24-2006, 08:15 AM
Ok, thank you for your reply ;-)
That's all I needed to know.
Hylke