More Win/GL Quake bugs - MainWndProc

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

More Win/GL Quake bugs - MainWndProc

Post by mh »

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
leileilol
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Post by leileilol »

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
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

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
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: More Win/GL Quake bugs - MainWndProc

Post by mankrip »

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
Post Reply