我正在使用 glut 制作一个简单的游戏。过剩显示回调如下所示:
std::chrono::duration<float> timeDelta = std::chrono::high_resolution_clock::now() - lastFrame;
lastFrame = std::chrono::high_resolution_clock::now();
std::cout << (1 / timeDelta.count()) << "fps" << std::endl; // print fps
game->draw();
std::cout << "finished frame" << std::endl << std::endl;
glutSwapBuffers();
由于某种原因,该函数永远不会完成,控制台输出如下所示:
166.639fps
draw game
166.667fps
draw game
无限重复。
该draw
函数如下所示:
std::cout << "draw game" << std::endl;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glClearColor(RENDER_BRIGHTNESS, RENDER_BRIGHTNESS, RENDER_BRIGHTNESS, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera.draw();
world.draw();
//Bind 0, which means render to back buffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, width, height);
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, frameTexture);
glGenerateMipmap(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glColor4d(1, 1, 1, 1);
glTexCoord2d(0, 0); glVertex2d(0, 0);
glTexCoord2d(1, 0); glVertex2d(width, 0);
glTexCoord2d(1, 1); glVertex2d(width, height);
glTexCoord2d(0, 1); glVertex2d(0, height);
glEnd();
camera.draw()
简单地操作 gls 矩阵。该函数使用平截头体剔除(从此处复制:httpworld.draw()
://www.crownandcutlass.com/features/technicaldetails/)遍历八叉树的节点(使用此实现: http: //nomis80.org/code/octree.html ) frustum.html ) 并将叶子绘制为立方体。
draw game
由game->draw()
函数打印。finished frame
从不打印。看起来该game->draw()
函数递归调用显示函数,即使它位于不同的文件中并且没有指向它的指针。甚至可以用代码存档这种效果吗?这是 mingw-g++ 中的错误吗?
八叉树经常使用不安全函数 reinterpret_cast。这可能是问题的根源吗?
我希望没有必要发布完整的源代码,因为它非常庞大。