# 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);
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 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 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.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627657
• Total Posts
2978471
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 12
• 22
• 13
• 33