Sign in to follow this  
Kraig

OpenGL Problems with projective textures using GL_TEXTURE_RECTANGLE_ARB

Recommended Posts

Hi all, I am farily new to OpenGL. I am trying to do a projective texture, but I need float precision in my texture. I am not quite sure how floats render, particularily small and negative numbers. Anyways, I first started playing around with projective textures using GL_TEXTURE_2D as the target and GL_LUMINANCE as the internal format. I got everything working beautifully. I then tried to load my texture, which has float format, but found that GL_LUMINANCE doesn't have 32-bit precision. I cannot find a 32-bit precision internal format for GL_TEXTURE_2D, so I went to the GL_TEXTURE_RECTANGLE_ARB target with GL_FLOAT_R32_NV as the internal format. Everything loads and stores fine. Here's the problem. The projective texture is completely screwed up now. I was starting with an identity matrix and then offsetting and scaling to convert the coordinates from [-1,1] to [0,1]. This used to put the projective texture shooting down the negative z axis, but now I have no idea what the orientation is. This is what my code used to look like in order for doing this:
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glTranslatef(0.5, 0.5, 0.5);
	glScalef(0.5, 0.5, 0.5);
I know that GL_TEXTURE_RECTANGLE_ARB uses non-normalized coordinates ([0,width] instead of [0,1]), but I am not sure how to change the glTranslatef statement. I am also not sure if I have to change the texture generation planes. Before I was just using the identity values as well:
	// texture coord generation
	GLfloat eyePlaneS[] = {1.0, 0.0, 0.0, 0.0};
	GLfloat eyePlaneT[] = {0.0, 1.0, 0.0, 0.0};
	GLfloat eyePlaneR[] = {0.0, 0.0, 1.0, 0.0};
	GLfloat eyePlaneQ[] = {0.0, 0.0, 0.0, 1.0};

	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_S, GL_EYE_PLANE, eyePlaneS);
	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_T, GL_EYE_PLANE, eyePlaneT);
	glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_R, GL_EYE_PLANE, eyePlaneR);
	glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_Q, GL_EYE_PLANE, eyePlaneQ);
Do I have to scale these by the width and height (or inverse of them)? Lastly, do textures in GL_FLOAT_R32_NV actually show up correctly when rendered? Either I see nothing at all (which could be due to the orientation being completely off), or something completely wrong. If anyone has ever tried this before or has some suggestions, I would love to hear from you. Thanks.

Share this post


Link to post
Share on other sites
Just to update, I switched the internal format from GL_FLOAT_R32_NV to GL_RGBA32F_ARB. I now get a texture showing up but there is some kind of clamping on the colors occurring. I don't know what is the valid number range for floats.

I have read on a number of forums that GL_FLOAT_R32_NV doesn't render textures unless you write a fragment shader that simply copies the texture color to the frag color. I am going spend some more time to try to get this GL_RGBA32F_ARB that I just found out about to work. Might as well stick with the ARB extensions for consistency, if nothing else.

Share this post


Link to post
Share on other sites
Eeesh! After scratching my head over this for so long I finally just sat down and wrote it out on paper. It is so embarrassingly easy I wish I could just delete the thread. Since I don't know how to delete it I might as well give the answer.

With GL_TEXTURE_2D (normalized texture coordinates) you need to transform [-1, 1] to [0, 1]. You do this by scaling by a half, making [-0.5, 0.5], and then add a half. Instead of going to [0, 1], with non-normalized texture coordinates, like GL_TEXTURE_RECTANGLE_ARB, you are transforming to [0, d], where d is the dimension size (like width or height). So you just scale and add d/2 instead of 1/2. Too simple and obvious once you just sit down and think about. I spent all day just blindly trying stuff. Stupid.

Anyways, remember that the operations are done in the opposite order so you would actually transform first and then scale.

At least this problem forced me to find the GL_RGBA32f_ARB, so it wasn't a complete waste.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this