该计划有效。
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
Shader* shader = Root::getInstance()->getRenderSystem()->getShader("Test");
shader->bind();
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
kmMat4 mvp;
kmMat4 mv;
kmMat4Multiply(&mv, &model, &view);
kmMat4Multiply(&mvp, &perspective, &mv);
GLint uMvp = shader->getUniformLocation("mvp");
LOG("%i", uMvp);
glUniformMatrix4fv(uMvp, 1, GL_FALSE, mvp.mat);
checkGlErro("uniform matrix");
GLint uColor = shader->getUniformLocation("color");
LOG("%i", uColor);
glUniform4f(uColor, 0, 0, 1, 1);
checkGlErro("uniform");
glDrawArrays(GL_LINES, 0, 2);
glDisableVertexAttribArray(0);
shader->unbind();
glBindBuffer(GL_ARRAY_BUFFER, 0);
着色器:
const std::string testShader_vert =
"uniform mat4 mvp; \n"
"attribute vec4 position; \n"
"void main() { \n"
" gl_Position = mvp * position; \n"
"}";
const std::string testShader_frag =
"precision mediump float; \n"
"uniform vec4 color; \n"
"void main() { \n"
" gl_FragColor = color; \n"
"}";