无法创建简单的彩色窗口OpenGL,GLFW,GLEW

问题描述

我已经尝试了几天来创建一个带有蓝色背景的简单窗口,但是由于某些未知的原因,我只得到了一个黑色窗口。我正在使用以下3个文件来编译一个小程序。

  • main.cpp
#include "wind.hpp"

int main()
{
    wind display;
    display.test();
}
  • wind.hpp
#include <GL/glew.h>
#include <GLFW/glfw3.h>

class wind
{
public:

    void test();

};
  • wind.cpp
#include "wind.hpp"

void wind::test()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);

    GLFWwindow* window = glfwCreateWindow(800,600,"LearnOpenGL",nullptr,nullptr);

    glfwMakeContextCurrent(window);

    glewInit();

    std::cout << "Version: " << glGetString(GL_VERSION) << std::endl;

    static unsigned frameCount = 0;

    while (true)
    {
        glClearColor(0.0f,0.0f,1.0f,1.0f);
        glClear(GL_COLOR_BUFFER_BIT);


        std::cout << ++frameCount << '\r';

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
}

我编译包含这3个文件的程序,输出为:

enter image description here

系统:Ubuntu 18.04.5 LTS。 使用的工具:OpenGL(彩色),GLFW(用于窗口),GLEW(用于OpenGL调用),CMake(用于建筑物)。

一些事实:

  • glfwCreateWindow(800,NULL,NULL) != NULL
  • glewInit() == GLEW_OK
  • 在控制台中,我得到的唯一输出是Version: 。后续的std::cout似乎都没有执行(没有输出)。
  • 如果删除行std::cout << "Version: " << glGetString(GL_VERSION) << std::endl;,则会在控制台中获得frameCount值(因此,主循环正在运行)。但是窗户还是黑的。
  • 如果我使用“ wind.hpp”和“ wind.cpp”(例如“ libwind.a”)创建静态库,然后将其链接到程序(“ main.cpp”)并进行编译。我得到了蓝色的窗口。但是我应该只为创建这个简单的蓝色窗口而做所有这一切。我不明白为什么它会这样运作,而不是其他...

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...