It doesn't work when changed attrib location,why?

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);

Attrib location 0 was the position slot in the old fixed pipeline, so my guess is that your driver still requires something to be bound to that location (in the really old days all vertex attributes - normal, colour, texcoords, etc - were transferred when and only when you sent position, so making certain that you sent position was kind of essential).

Afaik, the ‘old days’ didnt go anywhere. This is still required (use generic 0 or glVertex) if you work on compatibility profile context.

I had updated the videocard,but it still doesn’t work…I used the glGetAttribLocation funtion to query this inPosition Location,it return 2.
my videocard is ATI 6570M.

hello,please tell me how do I know it work on compatibility and make it doesn’t work on compatibility? thank u!

To discover the type of context you are getting just use
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &var) and check for either GL_CONTEXT_CORE_PROFILE_BIT or GL_CONTEXT_COMPATIBILITY_PROFILE_BIT, if that was what you asked.

Either way, just change position location to 0.

I tried the code and it works fine on my NVIDIA card.

Then its a driver bug :wink:
nvidia is known to ignore spec in places where they don’t see any value in following it (not that I blame them).

i had checked it as you,it return GL_CONTEXT_CORE_PROFILE_BIT.it seem a actual bug in ati card… because the same code can work well in nvidia card.i had tried it.

it seem a actual bug in ati card… because the same code can work well in nvidia card.

That doesn’t prove anything. There are plenty of things that work on NVIDIA cards that are illegal per the GL spec.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.