changing GLUT calls to work with MFC/C++

…衆ロ難τιáo~ 提交于 2019-12-07 17:20:17

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/3344583/changing-glut-calls-to-work-with-mfc-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!