Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to render a Quad via VAO, IBO and VBO but nothing is drawn. I'm using glDrawRangeElements in OS X OpenGL 3.2 Core context. The screen is completely black without any error. GLFW3 is used to create window and context.

Window opening/Context creation code

_mainWindow  = glfwCreateWindow(width, height, title, monitor, NULL);
if(_mainWindow == NULL)
    return false;
_mainWindowWidth  = width;
_mainWindowHeight = height;
glfwSetKeyCallback(_mainWindow, _onKeyEvent);

glewExperimental = GL_TRUE;

_openGLVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));

Shader sources (compiled successfully). Custom FragColor is binded.

_vertexShaderSource =
            "#version 150 core\n"
            "in vec3 in_Position;\n"
            "in vec3 in_Normal;\n"
            "in vec2 in_TexCoord;\n"
            "uniform mat4 ModelViewProjection;\n"
            "void main()\n"
            "   gl_Position = ModelViewProjection * vec4(in_Position, 1.0);\n"
_fragmentShaderSource =
            "#version 150 core\n"
            "out vec4 FColor;"
            "void main()\n"
            "   FColor = vec4(1.0, 1.0, 1.0, 1.0);\n"


Vertex* vertices = new Vertex[6];

vertices[0].nz = 1.0f;
vertices[1].nz = 1.0f;
vertices[2].nz = 1.0f;
vertices[3].nz = 1.0f;
vertices[4].nz = 1.0f;
vertices[5].nz = 1.0f;

vertices[1].y  = height;
vertices[1].v0 = 1.0f;

vertices[2].x  = width;
vertices[2].y  = height;
vertices[2].u0 = 1.0f;
vertices[2].v0 = 1.0f;

vertices[4].x  = width;
vertices[4].u0 = 1.0f;

vertices[5].x  = width;
vertices[5].y  = height;
vertices[5].u0 = 1.0f;
vertices[5].v0 = 1.0f;

_mesh->setVertices(vertices, 6);
vertices = NULL;

Uint16* indices = new Uint16[6];

indices[0] = 0;
indices[1] = 2;
indices[2] = 3;
indices[3] = 0;
indices[4] = 1;
indices[5] = 3;

indices = NULL;

Buffer update (checked the data, it seems to be correct)

// Update VBO
if(_vertexBufferObjectID == 0)
        glGenBuffers(1, &_vertexBufferObjectID);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferObjectID);

float* data = new float[_vertexCount * sizeof(Vertex) / sizeof(float)];
Uint64 begin = 0;
for(Uint32 i = 0; i < _vertexCount; i++)
    begin = i * 8;
    data[begin]     = _vertices[i].x;
    data[begin + 1] = _vertices[i].y;
    data[begin + 2] = _vertices[i].z;
    data[begin + 3] = _vertices[i].nx;
    data[begin + 4] = _vertices[i].ny;
    data[begin + 5] = _vertices[i].nz;
    data[begin + 6] = _vertices[i].u0;
    data[begin + 7] = _vertices[i].v0;

glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * _vertexCount, &data[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

delete[] data;
data = NULL;

// Update IBO
if(_indexBufferObjectID == 0)
    glGenBuffers(1, &_indexBufferObjectID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferObjectID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Uint16) * _vertexCount, &_indices[0], GL_STATIC_DRAW);

// Update VAO
if(_vertexArrayObjectID == 0)
    glGenVertexArrays(1, &_vertexArrayObjectID);

glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferObjectID);
// Vertices

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), ((char*)NULL + (0)));
// Normals
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), ((char*)NULL + (12)));
// TexCoords
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), ((char*)NULL + (24)));

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferObjectID);

glBindBuffer(GL_ARRAY_BUFFER, 0);

Rendering code

GLuint mvp = glGetUniformLocation(material->_programID, "ModelViewProjection");
glUniformMatrix4fv(mvp, 1, false, glm::value_ptr(camera_mvp));


// Draw
glDrawRangeElements(GL_TRIANGLES, 0, 3, node->_mesh->_vertexCount, GL_UNSIGNED_SHORT, NULL);

Note: camera_mvp is Orthographic

0.00333333_0___________0 0 
0__________0.00333333__0 0 
0__________0__________-1 0 
599________599_________0 1

Program Linking

_programID = glCreateProgram();
glAttachShader(_programID, vertex_shader);
glAttachShader(_programID, fragment_shader);

glGetProgramiv(_programID, GL_LINK_STATUS, &result);
glGetProgramiv(_programID, GL_INFO_LOG_LENGTH, &loglen);

if(loglen > 0)
    char* log = new char[loglen];

    glGetProgramInfoLog(_programID, loglen, 0, log);
    _lastInfoLog = log;

    delete log;
    log = NULL;

if(result == GL_FALSE)
    return false;

glBindAttribLocation(_programID, 0, "in_Position");
glBindAttribLocation(_programID, 1, "in_Normal");
glBindAttribLocation(_programID, 2, "in_TexCoord");
glBindFragDataLocation(_programID, 0, "FColor");

share|improve this question
You need to debug the code and ensure that you're properly catching errors. Start from a known working example and move on from there. With the amount of code you've included here, it's clear you haven't gotten very far in narrowing down where the problem might be coming from. You should do so and update your question with more specifics. – Byte56 Jul 24 '13 at 21:03
I'm catching ALL errors at the main loop event and as you know I cannot skip any of them just because they are stacked. I've placed a lot of code here just because any OpenGL adept could see anything he needs to write the answer. I really don't have any idea why it doesn't work. I debugged all my code and didn't discovered anything wrong. If I could cout from shaders I've solved the problem but I'm writing like a blind man trying to guess what's wrong. I decided to write here just because I was fighting with my problem for several days. – nmindiedev Jul 25 '13 at 5:20
Have you tried tools like gDebugger? You can view VBO data on the graphics card and see any OpenGL errors that come up. – Byte56 Jul 25 '13 at 12:52
My OS X version is not supported by gDEBugger :C – nmindiedev Jul 25 '13 at 15:07
@nmindiedev there's a few things a little suspect at first glance. Did you make sure that the Vertex class initialises all the values to 0.0 like you seem to assume? Also what are those 599 entries in the MVP matrix, I don't think I've seen anything but 0 in those 2 positions of the matrix. Then there's of course the matter of the depth buffer, do you have one, if not, did you make sure to disable depth test, if you do, did you make sure to clear it before drawing again? – PeterT Jul 25 '13 at 15:42
up vote 4 down vote accepted

I pasted together a running version here (just for demo purposes, I hacked around your existing names and structures)

Like I said, your indices were wrong. How you got your MVP matrix I don't know, but it still looks wrong, maybe you transposed it or printed it out transposed.

Also, the way you used glBindAttribLocation() and glBindFragDataLocation() is slightly wrong, you need to either call it before linking or link the program again after calling it.

These are your vertecies visualized:

|      /|
|     / |
|    /  |
|   /   |
|  /    |
| /     |
0&3     4

and you tried to draw 0,2,3 and 0,1,3. As you see that would draw triangles with no area as I explained to you.

share|improve this answer
Thank you very much! It worked! Next time I will be more attentive. – nmindiedev Jul 26 '13 at 18:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.