Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture Mapping not showing up...

Started by cyrax256 Mar 10, 2005 at 11:15 PM 7 replies 4.1k views
Original Post
cyrax256
cyrax256
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:

//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);
}



To init OpenGL

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);
}



The display function:

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();
}



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.
zedzeek
zedzeek
to see why u have a white texture read the opengl2.0 spec this part

3.8.10 Texture Completeness
A texture is said to be complete if all the image arrays and texture parameters
required to utilize the texture for texture application is ...............


also u might be better off using a 3d texture
cyrax256
cyrax256
hello, zedzeek... I checked the OpenGL specs (I forgot to read the doc before, thanks for pointing at it), although I didn't know the "Texture Completeness" concept, I was aware before of the importance of considering all the points in that section because I had read that in other article (I don't remember which one now)...

However, I'm not using mipmaps, nor I had set the GL_TEXTURE_{MAG|MIN}_FILTER for using Mipmaps (as you can see in the code). Although probably I'm still missing something I can't figure out what it is, and the data loaded in memory is loaded correctly. Thanks for your help, anyway.
benco420
benco420
Try cast or store your texture ids for glBindTexture as GLuint.

To build the texture:

void build_image(GLuint texture_number, ...


The display function:

GLuint i;


Seems trivial, but I remember having the same issue once, incorrect cast may depend on which compiler your using.
Roquqkie
Roquqkie
Hi cyrax256!

I've created a semi-simple OpenGL Volume Renderer using 2D textures.
My source-code can be downloaded Here

You can use it as a reference (the code is very readable and simple).

Good luck and best regards,
Roquqkie
cyrax256
cyrax256
Hey Roquqkie,

Thanks for the zip... I will try to read your code, although it looks like more Marching Cubes than Texture Mapping VR... I tried to compile it and gave me this error. Maybe some extra libraries I need?

TextureVolume.h:15:24: CGLA/Vec3f.h: No such file or directory
TextureVolume.h:16:24: CGLA/Vec3i.h: No such file or directory
cyberquiet
cyberquiet
Correct me if I'm wrong, but aren't you rendering 181 quads at the same depth (z=0)?
--------------------------------If you can't understand what I said, it's not you, it's because my english sucks!
cyrax256
cyrax256
Ok, thanks everyone for your comments... I have discovered what was going wrong... Definetely nothing with the texture loading (works fine), but rather with the blending functions I'm using, and haven't set them well... I'm going to check about blending a bit more, and maybe ask one or two questions :-)

About cyberquiet's reply, I suppose there is no problem drawing 181 quads at the same depth, as I have no depth tests, just drawing 181 images to the framebuffer. (Yes, the DEPTH_BIT there is confusing, I just got the blending lesson very wrong, my apologies :-))

Cheers,

Ciro.

[Edited by - cyrax256 on March 17, 2005 10:07:33 PM]
cyrax256
cyrax256
And to reward you (in some wicked way :-P), may I present you some nice images from my program...

This is a render of the gray matter in the brain...


This is a render of the areas which have fat...


There are other renders in http://www.ldc.usb.ve/~ciro/tesis, which you can see. The ones with notrans suffix were a variation of the program, in which the alpha assigned to the images was 0 if the intensity in the volume was 0, or else 255. The ones with trans suffix, were generated by assigning the intensity directly in the alpha value.

Thanks everyone.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.