Page 1 of 1

More Win/GL Quake bugs - MainWndProc

Posted: Mon Oct 25, 2010 12:44 am
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;

Posted: Mon Oct 25, 2010 1:07 am
by leileilol
wasn't this done for mgl support on older cards or something like that for the scitech stuff to take priority?

Posted: Mon Oct 25, 2010 1:18 am
by mh
Bleagh; it might just have been. :evil:

No excuse for it in GLQuake though.

Re: More Win/GL Quake bugs - MainWndProc

Posted: Fri Nov 30, 2012 6:06 am
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.