I've got a problem with a 3d texture in OpenGL.
I set the texture via
glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, 640, 480, 8, 0, GL_RED, GL_UNSIGNED_BYTE, tex3Ddata);
with tex3Ddata being in total 8 slices of 640x480 bitmaps. Now when I try to access the different slices with texture coordinates, for some reason the images blend into each other, thus I don't properly set the coordinates, yet I do not know why. The texture slices itself are 8bit monochrome.
Code for the displaying:
for(unsigned int i = 0; i < g_numCameras; i++) {
float tx = ((float)i) / ((float)g_numCameras - 1);
//tx = 0.5f; //this is for testing only
float fI = ((float)i) / ((float)g_numCameras);
if( i < (g_numCameras >> 1)) {
glTexCoord3f(0.0f, 1.0f, tx);
glVertex3f( -1.0f + fI * 4.0f, 0.0f, 0.5f);
glTexCoord3f(1.0f, 1.0f, tx);
glVertex3f( -1.0f + (fI + 1.0f / ((float)g_numCameras)) * 4.0f, 0.0f, 0.5f);
glTexCoord3f(1.0f, 0.0f, tx);
glVertex3f( -1.0f + (fI + 1.0f / ((float)g_numCameras)) * 4.0f, 1.0f, 0.5f);
glTexCoord3f(0.0f, 0.0f, tx);
glVertex3f( -1.0f + fI * 4.0f, 1.0f, 0.5f);
}
else {
fI -= 0.5f;
glTexCoord3f(0.0f, 1.0f, tx);
glVertex3f( -1.0f + fI * 4.0f, -1.0f, 0.5f);
glTexCoord3f(1.0f, 1.0f, tx);
glVertex3f( -1.0f + (fI + 1.0f / ((float)g_numCameras)) * 4.0f, -1.0f, 0.5f);
glTexCoord3f(1.0f, 0.0f, tx);
glVertex3f( -1.0f + (fI + 1.0f / ((float)g_numCameras)) * 4.0f, 0.0f, 0.5f);
glTexCoord3f(0.0f, 0.0f, tx);
glVertex3f( -1.0f + fI * 4.0f, 0.0f, 0.5f);
}
}
g_numCameras is 8, so I would expect the slices to be accessible via the Z-coordinates 0.0f, 1/7, 2/7, ..., 1.0f. Yet it's always interpolated. I tested with tx=0.5f; as well, but this is also a mix of images. The x/y coordinates work properly, and the 8 quads are placed as expected, just the slicing through the cube doesn't work the way I would have expected it.
Any ideas what I am doing wrong here? (I was not able to find an equivalent answer / example on 3d textures).
I've also tested whether the data is proper by uploading 8 times the same image, and that worked just fine (since interpolation will result in original image, I got the original image there).