尝试在打开GL中创建空白窗口时出现异常输出

Man*_*ngh 0 c c++ opengl graphics glfw

我试图在GLFW的帮助下在OpenGL中创建一个空白窗口.下面是我的代码

#include <stdio.h>
#include <stdlib.h>

#include <GL/glew.h>

#include <glfw3.h>
GLFWwindow* window;

#include <glm/glm.hpp>
using namespace glm;

int main( void )
{

    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    window = glfwCreateWindow(800,600,"learnopengl",NULL,NULL);
    if (window == NULL)
    {
        fprintf(stderr,"there is a problem with window creation\n");
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);

    glewExperimental = GL_TRUE;
    if (glewInit() != GLEW_OK)
    {
        fprintf(stderr,"Failed to initialize GLEW\n");
        return -1;
    }
    int width, height;
    glfwGetFramebufferSize(window,&width,&height);

    glViewport(0,0,width,height);

while(!glfwWindowShouldClose(window))
{
    glfwPollEvents();
    glfwSwapBuffers(window);
}


    glfwTerminate();
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试运行上面的代码而不是黑色空白时,它会在新创建的窗口中显示当前屏幕的实例.

der*_*ass 5

为什么您希望此代码导致空白窗口?

根据规范,在交换缓冲区后,后台缓冲区内容将变为未定义(最初,它们当然也是未定义的).因此,您应该得到的输出也是未定义的,基本上任何东西都可能出现.

glClear(GL_COLOR_BUFFER_BIT)如果需要某些已定义的输出,请在渲染循环中添加一个.