# 3D texture display

I am a learner of OpenGL and right now focus on 3D texture. I find that I can not display the inside information of the 3D texture. I wonder how to do that?

Following is part of the example modified from the red book.

#define iWidth 16
#define iHeight 16
#define iDepth 16
static GLubyte image[iDepth][iHeight][iWidth][4];
static GLuint texName;
PFNGLTEXIMAGE3DPROC glTexImage3D;
GLfloat verts[8][3] = {{0,0,0}, {0,1,0}, {1,0,0}, {1,1,0}, {1,0,1}, {1,1,1}, {0,0,1}, {0,1,1}};
GLfloat texs[8][3] = {{0,0,0}, {0,1,0}, {1,0,0}, {1,1,0}, {1,0,1}, {1,1,1}, {0,0,1}, {0,1,1}};

void makeImage(void)
{
int s, t, r;
//first set all the voxel in moderate transparency
for (s = 0; s < 16; s++)
for (t = 0; t < 16; t++)
for (r = 0; r < 16; r++)
{
image[r][t][s][0] = (GLubyte) (s * 17);
image[r][t][s][1] = (GLubyte) (t * 17);
image[r][t][s][2] = (GLubyte) (r * 17);
image[r][t][s][3] = 180;
}

// set depth 13 at red color and no transparency
for (s = 0; s < 16; s++)
for (t = 0; t < 16; t++)
{
image[13][t][s][0] = (GLubyte) 255;
image[13][t][s][1] = (GLubyte) 0;
image[13][t][s][2] = (GLubyte) 0;
image[13][t][s][3] = 255;

}
}

The result is shown below:

(I don’t know how to insert the figure here and I could only display a link of my result picture)

From the figure, we can not see the inside red color plane. I wonder how to show such non-transparency plane?

Thanks very much.

For texture mapping you need to use glTexImage3D call where you can specify the Volume image (in your case static GLubyte image[iDepth][iHeight][iWidth][4]). Your 4th dimension should hold alpha value. Value of alpha is usually between 0 and 1.

For getting inside information, you need to implement ray cast through the volume, till you find voxel beyond which it is completely opaque.

Please search in net for volume rendering. You will lot of stuff.

Thank you very much for the reply. The 4th dimension is the alpha value. Since I have defined image as unsigned byte (GLubyte),alpha value 0 to 1 corresponds to 0 to 255.

I don’t know much about ray casting. Right now I only have opengl superbible(blue book) and red book for reference. They do not have much description of ray casting. Is there any good reference book about ray casting you could recommend?

Thanks again.