PDA

View Full Version : GL_TEXTURE_RECTANBGLE_ARB



Rennie Johnson
11-12-2011, 11:17 AM
Can't seem to get this working. Trying to convert from GL_TEXTURE_2D. I've enabled it, and created all my test texture stuff, but I get only blackscreen.

I keep reading in the posts that the gurus remind us beginners to use texture coordinates, and not normalized coordinates. What exactly does that mean programatically? The shader examples I see still use glTexCoord[0].st in the texture2dRect() access funtion, which is the same as for normalized textures.

Here is my relevant SETUP CODE for this texture:
************************************************** ***
OpenGL Code:
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glGenTextures(1,&m_sourceTextureBlackOffset);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,m_sourceTex tureBlackOffset);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_WRAP_T,GL_CLAMP);
glPixelStorei(GL_UNPACK_SWAP_BYTES,GL_TRUE);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,GL_LUMINAN CE32F_ARB,m_maxTextureSize,m_maxTextureSize,0,GL_R ED,GL_UNSIGNED_BYTE,m_blackBuffer);

//Fragment Shader Relevant Code (Render To FBO Texture):
#version 110
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect BlackSampler;
float black = texture2DRect(BlackSampler, gl_TexCoord[0].st).r;
************************************************** ***

Everything seems to compile fine, just black image.

Do I have to modify my drawing code also? Presently, I use the following drawing code:

glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);
glVertex2f(-1.0,-1.0);

glTexCoord2f(1.0,0.0);
glVertex2f( 1.0,-1.0);

glTexCoord2f(1.0,1.0);
glVertex2f( 1.0, 1.0);

glTexCoord2f(0.0,1.0);
glVertex2f(-1.0, 1.0);
glEnd();

Do these need to be modified to reference texture coodinates?

what about the use of glTranslate(), glRotate() and glScale()?

Also, can I mix GL_TEXTURE_2D textures in a Fragment Shader with GL_TEXTURE_RECANGLE_ARB textures?
What about the FBO target texture?
Right now, all my textures are GL_TEXTURE_2D, and I'm just testing one rectangle source texture inside a fragment shade that uses 10 textures.

I appreciate your help.

Alfonse Reinheart
11-12-2011, 12:29 PM
I keep reading in the posts that the gurus remind us beginners to use texture coordinates, and not normalized coordinates. What exactly does that mean programatically?

I have no idea what you're talking about. Could you link to some of these posts you keep reading?

The whole point of using texture rectangles is to not have to use normalized texture coordinates (texture coordinate that go from [0, 1]). The whole point is to be able to specify texture locations in texel (pixels within the texture) coordinates. So the coordinate (0, 5) means the texel at the first row and sixth column of the texture.


what about the use of glTranslate(), glRotate() and glScale()?

What about them? Unless you're playing with texture matrices, they only affect vertex positions (and normals).


Also, can I mix GL_TEXTURE_2D textures in a Fragment Shader with GL_TEXTURE_RECANGLE_ARB textures?

What do you mean by that? If you're asking if you can access the same texture as a 2D texture and a texture rectangle, the answer is no. They are both different texture types (http://www.opengl.org/wiki/Texture#Theory). A single texture object cannot be both a 2D texture and a rectangle texture. The same goes for a sampler.

If you're asking if you can have one texture object that is 2D and another that is a rectangle, then the answer is of course. One texture does not affect another. As long as you match your sampler types with the texture you are using, that's fine.

If you're asking whether you can use a 2D texture with a shader at one point, then switch to a rectangle texture with the same shader, the answer is no. Samplers have types, and those types must match the texture types you are using, or else there is an error.

Rennie Johnson
11-12-2011, 12:53 PM
I'm sorry for confusing you. I'm just very frustrated. Could you please respond to my question about drawing code? Do I replace the QUAD drawing code with integer texture coordinates?

I posted a large post earlier which was not responded to. I was trying to understand the order of whether a texture lookup coordinate offset would be affected by vertex transformations in a vertex shader or in OpenGL drawinging code. If the vertex scaling is applied before the texel is offset, then the color records will not line up properly because the offets will all be different and will not scale identically.

At this point, I'm probably just going to do it at the texture loading state with glTexSubImage2D() offsets.

Thanks again for your help.

Alfonse Reinheart
11-12-2011, 01:07 PM
Could you please respond to my question about drawing code? Do I replace the QUAD drawing code with integer texture coordinates?

I did. And I quote:


The whole point of using texture rectangles is to not have to use normalized texture coordinates (texture coordinate that go from [0, 1]). The whole point is to be able to specify texture locations in texel (pixels within the texture) coordinates. So the coordinate (0, 5) means the texel at the first row and sixth column of the texture.

If you need it to be more succinct, here: if you are using rectangle textures, you need to be using texture coordinates that are not normalized.

Isn't that why you want to use rectangle textures?


I was trying to understand the order of whether a texture lookup coordinate offset would be affected by vertex transformations in a vertex shader or in OpenGL drawinging code. If the vertex scaling is applied before the texel is offset, then the color records will not line up properly because the offets will all be different and will not scale identically.

Texture coordinate is offset by what? You've made a lot of posts, yet never once have you said what it is you're actually trying to achieve. What are you trying to do that you think you need to offset texture coordinates?


I posted a large post earlier which was not responded to.

You mean this post (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=58940&Number=3059 25#Post305925), which you also didn't properly format? You'll generally have better luck if you use proper code tags so that it doesn't break the forum layout and is actually legible.

Rennie Johnson
11-12-2011, 01:49 PM
I will read up on the formatting and respond later with the explanation of my goal.

Thank you.