5

I'm normally a self-sufficient Googler, but I can't find any documentation on the OpenGL shader function texture2DRect(). Has anyone come across this before?

It's being used in some sample code for writing shaders in openframeworks, so I know it exists, and it works, just can't find any official docs on it. Where can I learn more about this function?

1

2 Answers 2

8

That function is used to sample a 2D Texture Rectangle (A NPOT texture target), and it's specified in "Additions to version 1.10.59 of the OpenGL Shading Language specification" of the GL_ARB_texture_rectangle extension.:

Add to section 8.7 "Texture Lookup Functions"

Syntax:

    vec4 texture2DRect(sampler2DRect sampler, vec2 coord)
    vec4 texture2DRectProj(sampler2DRect sampler, vec3 coord)
    vec4 texture2DRectProj(sampler2DRect sampler, vec4 coord)

Description:

    "Use the texture coordinate coord to do a texture lookup in the
    rectangle texture currently bound to sampler.  For the projective
    ("Proj") version, the texture coordinate (coord.s, coord.t) is
    divided by the last component of coord.  The third component of
    coord is ignored for the vec4 coord variant.

    No "bias" parameter or "Lod" suffixed functions for rectangle
    textures are supported because mipmaps are not allowed for
    rectangular textures."
Sign up to request clarification or add additional context in comments.

4 Comments

As a follow up question, can you provide any insight on the bounds of the vec coord argument? Normally texture coordinates are between 0 and 1, but this function deals with them differently.. The link you gave me goes into detail stating that its range is 0 to width or 0 to height, I'm getting bounds of width/4 instead. Am I missing something?
@Alan Ho - In my usage, I feed in the width and height of the rectangular texture image as the limits of the texture coordinates, then use texture2DRect() and I'm able to sample from every point within the image. I'm not sure where your width / 4 limit is coming from.
Thanks Brad, I'll look into what's making that happen in my code then.
@Alan Are you sure you're not messing the S texture coord with T? The range is [0, width] for S, and [0, height] for T.
2

texture2DRect() is an OpenGL shading language function that I believe is added by the ARB_texture_rectangle extension in order to support rectangular, non-power-of-two textures.

To use it, you'll need to set up a sampler2DRect uniform in your shader, then have texture2DRect() grab a color from that just like you would with texture2D(). In a Mac application that I have using this, I needed to create my OpenGL texture using GL_TEXTURE_RECTANGLE_EXT instead of GL_TEXTURE_2D.

Kos had to point this out to me in response to my question here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.