-1

I'm a beginner of OpenGL. After configuring the develop environment on Windows 7 64-bit, use vs2012, There's no effect when I run the demo program from gflw website.

here the code

void runRenderLoop(GLFWwindow *window){

glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetKeyCallback(window,keyCallback);

while (!glfwWindowShouldClose(window)) {
    int width;
    int height;
    glfwGetFramebufferSize(window,&width,&height);
    glViewport(0,0,width,height);
    glClear(GL_COLOR_BUFFER_BIT);

    GLfloat ratio = static_cast<GLfloat>(width)/static_cast<GLfloat>(height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);

    glBegin(GL_TRIANGLES);
        glColor3f(1.f, 0.f, 0.f);
        glVertex3f(-0.6f, -0.4f, 0.f);
        glColor3f(0.f, 1.f, 0.f);
        glVertex3f(0.6f, -0.4f, 0.f);
        glColor3f(0.f, 0.f, 1.f);
        glVertex3f(0.f, 0.6f, 0.f);
    glEnd();

    glfwSwapBuffers(window);
    glfwPollEvents();
}
glfwMakeContextCurrent(NULL);

glfwDestroyWindow(window);
glfwTerminate();

}

What weird is, i can see the window is created properly, also when i attach a break point between glBegin() and glEnd(), it triggers correctly. Also, glfw handles my keyCallback perfectly. However, the window is totally dark, nothing there. It really confused me

My current opengl version is 3.2

  • 1
    opengl 3.2 core? if so refer to http://stackoverflow.com/q/28361703/731620 – ratchet freak Mar 11 '16 at 11:32
  • Can you check with `glGetError` if there are any errors showing up? – BDL Mar 11 '16 at 12:10
  • 2
    Fixed function pipeline is removed from 3.2 core profile onwards. Better use vao/vbo and shaders. What language are you using opengl in? Here is a tutorial for C/C++ http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/ – gallickgunner Mar 11 '16 at 12:11

1 Answers1

1

My current opengl version is 3.2

If that's a core profile context (no compatibility) then glBegin / glEnd and friends are invalid to use: They've been removed from OpenGL-3 core and later.

datenwolf
  • 159,371
  • 13
  • 185
  • 298