gpt4 book ai didi

c++ - OpenGL 跳过 visual studio 上的主要功能

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:00:20 28 4
gpt4 key购买 nike

我正在尝试在 Visual Studio 2010 中运行以下 c++ opengl 代码。我正在使用 openglut 作为 opengl 实用工具包。

#include <iostream>
#include <gl\openglut.h>

using std::cout;
using std::endl;

void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

void SetupRC()
{
glClearColor(0, 0, 1.0f, 1.0f);
}

int main(int argc, char* argv[])
{
cout << "Test1" << endl;

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);

SetupRC();

glutMainLoop();

cout << "Test2" << endl;

return 0;
}

代码编译正确,但是当我在没有调试的情况下运行时,控制台上没有显示任何内容。当我在第一个 cout 语句处创建断点并使用调试运行时,它不会在断点处停止。它似乎跳过了主要功能。在我注释掉 2 个 cout 语句和干净的解决方案之间的 glut、gl 语句之后,它的行为正确(在断点处停止)。如果我不清理解决方案,它不会正常运行,但我看到 visual studio 在我进行更改后编译代码。这些奇怪的行为只有在我包含 opengl 代码时才会发生。正常进行更改后,我不需要清理解决方案。这是什么原因?

最佳答案

通常,glutMainLoop 函数不会返回。当您关闭窗口时,该函数将完全停止应用程序。因此,该函数调用之后的任何内容都不会被执行。

即使后面的代码被执行,它也只会在您关闭窗口时发生。 glutMainLoop 是等待您对窗口执行操作的工具。当窗口中发生事件(鼠标移动、鼠标单击、显示需要更新、计时器等)时,它会调用您注册的回调函数。

将其视为一个 while(true) 循环。

关于c++ - OpenGL 跳过 visual studio 上的主要功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8966128/

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