Hi All–I’m relatively new to OpenGL, and was hoping to get some feedback on my attempt to visualize a 3D medical image using 3D textures. I’ve managed to successfully render 2D images using 2D textures, but am having difficulty making the jump to 3D textures.
I’ve successfully rendered a 2D image using OpenGL, and it runs a bit differently using VAOs/VBOs and compiling shaders at runtime as opposed to the glBegin/glEnd combo used here.
Based off an online tutorial (google: CodeProject Volume Rendering)
I have a 1D RGBA array (“VolumeRGBA”) of size 256x256x256 that corresponds to a 3D volume in memory, and I want to visualize it. I’ve allocated the texture as follows:
#define MAP_3DTEXT( TexIndex, dOrthoSize ) \
glTexCoord3f(0.0f, 0.0f, ((float)TexIndex+1.0f)/2.0f); \
glVertex3f(-dOrthoSize,-dOrthoSize,TexIndex);\
glTexCoord3f(1.0f, 0.0f, ((float)TexIndex+1.0f)/2.0f); \
glVertex3f(dOrthoSize,-dOrthoSize,TexIndex);\
glTexCoord3f(1.0f, 1.0f, ((float)TexIndex+1.0f)/2.0f); \
glVertex3f(dOrthoSize,dOrthoSize,TexIndex);\
glTexCoord3f(0.0f, 1.0f, ((float)TexIndex+1.0f)/2.0f); \
glVertex3f(-dOrthoSize,dOrthoSize,TexIndex);
// Initialize GLFW
// Allocate RGBA array
// Create 3D texture
GLuint tex3D;
glGenTextures(1, &tex3D);
glBindTexture(GL_TEXTURE_3D, tex3D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 256, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, VolumeRGBA);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.1f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
for (float fIndx = -1.0f; fIndx <= 1.0; fIndx=fIndx+0.005)
{
glBegin(GL_QUADS);
MAP_3DTEXT(fIndx, 1.0f);
glEnd();
}
I can get the window open, but perhaps unsurprisingly, it’s a blank screen. So in addition to the fact that I’m clearly missing some conceptual info:
- How does this situation change when the volume itself isn’t in dimensions of power of 2? How does 3D texture size compare to 3D volume size?
- If I want to eventually have 2D images overlayed on the volume itself (separate images, not just slices of the volume), do I need a uniform set of shaders to handle the two of them?
I know it’s a lot to ask, but any insight would be tremendously helpful to my research.