Jump to content
  • Advertisement
Sign in to follow this  

glsl texture-uv set with GL_TEXTURE_COORD_ARRAY wrong in shader

This topic is 2829 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'm trying to render a full-screen textured quad to my window with the following code.

In the shader, if I use the "TextureCoordIn" it appears that I'm only sampling 1 texel (ie my screen is only 1 color).
However, if I calculate the texture coordinate (code commented out), then everything works perfectly...

So apparently the input-texture-coordinate is "not reaching" the shader (or maybe is always set to 0.0, 0.0) - but I can't figure out why...

Any ideas anyone?

const vec2 madd=vec2(0.5,0.5);

attribute vec2 Position;
attribute vec2 TextureCoordIn;

varying vec2 TextureCoord;

void main(void)
gl_Position = vec4(Position.xy, 0.0, 1.0);
TextureCoord = TextureCoordIn; <= screen in 1 color, wrong
//TextureCoord = Position.xy*madd+madd; <= this works

void render_fullscreen_rectangle(RenderDevice* _context, RenderTarget* _rt)
typedef struct _Vertex_V2fT2f
float x,y;
float u,v;
} Vertex_V2fT2f;

Vertex_V2fT2f flat[4] =
{ -1, -1, 0.0f, 0.0f },
{ 1, -1, 1.0f, 0.0f },
{ -1, 1, 0.0f, 1.0f },
{ 1, 1, 1.0f, 1.0f },

// render fullscreen textured quad
glVertexPointer (2,GL_FLOAT,(GLsizei)sizeof(Vertex_V2fT2f),&(flat[0].x));
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

void render (void)
// render scene to texture/fbo

// render texture to screen
glBindTexture(GL_TEXTURE_2D, _context->rt->texture);

glUseProgram (_context->m_blitting.program);
render_fullscreen_rectangle(_context, _context->rt);
glUseProgram (0);

Share this post

Link to post
Share on other sites
If you have arbitrary input attributes (e.g. not the opengl builtin variables), then you shouldn't be using any of these functions:


You need to query your shader for the attribute locations of "Position" and "TextureCoordIn", and then use these locations as inputs to these functions:


The fact that you're getting anything to render at all is pretty much luck I think, as you're using undefined behavior. Otherwise how is your program supposed to know that you want "TextureCoordIn" to be the texcoord pointer, and "Position" to be the vertex pointer?

Share this post

Link to post
Share on other sites
I was staring at that code for 2 hours, wondering why it wasn't working -
your tip took only 15 minutes of implementing and getting it working ^^


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!