coordinate of 3d texture

i want to know what is the differce between 2d and 3d texture coordinate? how can i make 3d texture coordinate? could give me some example?

thank you very much!

Think of 3D textures as multiple 2D textures.

  /|  /|  /|
 / | / | / |
 | | | | | |
 | | | | | |
 | / | / | /
 |/  |/  |/


2D texture coordinates are only capable of addressing one of those texture planes at a time.
3D texture coordinates allow you to map to different planes. In other words, the third texture coordinate selects which 2D texture to use.

You specify 2D texture coordinates with glTexCoord2f and 3D texture coordinates with glTexCoord3f.

There’s other stuff involved: the texture matrix can be changed to map 2D texture coordinates to 3D texture coordinates and vice versa, there’s linear interpolation, texture borders etc.

Oh, and 3D textures are relatively slow. (at least when interpolation is taking place)

when we define 2d texture coordinates,we do like this:

in this case ,if i want to texture mapping a cube,just need to use these code above six times for six faces of the cube.But i really don’t know how can i describe the coordinate when use 3d texture mapping in the same case of mapping a cube? my 3d texture has been defined

What are you trying to do here?

Are you just trying to texture map a cube or are you trying to visualise slicing through a “3D-sprite”?

If you only want to texture map a cube, you don’t need a 3D texture. For that you only need to map each surface onto part of your texture.

i want to see all the volume data in the cube not only the suface of the cube.that is every volume element will make effect to the result .do i depict it clearly?
thank you !

You can’t do this by simply drawing a cube. You have to draw multiple slices…

well how to do it ? In my mind use 3d texture is ok,but maybe i am not clearly understand the meaning of 3d texture?

If you have NxNxN volume, you can create N 2D textures of size NxN along one axis and render N texured quads from farthest to nearest. The axis of slicing must be chosen with respect to camera position. Using a single NxNxN 3D texture gives better results, because slices can be always view-aligned, i.e. perpendicular to the line of sight.
See for example