# How to get a safe index for glVertexAttribPointer without shader?

I'm learning to use VBOs and trying to keep it simple before building up. Trying to do it without writing a shader right now. It looks like this is possible, but I cannot seem to find a way to get the index parameter for glVertexAttribPointer.

I've seen that you can get the index with glGetAttribLocation, but that function seems to require a shader be passed in to get the index.

I don't want to assign the index, because I'm worried about different pieces of a project accidentally using the same index and causing problems. (If there's some reason I shouldn't be worried about that, please let me know)

Question is: Without using shaders and without assigning the index, how can I get the index for glVertexAttribPointer?

What you're asking for is impossible.

You are essentially asking how to get the address of an object in memory without ever actually creating the object.

I don't want to assign the index, because I'm worried about different pieces of a project accidentally using the same index and causing problems.

You shouldn't be worried about that. That isn't a real problem unless you're being really sloppy.

The indices should be assigned with names to avoid sloppiness. That is, in your C code make a define/enum named something like ATTRIB_POSITION that's assigned to 0, and then in your GLSL code use defines or includes (via a GLSL preprocessor) named the same thing assigned to the same value. Then you know that POSITION always matches. Do the same thing for other common properties (normals, texcoords, colors, etc.).

You can take this a step further and have pre-defined full layouts (e.g. a SkinnedMesh layout that has various attributes and their locations hard-coded). Then instead of trying to check if a shader has all the same attributes as some source data you're instead just making sure that a shader matches a particular pre-defined layout, of which all objects will use.

• Making more sense, but still a little confused. It sounds like the index needs to match the shader. Few questions: 1. If I'm not writing a shader, does that imply there is no shader or there is some default shader? 2. When not writing a shader, how do I know what the indices need to match (or does index not matter in this case)?3. If I'm drawing multiple objects using different vertex sets, they would all use the same index? – Dtor Oct 28 '16 at 14:57
• @Dtor: 1. you'd be on the fixed-function pipeline with no shader. 2. the fixed-function pipeline doesn't use attributes, it uses functions like glVertexPointer. 3. all models with the same general type of material (e.g. the same shader) would use the same attribute indices. – Sean Middleditch Oct 28 '16 at 15:20
• Ah, I see. So without writing a shader, I should not be using glVertexAttribPointer at all? – Dtor Oct 28 '16 at 15:33
• @Dtor: correct. Some hardware vendors' drivers assign pre-defined and hard-coded indices to fixed-function attributes but this is non-standard; that means that it might work on your machine but will break on a majority of other machines. – Sean Middleditch Oct 28 '16 at 15:37