hello everyone!
I have some troubles in using GLSL. it doesn’t work when changed attrib location,why?this is the OpenGL tuborial example like this http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=6.
this is GLSL code as:
layout (location = 2) in vec3 inPosition;
layout (location = 3) in vec3 inColor;
smooth out vec3 theColor;
void main()
{
gl_Position = vec4(inPosition, 1.0);
theColor = inColor;
}
c++ code is that:
// Setup whole triangle
glBindVertexArray(uiVAO[0]);
glBindBuffer(GL_ARRAY_BUFFER, uiVBO[0]);
glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), fTriangle, GL_STATIC_DRAW);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, uiVBO[1]);
glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), fTriangleColor, GL_STATIC_DRAW);
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, 0);
this code cann’t draw anything…when i changed it as that,it can draw a triangle…why? thanks!
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec3 inColor;
smooth out vec3 theColor;
void main()
{
gl_Position = vec4(inPosition, 1.0);
theColor = inColor;
}
c++ code is that:
// Setup whole triangle
glBindVertexArray(uiVAO[0]);
glBindBuffer(GL_ARRAY_BUFFER, uiVBO[0]);
glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), fTriangle, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, uiVBO[1]);
glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), fTriangleColor, GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);