[ATTACH=CONFIG]452[/ATTACH]
if(!initialized)
{
GLuint vertexId = shaderProgram->attributeLocation("vertex");
GLuint colorId = shaderProgram->attributeLocation("color");
glGenVertexArrays(1, &VAO_ID);
glBindVertexArray(VAO_ID);
glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[0]);
glVertexAttribPointer(vertexId, 2, GL_FLOAT, GL_FALSE, sizeof(vertices), 0);
glBufferData(GL_ARRAY_BUFFER, sizeof(QVector2D)*vertices.size(), vertices.constData(), GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[1]);
glVertexAttribPointer(colorId, 1, GL_FLOAT, GL_FALSE, sizeof(vertices), 0);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*vertices.size(), colors, GL_STATIC_DRAW);
initialized = 1;
}
//glBindBuffer(GL_ARRAY_BUFFER, VAO_ID);
glBindVertexArray(VAO_ID);
int vertexLocation = shaderProgram->attributeLocation("vertex");
shaderProgram->enableAttributeArray(vertexLocation);
int colorLocation = shaderProgram->attributeLocation("color");
shaderProgram->enableAttributeArray(colorLocation);
glDrawArrays(GL_TRIANGLES, 0, numVerts);
I changed the function. thanks. Yes, I receive no error regarding the shader program not linked. Besides, the shader program was working properly without VBO.
this is my shader program:
//#version 130
precision mediump float;
uniform mat4 mvpMatrix;
attribute vec4 vertex;
attribute float color;
varying float varyingColor;
void main(void)
{
varyingColor = color;
gl_Position = mvpMatrix * vertex;
}
//#version 130
precision mediump float;
varying float varyingColor;
void main(void)
{
gl_FragColor = vec4(varyingColor * vec3(0, 1, 0), 0.5);
}
The program should draw a ppi, but what it draws is quite irrelevant, I attached a screen shot.