更改GLUT调用以与MFC/C ++一起使用 [英] changing GLUT calls to work with MFC/C++

查看:103
本文介绍了更改GLUT调用以与MFC/C ++一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用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.

我已遵循本教程: 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 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!

推荐答案

我刚刚浏览了链接到的教程;在第二页上,可以找到以下几行内容(我对代码进行了一些整理):

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);
}

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

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.

我希望能有所帮助.

这篇关于更改GLUT调用以与MFC/C ++一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆