Measure running time in Opengl on Windows?
<p>I would like to measure running time of render function in opengl. <br>
I use <a href="https://www.nuget.org/packages/nupengl.core/" rel="nofollow noreferrer">nupengl</a> Nuget plugin on Visual studio 2015. <br>
In the code below, I would like to measure time to draw a triangle. <br>
However, it crash at glGenQueries(2, queryID) 
 <a href="https://i.stack.imgur.com/aVnNe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aVnNe.png" alt="Crash"></a><br>
Please check my code below or on <a href="https://github.com/ttpro1995/opengl_querytime" rel="nofollow noreferrer">github</a></p>

<pre><code>#include &lt;GL\glew.h&gt;
#include &lt;GL\freeglut.h&gt;
#include &lt;iostream&gt;

void display(void)
{
    GLuint64 startTime, stopTime;
    unsigned int queryID[2];

    // generate two queries
    glGenQueries(2, queryID);
        // issue the first query
        // Records the time only after all previous 
        // commands have been completed
        glQueryCounter(queryID[0], GL_TIMESTAMP);

    // call a sequence of OpenGL commands
        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(1.0f, 1.0f, 1.0f); //Defining color (white)
        glBegin(GL_LINE_LOOP);
        glVertex3f(5.0f, 5.0f, 0.0f);
        glVertex3f(25.0f, 5.0f, 0.0f);
        glVertex3f(25.0f, 25.0f, 0.0f);
        glEnd();
        glFlush(); 

        // issue the second query
        // records the time when the sequence of OpenGL 
        // commands has been fully executed
        glQueryCounter(queryID[1], GL_TIMESTAMP);
        // wait until the results are available
        GLint stopTimerAvailable = 0;
        while (!stopTimerAvailable) {
            glGetQueryObjectiv(queryID[1],
            GL_QUERY_RESULT_AVAILABLE,
            &amp;stopTimerAvailable);
    }

    // get query results
    glGetQueryObjectui64v(queryID[0], GL_QUERY_RESULT, &amp;startTime);
    glGetQueryObjectui64v(queryID[1], GL_QUERY_RESULT, &amp;stopTime);

    printf("Time spent on the GPU: %f ms\n", (stopTime - startTime) / 1000000.0);

}
void init(void)
{
    /* select clearing color */
    glClearColor(0.5, 0.5, 0.5, 0.0);
    /* initialize viewing values */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 30.0, 0.0, 35.0, -1.0, 1.0);
}
int main(int argc, char** argv)
{

    glutInit(&amp;argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(600, 600);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("TRIANGLE");
    init();
    const char* version = (const char*)glGetString(GL_VERSION);
    std::cout &lt;&lt; version;

    glutDisplayFunc(display);
    glutMainLoop();
    return 0; /* ANSI C requires main to return an int. */
}
</code></pre>