Jump to content
  • Advertisement
Sign in to follow this  
mlt

OpenGL GL_RGBA textures

This topic is 3574 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

I have a 512*512 grayscale GL_RGBA noise texture that I lookup in the vertex program:
struct vertex_input
{
  float4 position  : POSITION;
  float2 uv        : TEXCOORD0;
  float4 normal    : NORMAL;
};


struct vertex_output
{
  float4 position : POSITION;
  float3 normal   : TEXCOORD1;
  float change    : TEXCOORD2;
};

vertex_output main(  
        vertex_input       IN 
      , uniform float4x4   ModelViewProj
      , uniform float4x4   ModelViewIT      
      , uniform sampler2D  height_texture
)
{
	vertex_output OUT;

	float h = tex2D(height_texture, IN.uv).a;

	OUT.position = mul(ModelViewProj, IN.position);
        OUT.normal = normalize(mul(ModelViewIT, IN.normal).xyz);
	OUT.change = h;
        return OUT;
}

I would like to know the following: 1) What are the dimension of the 'height_texture'? In the application it was 512*512, but in the OpenGL manual I have read that textures are in the range u \in [0,1], v \in [0,1] How do I verify what the valid ranges are to lookup in the texture? 2) The texure is grayscale so I assume what tex2D returns is something like: (0.0, 0.0, 0.0, a) where 'a' is the intensity of the texel ranging from black (0) to white (1), but is this correct and how do I verify this? 3) What are the range of the texture coordinates IN.uv? From the application I have:
        static int offset_coord     = 0;
        static int offset_normal    = sizeof(vector3_type) + offset_coord;
        static int offset_color     = sizeof(vector3_type) + offset_normal;
        static int offset_tex0      = sizeof(vector4_type) + offset_color;
        static int offset_tex1      = sizeof(vector2_type) + offset_tex0;
        static int offset_tex2      = sizeof(vector2_type) + offset_tex1;

        GLsizei stride         = sizeof(vertex_type);
#define OFFSET(x) ((char *)NULL+(x))
        glClientActiveTexture(GL_TEXTURE0);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glTexCoordPointer( 2, GL_FLOAT, stride, OFFSET(offset_tex0)   );


But I don't see anything about the range of the texure coordinates.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by mlt
How do I verify what the valid ranges are to lookup in the texture?

If you want to avoid wrapping or clamping, they're [0..1]

Quote:
Original post by mlt
where 'a' is the intensity of the texel ranging from black (0) to white (1), but is this correct and how do I verify this?

It's an RGBA texture, so all four components will be returned. Their value entirely depend on what you put into the texture image before supplying it to OpenGL.

Quote:

3) What are the range of the texture coordinates IN.uv? From the application I have:

*** Source Snippet Removed ***

But I don't see anything about the range of the texure coordinates.

This sets up vertex arrays. It has nothing to do with UV ranges.

Share this post


Link to post
Share on other sites
I currently use GL_REPEAT, which means that the texture coordinates will not be in the range [0,1]?

But what are the range then?

The texture is just a grayscale perlin noise image so the returned float4 vector from tex2D should only contain a single value between 0-1 (0=black and 1=white). But how do I know for sure what the float4 vector contains?

Share this post


Link to post
Share on other sites
Quote:
Original post by mlt
I currently use GL_REPEAT, which means that the texture coordinates will not be in the range [0,1]?

But what are the range then?

0 to 1.

Quote:

The texture is just a grayscale perlin noise image so the returned float4 vector from tex2D should only contain a single value between 0-1 (0=black and 1=white). But how do I know for sure what the float4 vector contains?

Well, I don't know what you put into your texture image... The resulting four components will match the values that you supplied to OpenGL on a previous glTexImage2D (or similar) call.

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!