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 10 of 10

Thread: OpenGL + Windows controls

  1. #1
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    232

    OpenGL + Windows controls

    Hello!

    I am trying to make a simple application using OpenGL and WinAPI. I've got a dialog form where the scene - together with some windows controls (edit box, button and a check box) - is displayed. Everything seems fine but after my dialog loses focus (i.e, it hides under other window), the windows controls are not redrawed when the dialog gets its focus back again.

    You can take a look and see what I mean : priv.ckp.pl/aero/window.png

    I guess that the problem should be solved somewhere around WM_PAINT message. For the time being, here is what I do after getting WM_PAINT message :

    case WM_PAINT: // should be called continuously
    Render(); // just render GL scene (that's where SwapBuffers() is called)
    return TRUE;

    I'd be thankful if you could help me with this one!

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: OpenGL + Windows controls

    You say dialog, but it doesn't look like a standard dialog.

    Is the GUI drawn in your render callback or is it a windows modeless dialog?

    This is probably a simple drawing error if you render the GUI.

    If it's a modeless dialog then you probably need to handle the dialog's events correctly, realize it's a separarte thread.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    232

    Re: OpenGL + Windows controls

    It's a modal dialog box which is created with a call to DialogBox() just at the beggining of my WinMain().

    Actually, I don't render GUI at all. Once windows controls are created, I don't do anything with them. It works ok until the window hides behind some other windows and becomes visible again.

    To be honest, my problem disappears when I add calls to BeginPaint()/EndPaint() within WM_PAINT. Unfortunately when I do so, WM_PAINT is no longer being send to the event handler and my GL scene 'freezes'. I don't know where to put a call to Render() function.

    Maybe I should simply try a modeless dialog?

    Thank you

  4. #4
    Guest

    Re: OpenGL + Windows controls

    When you get the focus back try calling:
    Invalidate();
    UpdateWindow();

  5. #5
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    232

    Re: OpenGL + Windows controls

    I came up with the following solution. I've made a modeless dialog so I can have a control on a message loop.

    </font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> while (g_WindowHandle && (bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
    {
    if (bRet == -1)
    {
    // Handle the error and possibly exit
    }
    else if (!IsWindow(g_WindowHandle)

  6. #6
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    232

    Re: OpenGL + Windows controls

    Heh.

    I came up with the following solution. I've made a modeless dialog so I can have a control on a message loop.

    </font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> while (g_WindowHandle && (bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
    {
    if (bRet == -1)
    {
    // Handle the error and possibly exit
    }
    else if (!IsWindow(g_WindowHandle)

  7. #7
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    232

    Re: OpenGL + Windows controls

    :F

    Sorry for the mess. Something has screwed up.

    I came up with the following solution. I've made a modeless dialog so I can have a control on a message loop.

    </font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> while (g_WindowHandle && (bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
    {
    if (bRet == -1)
    {
    // Handle the error and possibly exit
    }
    else if (!IsWindow(g_WindowHandle)

  8. #8
    Guest

    Re: OpenGL + Windows controls

    Don't use the double-pipe OR operator in the code block

    There should be a warning somewhere on this site

    Cheers.

  9. #9
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: OpenGL + Windows controls

    A modal dialog blocks your code, it is single threaded, you get no app cycles or rendering while the dialog is running and you need to kill it after use, that's why it's called modal.

    Basically while the dialog is in use your app is out to lunch, when you're done with it you return to your app and the dialog is gone.

    I think I got this the right way around, it's been a while :-).

    P.S. modal dialogs are bad news IMHO, best to use modeless but you need to handle the IPC (just a few shared variables but most windows books make a BIG deal out of what is actually pretty trivial code).

  10. #10
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    232

    Re: OpenGL + Windows controls

    OK, I went for a modeless dialog. Everything works sweet except one thing... Look at the following code (main message loop).

    Code :
    MSG msg;		// Message to the event handler	
    	BOOL bRet;		// Returned value
    	while (g_WindowHandle &amp;&amp; (bRet = GetMessage(&amp;msg, NULL, 0, 0)) != 0) 
    	{ 		
    		if (bRet == -1)
    		{
    			// Handle the error and possibly exit			
    		}
    		else if (!IsWindow(g_WindowHandle) OR !IsDialogMessage(g_WindowHandle, &amp;msg)) 
    		{ 
    	        TranslateMessage(&amp;msg); 
    		    DispatchMessage(&amp;msg); 			
    		} 
    		else
    		{
    			Render();	// Render the scene	
    		}		
    	}
    It seems that Render() is called very very seldom. In fact, the more actions I do (for example - moving my mouse) the more frequently Render() is called.

    Do you have an idea what's goind on?

    Thank you

Posting Permissions

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