Hi everyone,
I’ve been trying to get copying of a 3D textured image to work. What I’d like
to do is texture a polygon with a 3D texture in the first pass. Then, copy this
texture, manipulate it some in later passes, and then copy it again to my
original 3D texture. Below, I’ve removed all the manipulation part (I’m going
to be using multitexturing later on), and I simply have 2 passes - one texturing
pass, and one copy and texturing pass. The output I’m expecting is just to see
the exact same image as the first pass, but instead I get nothing at all. I
have an Nvidia 4600 card, and will soon get the 5900, but I think neither of
those cards support glCopyTexSubImage3DEXT so I can’t use that function. Below
is the snippet of my code.
Would it make more sense for me to use a 2D Texture in the second pass as the
target rather than GL_TEXTURE_3D_EXT? But if I do that, how do I store a 2D
slice back to a 3D texture?
Any help is greatly appreciated! Thanks!
-
Quynh.
// First pass - simply render a square textured with a 3D texture.
glEnable(GL_TEXTURE_3D_EXT);
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_3D_EXT, texture[shape]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // Clears out previous textures - no combining.
glTexParameteri(GGL_TEXTURE_3D_EXT,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_T,GL_CLAMP);// Draw initial shape onto a quad.
// Texturing function MUST be glMultiTexCoord2fARB. Does NOT work with just glTexCoord2f
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glMultiTexCoord3fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f, zslice);
glVertex3f(-1.0f, -1.0f, 0.0f);
glMultiTexCoord3fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f, zslice);
glVertex3f(1.0f, -1.0f, 0.0f);
glMultiTexCoord3fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f, zslice);
glVertex3f(1.0f, 1.0f, 0.0f);
glMultiTexCoord3fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f, zslice);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
glFlush();// Create and bind accum_texture for accumulation. Copy what was rendered
// in the last pass to a texture.
glActiveTextureARB(GL_TEXTURE1_ARB); // Doesn’t seem to work if using TEXTURE0!
glEnable(GL_TEXTURE_3D_EXT);
glGenTextures(1, &accum_texture); // Create one texture
glBindTexture(GL_TEXTURE_3D_EXT,accum_texture);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_T,GL_CLAMP);
glCopyTexImage2D(GL_TEXTURE_3D_EXT, 0, GL_LUMINANCE_ALPHA, 0, 0, IMAGE_SIZE, IMAGE_SIZE, 0);
glFlush();glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glMultiTexCoord3fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f, zslice);
glVertex3f(-1.0f, -1.0f, 0.0f);
glMultiTexCoord3fARB(GL_TEXTURE1_ARB, 1.0f, 0.0f, zslice);
glVertex3f(1.0f, -1.0f, 0.0f);
glMultiTexCoord3fARB(GL_TEXTURE1_ARB, 1.0f, 1.0f, zslice);
glVertex3f(1.0f, 1.0f, 0.0f);
glMultiTexCoord3fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f, zslice);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
glFlush();