Triángulo simple usando OpenGL y GLFW [duplicado]

Esta pregunta ya tiene una respuesta aquí:

¿Cómo creo un contexto OpenGL 3.3 en GLFW 3? 1 respuesta

Escribí un pequeño programa para mostrar un triángulo simple usando el buffer de vértices. Para las ventanas estoy usando glfw, mi entorno es Mac 10.9, XCode 5.

La ventana aparece negra pero el triángulo no es pintura.

Aquí el código:

#include <GLFW/glfw3.h>
#include <OpenGL/gl.h>
#include <iostream>

int main(int argc, const char * argv[])
{
    GLFWwindow* window;
    if (!glfwInit())
    {
        return -1;
    }

    glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1);
    glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    window = glfwCreateWindow(640, 480, "Hello Triangle", NULL, NULL);
    if (!window) 
    {
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window);

    GLfloat verts[] =
    {
        0.0f,  0.5f,  0.0f,
        0.5f, -0.5f,  0.0f,
        -0.5f, -0.5f,  0.0f
    };

    //Generate a buffer id
    GLuint vboID;

    //Create a buffer on GPU memory
    glGenBuffers(1, &vboID);

    //Bind an arraybuffer to the ID
    glBindBuffer(GL_ARRAY_BUFFER, vboID);

    // Fill that buffer with the client vertex
    glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);

    //Enable attributes
    glEnableVertexAttribArray(0);

    // Setup a pointer to the attributes
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    while (!glfwWindowShouldClose(window))
    {
        glDrawArrays(GL_TRIANGLES, 0, 3);

        glfwPollEvents();
        glfwSwapBuffers(window);
    }

    glfwTerminate();
    return 0;
}

Respuestas a la pregunta(1)

Su respuesta a la pregunta