【问题标题】:GLFW window not respondingGLFW 窗口没有响应
【发布时间】:2015-09-19 22:20:34
【问题描述】:

我正在开发一个使用 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

【问题讨论】:

    标签: c++ opengl-es


    【解决方案1】:

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

    【讨论】:

    • 你说得对,我没有调用 glfwPollEvents()。应用程序不再崩溃,声音也来了,因为我渲染了太多帧和 glfwSwapInterval(1);停止声音,所以你是对的 2 次。感谢您的快速回答!
    猜你喜欢
    • 1970-01-01
    • 2018-10-16
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 1970-01-01
    相关资源
    最近更新 更多