Forum

More Win/GL Quake bugs - MainWndProc

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

More Win/GL Quake bugs - MainWndProc

Postby mh » Mon Oct 25, 2010 12:44 am

Two things here. First one is that if you handle a message in your WndProc you should normally return 0, not 1. This is all over the MSDN documentation for window messages, and the fix is easy. Find this:
Code: Select all
LONG   lRet = 1;
And change it to this:
Code: Select all
LONG   lRet = 0;

The next one is straight from MSDN as well:
The DefWindowProc function erases the background by using the class background brush specified by the hbrBackground member of the WNDCLASS structure. If hbrBackground is NULL, the application should process the WM_ERASEBKGND message and erase the background.

So guess what: both Win and GL Quake set hbrBackground to NULL, but neither handle WM_ERASEBKGND! Add this somewhere after your "switch (uMsg)":
Code: Select all
   case WM_ERASEBKGND:
      return 1;

Yes, here we're returning 1 because:
An application should return nonzero if it erases the background; otherwise, it should return zero.

(We're not really erasing the background, but we are drawing over it with our renderer.)

Neither of these will give you any performance gains by the way, there's no voodoo at work here. What they will do is make your program a better behaved citizen in Windows-land (and may help prevent odd behaviour on bad drivers).

While we're at it, and now that we've mentioned the WNDCLASS struct, find your VID_InitDIB function and set the correct class styles for OpenGL (GLQuake totally fails to do this):
Code: Select all
   wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2283
Joined: Sat Jan 12, 2008 1:38 am

Postby leileilol » Mon Oct 25, 2010 1:07 am

wasn't this done for mgl support on older cards or something like that for the scitech stuff to take priority?
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby mh » Mon Oct 25, 2010 1:18 am

Bleagh; it might just have been. :evil:

No excuse for it in GLQuake though.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2283
Joined: Sat Jan 12, 2008 1:38 am

Re: More Win/GL Quake bugs - MainWndProc

Postby mankrip » Fri Nov 30, 2012 6:06 am

Well, I've added it:
Code: Select all
   // mh - begin
   // http://forums.inside3d.com/viewtopic.php?f=12&t=2708
   case WM_ERASEBKGND:
      return 1;
   // mh - end
   default:
      /* pass all unhandled messages to DefWindowProc */
      lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
      break;
   }

   /* return 0 if handled message, 1 if not */
   return lRet;
}

I'm not using the MGL code anymore, so I guess it should work fine.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 908
Joined: Fri Jul 04, 2008 3:02 am


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest