how can I make a triangle appear on the screen using OpenGL? : <p>I'm trying to make a triangle appear on the screen using OpenGL but when I run the code, a black screen appears</p>

<p>I am currently using a guide I found on the internet (here is the link: <a href="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/" rel="nofollow noreferrer">http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/</a>).</p>

<p>this is the code :</p>

<pre><code>#include &lt;GL/glew.h&gt;
#include &lt;GLFW/glfw3.h&gt;
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int larghezza = 1024;
int altezza = 768;

int main (){
    glewExperimental = true;
    if (!glfwInit() )
    {
        fprintf (stderr, "non è stato possibile inizzializzare glfw\n");
        return -1;
    }
    glfwWindowHint(GLFW_SAMPLES, 4);// 4x antialiasing
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);// utilizza OpenGL 4.1
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);//NON VOGLIO VECCHIE VERSIONI DI OPENGL

    GLFWwindow* window; // crea una finestra
    window = glfwCreateWindow(larghezza, altezza, "FINESTRA 1", NULL, NULL);
    if (!window){
        fprintf (stderr, "Non è stato possibile aprire la finestra!\n");
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window); //inizzializza GLEW
    glewExperimental = true;
    if (glewInit() != GLEW_OK){
        fprintf (stderr, "non è stato possibile inizzializzare GLEW");
        return -1;
    }

    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

    do {
        glClear(GL_COLOR_BUFFER_BIT);



        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &amp;&amp;
          glfwWindowShouldClose(window) == 0 );

    GLuint VertexArrayID;
    glGenVertexArrays(1, &amp;VertexArrayID);
    glBindVertexArray(VertexArrayID);
    static const GLfloat g_vertex_buffer_data[] = {
        -1.0f, -1.0f, 0.0f,
        1.0f, -1.0f, 0.0f,
        0.0f,  1.0f, 0.0f,
    };
    GLuint vertexbuffer;
    // Generate 1 buffer, put the resulting identifier in vertexbuffer
    glGenBuffers(1, &amp;vertexbuffer);
    // The following commands will talk about our 'vertexbuffer' buffer
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    // Give our vertices to OpenGL.
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    glVertexAttribPointer(
                          0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
                          3,                  // size
                          GL_FLOAT,           // type
                          GL_FALSE,           // normalized?
                          0,                  // stride
                          (void*)0            // array buffer offset
                          );
    // Draw the triangle !
    glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -&gt; 1 triangle
    glDisableVertexAttribArray(0);
}
</code></pre>

<p>how can i fix it?</p>
