Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Problems with projective textures using GL_TEXTURE_RECTANGLE_ARB

This topic is 4141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

	glTexGenfv(GL_S, GL_EYE_PLANE, eyePlaneS);
	glTexGenfv(GL_T, GL_EYE_PLANE, eyePlaneT);
	glTexGenfv(GL_R, GL_EYE_PLANE, eyePlaneR);
	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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!