PDA

View Full Version : How to use generic vertex attribute



orlando
04-20-2004, 10:06 PM
Here is a code snippet from a small test on generic vertex attribute in ARB_VERTEX_PROGRAM extension:
...
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho ( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
...
/* draw quad */
glBegin(GL_QUADS);
glVertexAttrib4fARB(6, 1.0, 0.0, 0.0, 1.0);
glVertex3f(-0.5, -0.5, 0.0);

glVertexAttrib4fARB(6, 1.0, 0.0, 0.0, 1.0);
glVertex3f( 0.5, -0.5, 0.0);

glVertexAttrib4fARB(6, 1.0, 0.0, 0.0, 1.0);
glVertex3f( 0.5, 0.5, 0.0);

glVertexAttrib4fARB(6, 1.0, 0.0, 0.0, 1.0);
glVertex3f(-0.5, 0.5, 0.0);

glEnd();

glGetVertexAttribfvARB(6, GL_CURRENT_VERTEX_ATTRIB_ARB, color);
=======================================

Below is the vertex program:
!!ARBvp1.0
ATTRIB iPos = vertex.position;
ATTRIB icolor = vertex.attrib[6];
PARAM mvp[4] = { state.matrix.mvp };
OUTPUT oPos = result.position;
OUTPUT oColor = result.color;

# Transform the vertex to clip coordinates.
DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;

MOV oColor, icolor;
END
==================================

Since the vertex attribute 6 is set to (1,0,0,1), which is used as color data in the vertex program, I expect to see a red quad. But it turned out to be a green quad on both Nvidia and ATI cards.

The color value returned in glGetVertexAttribfvARB(6, GL_CURRENT_VERTEX_ATTRIB_ARB, color) are (0, 1.9, 0, 0).

Is the code correct to use the generic vertex attribute? What should I expect to see?

Thanks.