更改 GLUT 调用以与 MFC/C++ 一起使用

发布于 2024-09-12 00:16:21 字数 568 浏览 2 评论 0原文

我有一个使用 GLUT 进行 OpenGL 渲染的程序。现在我需要它位于 MFC 项目内部,以便它可以与另一个程序组件一起使用。

我遵循了本教程:http://www.codeguru.com/cpp/gm/opengl/openfaq/article.php/c10975__1/Setting-Up-OpenGL-in-an-MFC-Control.htm

当计时器触发时,我正在调用作为 GLUT 显示回调的函数,但这不起作用,因为渲染取决于 GLUT 空闲回调中发生的事情。我不明白应该在 MFC 程序中的哪里调用 GLUT 空闲回调。我是否应该为其创建一个单独的事件处理程序,如果是,是哪个事件?或者我做了其他完全错误的事情?我对 OpenGL 相当熟悉,但这是我第一次使用 MFC,所以我可能在这方面犯了错误。

非常感谢您抽出时间;我真的很感激!

I have a program that uses GLUT for its OpenGL rendering. Now I need it to be inside of a MFC project so that it can work with another program component.

I've followed this tutorial: http://www.codeguru.com/cpp/g-m/opengl/openfaq/article.php/c10975__1/Setting-Up-OpenGL-in-an-MFC-Control.htm

I am calling the function that was the GLUT display callback when the timer fires, but that's not working because the rendering depends on something that happens in the GLUT idle callback. I don't understand where I should call the GLUT idle callback in my MFC program. Is there a separate event handler I should make for it, and if so, which event? Or am I doing something else completely wrong? I'm fairly familiar with OpenGL but this is my first experience with MFC so I am probably erring on that side.

Thanks so much for your time; I really appreciate it!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2024-09-19 00:16:21

我刚刚浏览了您链接到的教程;在第二页上,可以找到以下内容(我稍微清理了代码):

void COpenGLControl::OnTimer(UINT nIDEvent)
{
   if(nIDEvent==1)
   {
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    
         oglDrawScene();
         // try to insert your idle function code here
         SwapBuffers(hdc);    
   }
   CWnd::OnTimer(nIDEvent);
}

所以,基本上这是教程建议的 glutIdleFunc 的替代品。我只是尝试在调用 SwapBuffers 之前插入在空闲函数中调用的代码。

我希望这有帮助。

I just browsed the tutorial you've linked to; on page two, something along the following lines can be found (I cleaned up the code a little bit):

void COpenGLControl::OnTimer(UINT nIDEvent)
{
   if(nIDEvent==1)
   {
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    
         oglDrawScene();
         // try to insert your idle function code here
         SwapBuffers(hdc);    
   }
   CWnd::OnTimer(nIDEvent);
}

So, basically this is the replacement for glutIdleFunc suggested by the tutorial. I'd simply try to insert the code called in your idle function before the call to SwapBuffers.

I hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文