Original Post
Hello, I'm doing a kind of basic volume renderer in OpenGL. Let's say I have a big file filled with unsigned bytes which form a tridimensinal unsigned char array. My goal is to show a top, side and front orthogonal views of the volume, by making texture slices of the volume file (I make a 256x256 blank image where I paste the texture slice, and put it in video memory with glTexImage2D), and then drawing in each view all the slices one on top of the other. Loading this volume into 2D textures is no more difficult than loading a bunch of image files. I suspect my problem is of OpenGL nature, as I have triple-checked my volume file loader, and my texture slice creator, and they work fine (by printing in console the result). My problem is that the textures aren't being drawn, and all I receive is a white square. I would appreciate if someone could point me what I'm missing or doing wrong... I've followed (I think) all the steps I need in order to create the textures in my video card. They're 256*256 images (the volume file is 181x217x181, so each texture axis needs this image size), with 3 color components plus the alpha one (the volume has several zero filled areas, a texel has alpha 0 in those parts, and alpha 255 in the rest). The functions I use to init OpenGL, to build the 2D textures, and to display the textures follow up: To build the texture: To init OpenGL The display function: I'm quite sure I'm using the right texture ID's, as I have done a version where I only create a specific texture, and try to display it with the same display function, but restricting to that specific texture ID. The original code begins binding from texture ID number 1 and going forward (There are in total 181 textures for the XY plane, 181 for the ZY plane and 217 for the XZ plane). In case you're thinking of that, I initialized my GLUT window with the GL_RGBA value. I tried to generate textures with glGenTexture() but I had no different results, and I haven't seen this done in all the tutorials I've read. I don't think my memory video is a constraint, as I have a 256Mb video card, and if my calculations are correct: (181+181+217)*256*4 bytes per component = 592Kbytes. Thank you very much if you have read up to this point :-) I'm continuing looking what's wrong here... Cheers, Ciro.
//typedef voxel (unsigned char);
void build_image(int texture_number, const int width, const int height, const voxel *data) {
glBindTexture(GL_TEXTURE_2D, texture_number);
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}
void glInit (int w, int h) {
double left = -8.0, right = 8.0, top = 8.0, bottom = -8.0;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_FLAT);
glClearColor(0.0, 0.0, 0.4, 0.0);
glColor4f(1.0f,1.0f,1.0f,0.5f);
glViewport (0, 0, (GLsizei) WIDTH, (GLsizei) HEIGHT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(left, right, bottom, top);
}
void display(GLvoid) {
int i;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Modeling transformation
glLoadIdentity(); // Initialize the model matrix as identity
for ( i = 0; i < Z_AXIS; i++) {
glBindTexture (GL_TEXTURE_2D, i+1);
glBegin (GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2f (-X_AXIS / 2 , -Y_AXIS / 2);
glTexCoord2f(0.0, 1.0);
glVertex2f (-X_AXIS / 2 , Y_AXIS / 2);
glTexCoord2f(1.0, 1.0);
glVertex2f ( X_AXIS / 2 , Y_AXIS / 2);
glTexCoord2f(1.0, 0.0);
glVertex2f ( X_AXIS / 2 , -Y_AXIS / 2);
glEnd();
}
glFlush();
glutSwapBuffers();
}

