7

I have to send vertex attributes using glVertexAttribPointer to shaders expecting them as built-in (gl_Vertex, gl_Color, etc.).

The glVertexAttribPointer function needs to specify the index (or location) of each built-in attribute. I can do it on NVidia implementations since the location of each attribute is fixed (see http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php at the section "Custom attributes), however i'm not sure about the locations in ATI implementation.

Also, the function glGetAttribLocation will return -1 when trying to get the location of any attribute beginning starting with "gl_".

I think i'm missing something and this is a trivial problem, however I have not found the correct solution for ATI.

Rabbid76
  • 142,694
  • 23
  • 71
  • 112
Pau Baiget
  • 73
  • 3

1 Answers1

7

The builtin attribute arrays are not set with glVertexAttribPointer, but with functions like glVertexPointer, glColorPointer, .... And you enable these by calling glEnableClientState with constants like GL_VERTEX_ARRAY, GL_COLOR_ARRAY, ..., instead of glEnableVertexAttribArray.

Whereas on nVidia glVertexAttribPointer might work, due to their aliasing of custom attribute indices with builtin attributes, this is not standard conformant and I'm sure you cannot expect this on any other hardware vendor. So to be sure use glVertexAttribPointer for custom attributes and the glVertexPointer/glNormalPointer/... functions for bultin attributes, together with the matching enable/disable functions.

Keep in mind that the builtin attributes are deprecated anyway, together with the mentioned functions. So if you want to write modern OpenGL code, you should define your own attributes anyway. But maybe you have to support legacy shaders or don't care about forward compatiblity at the moment.

Christian Rau
  • 43,206
  • 10
  • 106
  • 177
  • Great! That's what I was suspecting. However, i tried to get it working using glVertexAttribPointer since the gl*Pointer calls are deprecated in newer versions of OpenGL. Thanks!!! – Pau Baiget Sep 22 '11 at 16:45
  • 4
    @Pau The bultin attributes are deprecated anyway, so if you use these, you already use deprecated functionality. And if the answer helped, accepting would be appreciated. – Christian Rau Sep 22 '11 at 16:48
  • Thanks Christian, your answer has been very helpful indeed. It was my first question on stackoverflow. – Pau Baiget Sep 22 '11 at 20:14
  • I found that the non-standard behavior working also on AMD too (MabBook Pro 2011, and Mac Pro 2013). I could not understand why it does not work on Intel implementations until found this answer (thanks!). – Yoav Dec 11 '14 at 08:53