PDA

View Full Version : 3D Texture Rendering Confusion



Jay Soyer
08-24-2011, 07:04 AM
I'm currently working on a QT program that uses OpenGL to display a 3D volume rendering of a brain. There are some minor display bugs which I need to fix but have hit a wall simply on how the 3D texture of the brain is being displayed.

No binding nor explicit tex coord assignment is occuring. Yet the image displays nearly perfectly. Here's the short code snippet.



glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_3D);

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
#ifdef _WIN32
myGLTexImage3D;
#endif
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA,
texture_width, texture_height, texture_depth,
0,
GL_RGBA, GL_UNSIGNED_BYTE, texture_data);

glBegin(GL_QUADS);
for(int i = 0; i < slices; i++)
{
glVertex3f(-windowHalf, -windowHalf, -windowHalf + i * offR);
glVertex3f( windowHalf, -windowHalf, -windowHalf + i * offR);
glVertex3f( windowHalf, windowHalf, -windowHalf + i * offR);
glVertex3f(-windowHalf, windowHalf, -windowHalf + i * offR);
}
glEnd();

glDisable(GL_TEXTURE_3D_EXT);
glDisable(GL_BLEND);


Aside from the normal initializing code, thats it. All my attempts to actually bind the texture and specifically assign texture coordinates yield a solid block of white. I didn't even know it was possible to display textures without binding. The above code is being called on every redisplay. Probably not the best idea. My questions are; without explicitly binding the texture, what's happening? Is it being loaded directly into the fame buffer to draw? Second, what's the default text coordinate assignment OpenGL gives when nothing is explicitly stated? Finally, anyone have any clue why that white block appears when I try to bind it?

V-man
08-24-2011, 07:45 AM
without explicitly binding the texture, what's happening?
Because GL is backwards compatible and in GL 1.0, there were no texture objects. You had to call glTexImage1D/glTexImage2D every time you wanted to change a texture.


All my attempts to actually bind the texture and specifically assign texture coordinates yield a solid block of white.

Are you using glGenTextures, then glBindTexture, then glTexParameteri, then glTexImage3D?


Is it being loaded directly into the fame buffer to draw?
You have to look at the driver source code to know that.


what's the default text coordinate assignment OpenGL gives when nothing is explicitly stated?
I think it is {0.0, 0.0, 0.0, 1.0}. Look at the spec file to be sure.


Finally, anyone have any clue why that white block appears when I try to bind it?
My guess is there is a bug in your code.