I don’t mean to hijack your thread, but I too have been having issues porting my older code to modern OpenGL. Below is my snippet of my attempt at Direct State Access, but I just get a blank screen. I’m hoping, since you just went through this yourself, you’d be able to point out what’s wrong. Full code here: pastebin.com/ephfTbCj (Apparently I can’t create URL being new and all…).
First buffer stride should be zero, correct? Followed by the next buffer stride being 3 * sizeof(float)?
Also, I’ve enabled the debug context and it’s clean.
[DEBUG]: Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[DEBUG]: Buffer detailed info: Buffer object 2 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[DEBUG]: Buffer detailed info: Buffer object 3 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
No errors using GDEBugger either.
///////////////
// Locations //
///////////////
GLint positionLocation = glGetProgramResourceLocation ( program, GL_UNIFORM, "position" );
assert ( positionLocation != -1 );
GLint normalLocation = glGetProgramResourceLocation ( program, GL_UNIFORM, "normal" );
assert ( normalLocation != -1 );
GLint modelViewMatrixLocation = glGetProgramResourceLocation ( program, GL_UNIFORM, "ModelViewMatrix" );
assert ( modelViewMatrixLocation != -1 );
GLint normalMatrixLocation = glGetProgramResourceLocation ( program, GL_UNIFORM, "NormalMatrix" );
assert ( normalMatrixLocation != -1 );
GLint projectionMatrixLocation = glGetProgramResourceLocation ( program, GL_UNIFORM, "ProjectionMatrix" );
assert ( projectionMatrixLocation != -1 );
////////////////////
// Vertex Buffers //
////////////////////
// Vertex Buffer
GLuint vertexBuffer;
glCreateBuffers ( 1, &vertexBuffer );
glBindBuffer ( GL_ARRAY_BUFFER, vertexBuffer );
glBufferData ( GL_ARRAY_BUFFER, vertices.size () * sizeof ( GLfloat ), vertices.data (), GL_STATIC_DRAW );
// Index Buffer
GLuint indexBuffer;
glGenBuffers ( 1, &indexBuffer );
glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, indexBuffer );
glBufferData ( GL_ELEMENT_ARRAY_BUFFER, indices.size () * sizeof ( GLuint ), indices.data (), GL_STATIC_DRAW );
// Normal Buffer
GLuint normalBuffer;
glGenBuffers ( 1, &normalBuffer );
glBindBuffer ( GL_ARRAY_BUFFER, normalBuffer );
glBufferData ( GL_ARRAY_BUFFER, normals.size () * sizeof ( GLfloat ), normals.data (), GL_STATIC_DRAW );
//////////////////
// Vertex Array //
//////////////////
GLuint vertexArray;
glCreateVertexArrays ( 1, &vertexArray );
glVertexArrayElementBuffer ( vertexArray, indexBuffer );
glVertexArrayAttribFormat ( vertexArray, positionLocation, 3, GL_FLOAT, GL_FALSE, 0 );
glVertexArrayVertexBuffer ( vertexArray, 0, vertexBuffer, 0, 0 );
glVertexArrayAttribBinding ( vertexArray, positionLocation, 0 );
glEnableVertexArrayAttrib ( vertexArray, positionLocation );
glVertexArrayAttribFormat ( vertexArray, normalLocation, 3, GL_FLOAT, GL_FALSE, 0 );
glVertexArrayVertexBuffer ( vertexArray, 0, normalBuffer, 0, 3 * sizeof(float));
glVertexArrayAttribBinding ( vertexArray, normalLocation, 0 );
glEnableVertexArrayAttrib ( vertexArray, normalLocation );
glBindVertexArray ( vertexArray );