0
votes

I'm working on a graphics project involving using a 3D texture to do some volume rendering on data stored in the form of a rectilinear grid, and I was a little confused on the width, height, and depth arguments for glTexImage3D. For a 1D texture, I know that you can use something like this:

glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

where the width is the 256 possible values for each color stream. Here, I'm still using colors in the form of unsigned bytes (and the main purpose of the texture here is still to interpolate the colors of the points in the grid, along with the transparencies), so it makes sense to me that one of the arguments would still be 256. It's a 64 X 64 X 64 grid, so it makes sense that one of the arguments (maybe the depth?) would be 64, but I'm not sure about the third, or even if I'm on the right track there. Could anyone enlighten me on the proper use of those three parameters? I looked at both of these discussions, but still came away confused:

regarding glTexImage3D

OPENGL how to use glTexImage3D function

1
How are you planning on to render the date from the 3D texture. OpenGL 3D textures are not "magical" volume rasterizers. When drawing regular OpenGL primitives you can cut "slices" out of the volume, but it will not be a volumetric rendering automatically. For that to happen you must implement some kind of volume raycaster or similar.datenwolf
"where the width is the 256 possible values for each color stream" –– total misunderstanding of what it does. The width (and height and depth) parameter tells, how many pixels to allocate for the texture.datenwolf

1 Answers

2
votes

It looks like you misunderstood the 1D case. In your example, 256 is the size of the 1D texture, i.e. the number of texels.

The number of possible values for each color component is given by the internal format, which is the 3rd argument. GL_RGB actually leaves it up to the implementation what the color depth should be. It is supported for backwards compatibility with old code. It gets clearer if you specify a sized format like GL_RGB8 for the internal format, which requests 8 bits per color component, which corresponds to 256 possible values each for R, G, and B.

For the 3D case, if you want a 64 x 64 x 64 grid, you simply specify 64 for the size in each of the 3 dimensions (width, height, and depth). Say for this size, using RGBA and a color depth of 8 bits, the call is:

glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 64, 64, 64, 0,
             GL_RGBA, GL_UNSIGNED_BYTE, data);