Reputation: 123
I read the red book (7th edition) and while testing glMultiDrawElements I got nothing on my screen, and "Access violation" error in debug console. I use MVS2010, and here are main code parts I compile:
// C4UB_V2F interwined format, vertex are CCW ordered
static const GLfloat vertex[] = {
// First triangle
0xff0000ff, 0.25f, 1.0f, // nevermind on that incorrect integer colors
0x00ff00ff, 0.0f, 0.0f,
0x0000ffff, 0.5f, 0.0f,
// Second one
0xff0000ff, 0.75f, 0.0f,
0x00ff00ff, 0.5f, 1.0f,
0x0000ffff, 1.0f, 1.0f
};
void init() {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_SMOOTH);
glInterleavedArrays(GL_C4UB_V2F, 0, vertex);
}
static const GLubyte order[] = { 0, 1, 2, 3, 4, 5 };
static GLubyte oneIndices[] = {0, 1, 2};
static GLubyte twoIndices[] = {3, 4, 5};
static GLsizei count[] = {3, 3};
static GLvoid * indices[2] = {oneIndices, twoIndices};
void render() {
glClear(GL_COLOR_BUFFER_BIT);
// This one works perfectly:
//glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, order);
// And this one generates access violation error
// in the book there's no indices casting, but MVS2010 is too lazy to cast it itself
glMultiDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_BYTE, (const GLvoid **)indices, 2);
// This command never executes 'cause of acces violation error occuring
glFlush();
}
Seems to me I've missed something while casting indices, but I can't get what exactly. Any ideas?
Upvotes: 1
Views: 2682
Reputation: 474376
I just checked - printf("%i", glDrawElementsInstanced); is printing zero.
There are two possibilities for that.
Your OpenGL implementation doesn't support them. This would mean that you have ancient drivers, or you aren't creating a context properly. Since you're using FreeGLUT, a context creation problem is unlikely. If your hardware was made in the last 7 years, you should be able to get them.
You did not initialize GLEW. You must call glewInit
after creating the OpenGL window with FreeGLUT. Otherwise, you will not have properly initialized GLEW, and your function pointers will be NULL.
Upvotes: 1
Reputation: 45968
Due to your comments it seems these functions are not supported by your hardware and/or driver. glMultiDrawElements
is supported from 1.4 on and glDrawRangeElements
is supported from 1.2 on. Make sure your hardware supports these versions and you got the latest drivers.
And of course you first have to retrieve the corresponding function pointers before you can use them. This can be done manually by means of wglGetProcAddress
(assuming Windows due to your mentioning of VS) or by an extension loading library, like GLEW.
Upvotes: 0