Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: MFC + OpenGL freezes

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2002
    Location
    St. Louis, MO USA
    Posts
    181

    MFC + OpenGL freezes

    Hi. I'm kind of a newbie to MFC proramming, but I've been doing OpenGL for a while now. I am making a program called Particle Studio, which shows a particle cluster in the view window, and provides a series of dialogs for the user to edit the attributes of the particles.

    Everything works fine except that after it's been running for a while it sometimes freezes. The freezes are not caused by my particle code, because the particle code is taken directly from my main engine (which uses SDL), and there are no freezes in that.

    The program is an SDI program, and I use the view window to issue OpenGL commands. I update my scene and redraw it when the OnIdle function of the app is called. In the PreCreateWindow function for the view, I specify the following class styles:

    AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_OWNDC , AfxGetApp()->LoadStandardCursor(IDC_ARROW), NULL,NULL);

    I set up OpenGL as follows:

    int CParticleStudioView::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CView::OnCreate(lpCreateStruct) == -1)
    return -1;

    // TODO: Add your specialized creation code here
    static HGLRC hRC = NULL;
    static HDC hDC = NULL;

    hDC = ::GetDC(m_hWnd);
    SetDCPixelFormat(hDC);

    hRC = wglCreateContext(hDC);
    wglMakeCurrent(hDC, hRC);

    glClearColor(0,0,0,1);

    TEXTUREMANAGER.LoadTextures();
    SCENEMANAGER.Init();

    return 0;
    }

    SetDCPixelFormat is a function I wrote that picks the best pixel format.


    Any ideas what is causing the freezing?

    [This message has been edited by ioquan (edited 11-18-2002).]

  2. #2

    Re: MFC + OpenGL freezes

    OnIdle processes while the system is idle. something of higher priority is probably causing the slow down. Try a flavor of InvalidateRect() after swapbuffers in OnDraw(). If that doesn't work bypass the MFC message processing loop with your own message handling loop. See www.mfcogl.com

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2002
    Location
    St. Louis, MO USA
    Posts
    181

    Re: MFC + OpenGL freezes

    Thanks!

  4. #4
    Intern Contributor
    Join Date
    Feb 2002
    Posts
    68

    Re: MFC + OpenGL freezes

    This may be obvious, but first make sure the OnIdle handler returns non-zero, indicating that you want to receive further idle messages.. If this fails, you could use SetTimer to fire an OnTimer() regularly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •