http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

TheGrumpyProgrammer



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

DirectX Blues



I'm having a few problems with my DirectX program. I was wondering if
someone could please help me with a few questions:
1. How do I check Windows messages to see when the program becomes avtive
(i.e. not minimized). I've read "just look for the WM_ACTIVATE message, so
I tried toggling a "BOOL Active" every time I get that message, but it
doesn't seem to work.
2. Can I safely assume that the screen's pitch as stored in the surface
descreption after locking a surface will remain constant? I.e. Can I get it
once and save it, or do I have to check it every frame?
3. How do I align my page-flips with the monitor's refresh? Is this done
automatically? Can I continue calculating something else while I wait?
4. Why does the following code not work? I'm using page-flipping, but the
screen is still flashing psychedellically and exhibiting massive tearing. I
can see pixels I've drawn over as semi-transparent just as though I were
writing directly to the screen even though I'm pretty sure I'm not; I know
I'm not trying to.

<errant code snippet, language = C>
inline void DrawScreen(BOOL Active, game_t *Game, trig_t *Trig, vec2_it
ScreenSize, int ScreenBits, LPDIRECTDRAW lpdd, LPDIRECTDRAWSURFACE
*lpddsPrimary, LPDIRECTDRAWSURFACE *lpddsBack, DDSURFACEDESC *ddsdBack) {
	HRESULT hResult; //for checking return value
	byte *ScreenBuffer; //pointer to back buffer
	int ScreenPitch; //stores the memory difference between vertical pixels

	if(Active) { //not minimized or otherwise hidden (Cant get this to do
anything or even work, how can I tell when my program is minimized /
fullscreen?)
		if(SUCCEEDED(hResult = IDirectDrawSurface_Lock(*lpddsBack, NULL,
ddsdBack, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) { //optain pointer
to back video memory
			ScreenBuffer = ddsdBack->lpSurface; //assign the back buffer memory
location to ScreenBuffer
			ScreenPitch = ddsdBack->lPitch; //take out of loop? This won't change,
will it?
			memset(ScreenBuffer, 0, ScreenPitch * ScreenSize.y * ScreenBits);
//clear the screen (DELETE THIS LATER)
			GameDraw(Game, Trig, ScreenBuffer, ScreenSize, ScreenPitch); //call the
function that draws to the screen
			IDirectDrawSurface_Unlock(*lpddsBack, ddsdBack->lpSurface); //release
the pointer to video memory
			//IDirectDraw_WaitForVerticalBlank(lpdd, DDWAITVB_BLOCKBEGIN, NULL);
//wait for monitor retrace (Doesn't seem to do anything but slow the
program down?)
			IDirectDrawSurface_Flip(*lpddsPrimary, NULL, DDFLIP_WAIT); //flip pages
		}
		else if(hResult == DDERR_SURFACELOST) { //if the surface memory was lost
(i.e. while inactive)
			IDirectDrawSurface_Restore(*lpddsPrimary); //try to restore it for next
time (todo: if this works, do the graphics (there is now a blank frame
after re-activation)
		}
	}
}
</code snippet>

-- Neil Edelman
-- ICQ UIN: 705130
-- email: mailto:dreaded.neil@phreaker.net?subject=sig
-- home: http://members.xoom.com/dreadedneil
-- moop: http://moop.bizland.com
-- "My air-to-air missile overrides your air traffic control clearance"
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html