gpt4 book ai didi

c++ - glfw 在 vi​​sual studio 2017 上一打开就关闭

转载 作者:行者123 更新时间:2023-11-30 05:12:22 25 4
gpt4 key购买 nike

这段测试代码导致opengl窗口一出现就打开又消失。是的,我正在从源代码编译库。

我的代码有什么问题?

#include<glad\glad.h>
#include<GLFW\glfw3.h>
#include<stdio.h>
#include<stdlib.h>

int main()
{
if (glfwInit() == false)
{
fprintf(stderr, "GLFW Failed to initialise");
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

GLFWwindow * window = glfwCreateWindow(640, 480, "Test OPENGL", NULL, NULL);
if (!window)
{
fprintf(stderr, "window failed to open");
glfwTerminate();
return -1;
}

glfwMakeContextCurrent(window);
//system("pause");
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
fprintf(stderr, "Failed to initialize GLAD");
return -1;
}
return 0;
}

最佳答案

You need an event loop to pump the message queue and swap buffers :

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

// draw stuff

glfwSwapBuffers(window);
}

关于c++ - glfw 在 vi​​sual studio 2017 上一打开就关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44569974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com