Advertisement

win32 opengl

Started by
4 comments, last by GameDev.net 18 years, 11 months ago
Hi, I created my own code for using opengl on win32 (based on the NEHE tutorial). I need to render static scenes, so I don't wan't the scene to render over and over. I hooked my DrawScene() function on the WM_PAINT message inside my winproc, but the scene is getting redrawn constantly, just like with the code from the tutorial, as if every render would trigger a repaint event.

  switch(umsg) {
    ...
    ...
    case WM_PAINT:
       DrawScene();
       SwapBuffers(hDC);
       break;
    ...
    ...
  }
I'm going to stop using double buffering when I figure out how to do that (can that be the cause of my problem?) Thanks for any help
If you're looking to render a static scene 1 time only you'll want to hook it to something like a button click or keypress event, rather than your WM_PAINT message. The WM_PAINT event occurs much more quickly than the effect you seem to be striving for.

As far as double buffering the GL red book (ISBN 0-201-60458-2) has a good explanation on page 20 under "Animation."

Advertisement
Quote: Original post by sbayeta
as if every render would trigger a repaint event.
...
I'm going to stop using double buffering when I figure out how to do that (can that be the cause of my problem?)

Rendering the way you probably do is actually triggering a contiuous stream of WM_PAINT messages.
When the WM_PAINT message is used, you shall tell OS your window now looks fine. This is made with a function which is called ValidateWindowRect I think, but I'm not sure. It's some time I don't use it. If I'm wrong, someone will surely fix this.

Disabling double buffering is pointless. Why should it cause a problem like this?

By the way, take care when you validate a window rect. Once the window is marked by the OS as "ok", no more WM_PAINTS will be posted until something interesting happens. I think some windows implementation may give you something like 10 WM_PAINT messages/second in case nothing happens. If you need to redraw something, you'll need for example to pump an application specific window message to your WndProc (how are those structures called?).
By sure means, you'll get a WM_PAINT anyway in case "something interesting happens". This may be:
1- Lot of time passes (not sure of that!)
2- An overlaying window is moved/resized so your windows gets exposed in different areas.
3- Your window is moved/resized, restored...
4- Not sure: user input?

Well, details are not my strong point. ;)
I hope this helps!

Previously "Krohm"

Quote:
Rendering the way you probably do is actually triggering a contiuous stream of WM_PAINT messages.
When the WM_PAINT message is used, you shall tell OS your window now looks fine. This is made with a function which is called ValidateWindowRect I think, but I'm not sure. It's some time I don't use it. If I'm wrong, someone will surely fix this.

Disabling double buffering is pointless. Why should it cause a problem like this?

By the way, take care when you validate a window rect. Once the window is marked by the OS as "ok", no more WM_PAINTS will be posted until something interesting happens. I think some windows implementation may give you something like 10 WM_PAINT messages/second in case nothing happens. If you need to redraw something, you'll need for example to pump an application specific window message to your WndProc (how are those structures called?).
By sure means, you'll get a WM_PAINT anyway in case "something interesting happens". This may be:
1- Lot of time passes (not sure of that!)
2- An overlaying window is moved/resized so your windows gets exposed in different areas.
3- Your window is moved/resized, restored...
4- Not sure: user input?

Well, details are not my strong point. ;)
I hope this helps!


Ok thanks a lot.
I only want to repaint in cases 2, 3 and maybe 4. I'll try the ValidateWindowRect thing and get back to the forum.

Cheers
Well, it worked out just fine.

here's the code and the explanation
case WM_PAINT:	DrawGLScene();	SwapBuffers(hDC);		ValidateRect(hWnd, NULL);		break;


and according to Petzold,

Quote:
But don't do this:


case WM_PAINT:
return 0 ; // WRONG !!!

Windows places a WM_PAINT message in the message queue because part of the client area is invalid. Unless you call BeginPaint and EndPaint (or ValidateRect), Windows will not validate that area. Instead, Windows will send you another WM_PAINT message, and another, and another, and another….


Cheers


Hi

Does it help in an OpenGl Win32 App to validate the Window?

Just curious. Because I sometimes do, but, do'nt know exactly how it would help other than validating the window.

I Call RenderScene() Swapbubbers() and Keyboard() thru the Main Loop, allready.

So, aside from validating the window, what other effect, beneficial/detrimental, does something like below, cause :


CASE: WM_PAINT
hDC = BeginPaint( hWnd, ps )
EndPaint ( hWnd, ps )
break;


Thanks in advance


Orangutang

This topic is closed to new replies.

Advertisement