Hello,
I m working on some 2D project and would love to add a custom attributes in a GLSL vertex shader, but I m a bit confused about usage of glEnableVertexAttribArray, glVertexAttribPointer and glBindAttribLocation
basically, i m drawing 2D quads and what to have to get an index (in the range [0,1,2,3]) for each vertex. ex : bottom left will get index 0 , bottom right vertex will get index 1.
my code :
Vertex2df vertices[] = {
{-half_x , -half_y ,0},
{ half_x , -half_y ,0},
{ half_x , half_y ,0},
{-half_x , half_y ,0}};
float text []=
{ BotLeftTex.x , BotLeftTex.y ,
TopRightTex.x , BotLeftTex.y ,
TopRightTex.x , TopRightTex.y ,
BotLeftTex.x , TopRightTex.y
};
short attributes[] =
{
0,1,2,3
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2,GL_FLOAT,0,text);
if (pShader)
{
glBindAttribLocation(pShader->getProgramObj(), 10, "vertexIndex");
glEnableVertexAttribArray(10);
//
// (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer);
glVertexAttribPointer(10,1,GL_SHORT,false,0,attributes);
}
glDrawArrays(GL_QUADS,0,4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (pShader)
{
glDisableVertexAttribArray(10);
}
GLSL
attribute short vertexIndex;
void main(void)
{
if (vertexIndex==1)
{
// do something
}
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}
the code works fine for vertex position/texture, but something is wrong in my usage of custom attributes
Any ideas ?
Thanks in advance,
Nicolas