3D Texture Map

I’m sure we’ve all seen the 2D texture map of a flag blowing in the wind.

I need to write some code that will allow me to do this ‘mesh warping?’ in 3D.

Is this possible with OpenGL and/or can you point me to an example?


The question “can this be done with OpenGL” can usually be answered with “yes”.

But i don´t know, what you want to do. Do you actually want to do that flag-blowing-in-the-wind-thing ? In this case, check out nehe.gamedev.net (lesson 11).
Otherwise, i don´t know what you mean.


I think the OP wants a 3D texture mapped on some animated waving teapot.

Well actually I want to move the verticies of the 3D texture, pass a plane through the cube and render the surface of that plane as it passes through the 3D texture.

I’m not sure I understand what you mean. A texture does not have vertices …
Is this anything near what you have in mind?

Put a plane into your fragment program using [0,0,0]->[1,1,0] coordinates.

In your fragment program, perturb the texture coordinate in any way you want before you fetch out of the 3D texture.

Problem solved.

As far as I know I define a 2D texture with glTexImage2D,
glTextParameterf and then with glBegin(GL_TRIANGLE_STRIP)
glBegin, glNormal3f, glVertex3f and compile these into a newlist etc. etc.

So that is what I mean about the texture having vertices…

So my question is how to do that in 3D? I’ve heard about 3D texture maps but haven’t actually had chance to program it.

In 2D I need to move the points that I defined with glVertex to make an object move (Like the flag wave). Perhaps there is a better way to do this that I am unaware of.

A 2D texture can be applied in 3D. The vertices are 3D etc but the texture coordinates and interpolated image remain 2D. Yes 3D texture exists and can be used but that is really to sample a slice through a 3D image for example if you had a 3D marble texture and wanted to sample based on surface location in that volume.

I’m moving this thread to the beginners section.

EXACTLY! :slight_smile:
Yes what your saying about a 3D marble texture and passing a slice through it is exactly what I’m trying to do however the block of marble is malibal. Do you know of any code snippets that make use of a 3D texture in this way?

Thanks. :slight_smile:

Yes, this is relatively simple.

There are two possible graphics behaviours with a “malleable” marble surface. One is that your 3D texture moves with the block and so the surface remains the same. An alternative is that the surface slides through the marble block, its local surface appearance changing with the contents of the 3D texture.

Both are possible.

To move the surface and retain the original 3D texture appearance you would retain the original 3D texture coordinates for that surface.

To slide through you simply update the 3D texture coordinates as the vertex coordinates change. This is pretty simple to do but OpenGL has functions which can automatically do this making it hardware accelerated and automatic, this mechanism is called texgen. Simply set up and enable texgen for s t and r coordinates with plane equations around your flag to match the desired axis orientation and position of your 3D texture volume.

Once you’ve done this each 3D vertex will produce a texture coordinate based on its position in the volume.

P.S. read this useful thread, it should give you a good idea of how to set up the texgen etc.

http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_to pic;f=3;t=006597

and some of the broken links from that thread:



Thank Dorbie… :slight_smile:
I’ll check out these threads… In the advanced discussion group.

I just wanted to be sure we were on the same page in regards to the clipping plane.

I’m my application it would be equivalent to cutting a tree down and being able to see the rings of the tree.
Is this accomplished with clipping plane?

When you are using 2D textures you define the points on the texture using right hand rule…

What do you do for 3D textures?
Would it be easier to use triangles or quads?
Are there backface issues think about?
Are there vertext norms to define?

Thanks dorbie!

I just found an example in the red book texture3d.c Do you recommend I use it?