I'm pretty sure that I have the code setup properly to do this. My graphics card supports openGL 4.0, but I'm still using a GL 2.0 context.
Can I still use the extension? My code compiles and glew seems to find the extension pointer. I assume because it doesn't crash that everything is good and I just have to debug this but I wanted to make sure.
glDrawElementsInstanced not drawing
According to OpenGL's reference pages, you need a 3.1 or higher context.
http://www.opengl.org/sdk/docs/man4/html/glDrawElementsInstanced.xhtml
Hope this helps.
You need to check for the GL_ARB_draw_instanced extension, and if that exists, use glDrawElementsInstancedARB. Even if glDrawElementsInstanced exists and seems to work without problems, GL doesn't guarantee that the extension function pointer and the non-extension function pointer are the same. The only guarantee you have is that if an extension is available, then the functions defined by that extension are available.
I got it working now. I forgot with this mesh I was using is using non-indexed and needed to use glDrawArraysInstanced instead of glDrawElementsInstanced
My new problem is this. The second I add in all this per-instance attributes along with glDrawArraysInstanced, nothing show up. My shader works when I draw with glDrawArrays so the shader is perfectly fine. glDrawArraysInstanced is working, but just when I turn on the surrounding attribute code which is to pass an instance color down, nothing show. I don't know if its somehow over-writing other attributes or if I have messed up badly.
I can say that a don't use vertex attributes for the rest of the data. I use multi-texture coords for tangents and other per vertex data at the moment. Is this my problem that I'm using gl_Vertex and the built-in attributes along with my own custom ones? attribLoc seems to = 4 and be valid tho.
int attribLoc = glGetAttribLocation(NormalMap.handle_, "color");
glEnableVertexAttribArray(attribLoc);
glBindBuffer(GL_ARRAY_BUFFER, VBO_Index);
glVertexAttribPointer(attribLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (void*)(0));
glVertexAttribDivisor(attribLoc, 2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDrawArraysInstanced(GL_TRIANGLES, 0, meshToRender->num_faces*3, 2);
glDisableVertexAttribArray(attribLoc);
You still need to use the ARB versions of the function if you only have a 2.0 context
I think the problem is you have the divisor set to 2? This means the colour attribute will change every 2 instances, so your 2 instances will have the same colour. If you want it to be per-instance, you need to set the divisor to 1:
glVertexAttribDivisor(attribLoc, 1);
That's correct, I tried using per instance and per 2 instances, but at the end of the day that attribute is a color to the shaders, nothing to do with position. So I should at least see something rendered. Like I do without using the per-instance attributes.
ARB didnt do anything, I don't use ARB in anything, I think glew strips that by default. Either way it worked just not with the attributes turned on, hopefully this doesn't turn into a long bug.
Sorry, I completely misread your post. As far as I know, you can't mix the generic vertex attributes (glVertexAttribPointer) with the built-in attributes - how would the built-in attributes know which generic attribute to use? You should be using your own custom attributes in this case.
I'll give that a try. Well it does return 4 as a valid index, and i have pos,normal,texcoord,tangent so the next attribute would be 4.
I would think it still knows though because my shader compiles knowing what built-in and custom attributes to use an build an index map for them. I still call glVertexPointer, normal texcoord, which those might map to a default.
I get what you are saying though it probably is the issue, don't know what else it would be.