PDA

View Full Version : Drawing from Vertex Array into Shader



uwi2k2
09-26-2012, 05:38 AM
Hi all,

i worked a lot with shaders, but only used VBO.
Now i have a APP where i need to draw from Vertex Array.

So here is my render func, i canīt get it working:



void RenderFunction(void)
{
++FrameCount;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// draw from VBO <<<<<<<<< worx fine
CreateVBO();
glDrawArrays(GL_LINE_LOOP, 0, 3);


// draw from Vertex array <<<<<<< does not draw anything
GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, 0.0f, 1.0f };

GLfloat colors[] = { 0.0f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 1.0f, 1.0f };

// Load the vertex data
glVertexAttribPointer ( 0, 4, GL_FLOAT, GL_FALSE, 0, vVertices );
glVertexAttribPointer ( 1, 4, GL_FLOAT, GL_FALSE, 0, colors );
glEnableVertexAttribArray ( 0 );
glEnableVertexAttribArray ( 1 );

glDrawArrays ( GL_LINE_LOOP, 0, 3 );

glDisableVertexAttribArray ( 0 );
glDisableVertexAttribArray ( 1 );

glutSwapBuffers();
glutPostRedisplay();
}


can someone pls tell me where i got my missunderstanding ?
The shader programm is loaded and succesfully used bei the VBO drawing.
Also the attributs in the shader are binded to 0 and 1 - as well used for the VBO.
I also checked the coordinates - they are fine as well.

what do i need to change ?

thanx
uwi

Dan Bartlett
09-26-2012, 06:02 AM
If you want to draw using client vertex arrays (which is not supported in the core profile any more), you would need to unbind the VBO before calling glVertexAttribPointer.

uwi2k2
09-26-2012, 11:24 PM
thanx !!

thjat was it !