GLFW窗口没有响应

时间:2015-09-19 12:14:08

标签: c++ opengl-es

我正在开发一个使用openGL ES 2.0而不是普通openGL的GLFW桌面应用程序!

我编写的代码汇编很好但是当我运行应用程序时,我听到一些奇怪的声音来自我的笔记本电脑,几秒钟后,当我关闭窗口声音停止时,应用程序的窗口没有响应!

是硬件/软件问题还是我做错了什么?

这是我的main.cpp:

#ifndef GLFW_INCLUDE_ES2
#define GLFW_INCLUDE_ES2
#endif
#include "game.h"
#include <GLFW/glfw3.h>

int init_gl();
void shutdown_gl();
void set_main_loop();

GLFWwindow* window;

int main()
{
    if (init_gl() == GL_TRUE) {
        on_surface_created();
        on_surface_changed();
        set_main_loop();
    }
    shutdown_gl();
    return 0;
}

void shutdown_gl()
{
    glfwDestroyWindow(window);
    glfwTerminate();
}

int init_gl()
{
    const int width = 480,
         height = 800;

     if (glfwInit() != GL_TRUE) {
         return GL_FALSE;
     }

     window = glfwCreateWindow(width, height, "Simple example", NULL, NULL);

     if (!window) {
         return GL_FALSE;
     }

     glfwMakeContextCurrent(window);

     return GL_TRUE;
}

void set_main_loop()
{
    while (!glfwWindowShouldClose(window))
    {
        on_draw_frame();
        glfwSwapBuffers(window);
    }
}

告诉我你是否需要来自game.cpp的代码!

代码在Ubuntu 14.04上使用g ++和命令编译:

g++ -I. -I../common -c main.cpp ../common/game.cpp
g++ main.o game.o -o main.exec -lglfw3 -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lGL -lpthread

1 个答案:

答案 0 :(得分:4)

你需要在你的循环中调用glfwPollEvents(),但是我并不是100%肯定,因为声音可能是由于应用程序不是vsync-d引起的。 参考: http://www.glfw.org/docs/latest/quick.html