I'm trying to do a cross OpenGL ES - OpenGL 3.0 (not ES) code to draw triangles just changing the shaders being used.
The code works for the OpenGL ES version, but doesn't work for the OpenGL 3.0 one. Here is what I'm doing:
Vertex shader:
#version 330 core
in vec3 a_v4Position;
void main(){
gl_Position = vec4(a_v4Position, 1.0);
}
Fragment shader:
#version 330 core
out vec3 color;
void main(){
color = vec3(0,1,0);
}
Code to draw the triangle (GLProgram is linked correctly)
const float triangleVertices[] =
{
0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
};
positionAttribLocation = glGetAttribLocation(GLProgram, "a_v4Position");
glEnableVertexAttribArray(positionAttribLocation);
glVertexAttribPointer(positionAttribLocation, 3, GL_FLOAT, GL_FALSE, 0, TriangleVertices);
glDrawArrays(GL_TRIANGLES, 0, 3);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…