Hi, buddies,
I have encountered a strange problem when I am trying to uploading a 3D texture to GPU. The test code is simple as following ,
// code snippets
// enable GLSL program
glUseProgram(glslProgram);
// enable texture x
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_3D, xTexID);
//The following is only for Debugging the texture
float* outData = new float[imgCube];
fill(outData, outData+imgCube, 0.0);
glGetTexImage(GL_TEXTURE_3D, 0, GL_LUMINANCE, GL_FLOAT, outData);
cout <<"Debug: TextureX" <<endl;
copy(outData, outData+imgCube, ostream_iterator<float>(cout, " "));
cout <<endl;
delete outData;
// End debugging
glUniform1i(xParam, 0); // texunit 0
In order to test whether I have successfully created the 3D texture, I specially inserted the test code to fetch data from the tex3D handle “xTexID”, and it printed out exactly what I have set. But when it is transfered to the fragment shader by “glUniform1i(…)”, the corresponding tex variable in the shader contains only 2 or 3 diffren data which fill the tex by repeating. The following is my test shader,
//shader.frag
#extension GL_ARB_texture_rectangle : enable
uniform sampler3D textureX;
void main(void)
{
vec2 coord2D = gl_TexCoord[0].st;
vec3 coord3D = vec3(coord2D, 0);
vec4 tmpColor = texture3D(textureX, coord3D);
gl_FragColor = tmpColor;
}
My OS system is WinXP SP2 (32bits), OpenGL 3.2 & GLSL1.5. By using of the similar code, when I test the transition using 2D texture, it works well. By for 3D case above, I can’t locate where the crux is.
Any indications would be appreciated.
Thank you in advance,
Charmingzuo