I’m trying to create a renderer using only the generic vertex attribute submission functions and GLSL. By all accounts this should be possible.
However, I’ve run into problems on Ati cards. First the code:
App:
virtual bool Render(const Scene& scene )
{
prog.Bind();
Clear();
CUSTOMVERTEX *data = new CUSTOMVERTEX[scene.numVertices];
std::copy(scene.data, &scene.data[scene.numVertices], data);
data[1].x = 0.1;
glEnableVertexAttribArray(prog.GetLocationOfAttrib("color"));
glEnableVertexAttribArray(prog.GetLocationOfAttrib("pos"));
glVertexAttribPointer(prog.GetLocationOfAttrib("color"), 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(CUSTOMVERTEX), &scene.data[0].color);
glVertexAttribPointer(prog.GetLocationOfAttrib("pos"), 3, GL_FLOAT, GL_FALSE, sizeof(CUSTOMVERTEX), &data[0].x);
//glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(CUSTOMVERTEX), &scene.data[0].x);
glDrawArrays( GL_TRIANGLES, 0, scene.numVertices );
delete [] data;
return true;
}
Vertex shader:
attribute vec3 pos;
attribute vec4 color;
varying vec4 colorI;
void main()
{
colorI = color;
gl_Position = gl_ModelViewMatrix*vec4(pos, 1);
}
Fragment shader:
varying vec4 colorI;
void main()
{
gl_FragColor = colorI;
}
Now on nVidia cards this works just fine. On Ati cards I need to uncomment the line with glEnableClientState(GL_VERTEX_ARRAY);
The code then does work. The position is indeed sourced from the altered copy and not from whatever goes into glVertexPointer.
What am I missing?
A copy of my program can be downloaded here . If anyone with an Ati card can get something other than a black screen when running the OpenGL2.bat file, please let me know. The other profiles show the same scene running in different renderers.
Edit: after a suggestion on GameDev that I check the locations it turns out that that was the problem. pos was at location 2, and color at location 1. Since I wasn’t assigning anything to position 0, that appeared to break. By setting pos to location 0 explicitly before linking, the program does work on Ati cards.
Now my next question: is this all expected behaviour according to the spec. If pos and color are at location 2 and 1, then what is at location 0? I assume vertex position, but gl_Vertex isn’t used.