if(!initialized)
{
GLuint vertexId = shaderProgram->attributeLocation("vertex");
GLuint colorId = shaderProgram->attributeLocation("color");
glGenBuffers(2, VBO_ID);
glGenVertexArrays(1, &VAO_ID);
glBindVertexArray(VAO_ID);
glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(QVector3D)*verticesSize, vertices.constData(), GL_STATIC_DRAW);
glVertexAttribPointer(vertexId, 3, GL_FLOAT, GL_FALSE, 0, 0);// param - 1 ->0
glEnableVertexAttribArray(vertexId);
glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*verticesSize, colors, GL_STATIC_DRAW);
glVertexAttribPointer(colorId, 1, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(colorId);
glBindBuffer(GL_ARRAY_BUFFER, 0);
vertices.clear();
free(colors);
initialized = true;
}
glBindVertexArray(VAO_ID);
int vertexLocation = shaderProgram->attributeLocation("vertex");
int colorLocation = shaderProgram->attributeLocation("color");
shaderProgram->enableAttributeArray(vertexLocation);
shaderProgram->enableAttributeArray(colorLocation);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_TRIANGLES, 0, 6*numVerts);
glFlush();
glBindVertexArray(0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
if(!initialized)
{
GLuint vertexId = shaderProgram->attributeLocation("vertex");
GLuint colorId = shaderProgram->attributeLocation("color");
glGenBuffers(2, VBO_ID);
glGenVertexArrays(1, &VAO_ID);
glBindVertexArray(VAO_ID);
glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(QVector3D)*verticesSize, vertices.constData(), GL_STATIC_DRAW);
glVertexAttribPointer(vertexId, 3, GL_FLOAT, GL_FALSE, 0, 0);// param - 1 ->0
glEnableVertexAttribArray(vertexId);
glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*verticesSize, colors, GL_STATIC_DRAW);
glVertexAttribPointer(colorId, 1, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(colorId);
glBindBuffer(GL_ARRAY_BUFFER, 0);
vertices.clear();
free(colors);
initialized = true;
}
glBindVertexArray(VAO_ID);
int vertexLocation = shaderProgram->attributeLocation("vertex");
int colorLocation = shaderProgram->attributeLocation("color");
shaderProgram->enableAttributeArray(vertexLocation);
shaderProgram->enableAttributeArray(colorLocation);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_TRIANGLES, 0, 6*numVerts);
glFlush();
glBindVertexArray(0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
To copy to clipboard, switch view to plain text mode
Bookmarks