c++openglmfcwgl

changing GLUT calls to work with MFC/C++


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!


Solution

  • 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.