Backsurface for flipping in Windowed Mode?
some pointers and pitfalls:
A) no flipping, unless you are using overlays. support for overlays isnt common.
B) you need a clipper. use the SetHWnd() function to make it update with a window automatically
C) the primary surface represents the ENTIRE area of the surface, clipped by your clipper. the coordinates are NOT based off of the client coordinates of the window. ergo, if the window moves, is resized, etc, you have to change to where you blit on the primary surface (use of ClientToScreen() works here)
D) you have to accomodate ALL possible pixel formats. easy enough to do with using GDI to load your bitmaps onto your surfaces. beware that your user may change the display mode while your app is running.
Get off my lawn!
Wow, sounds like a lot of work to use DD in Window mode. I was a fool and thought maybe it was as easy as setting the cooperation level.
I'm almost done with the full screen version of the game and maybe I'll just leave at that.
Thanks again..
Anyone else hate the screeching pop your monitor makes when switching video modes?
Another word of advice. I read that TNT based cards don't work well with clippers, so you could either force fullscreen mode if you find that a card isn't working well in windowed mode, or you could write your own clipper. Also to achieve smooth animation, you just draw to an offscreen surface surface, and blt that to the screen.
First of all, you need to do some special initialization. I have three functions that do the work. The first is the initialization of my LPDIRECTDRAW. You need to do this differently based on whether it's windowed mode or not, so therefore you have a flag. If it's fullscreen, you go exclusive, set up your screen mode, bit depth, etc. Windowed mode, you have to just take what windows gives you, and therefore you need to set up some flags that will tell the rest of your app what the bit depth is, what the resolution is, etc. Anyway, the second function sets up my two main surfaces the way I like them. My primary is initialized based upon what my window mode is (once again, a flag passed to the functinon). After that, if I'm in windowed mode, I set up a clipper for it. Now, if I'm in windowed mode, I create a separate surface that is my backbuffere that is the same size as the window. Otherwise, I get an attached surface for my primary that will be called with flip in fullscreen. Now that I have all this, my last function loads all my other surfaces with bitmaps, etc.
Now, to actually do all the work, you need to do a special check only when you're ready to draw everything to the primary. The rest of your program should be fine just drawing to the backbuffer, since it can't tell whether or not that backbuffer's going to be blit'd or flipped onto the primary. Therefore, the last place you need to check you're window mode is just before you put it onto the screen Here's a snippet:
if ( WindowMode == 1 ) // We're in a window
{
RECT
DestRect = {0, 0, 640, 480}; // Set up our destination rect for the window
lpDDSPrimary->Blt( &DestRect, lpDDSBackbuffer, NULL, DDBLT_WAIT, NULL ); // Do the blit from the backbuffer to the primary
}
else
{
lpDDSPrimary->Flip( NULL, DDFLIP_WAIT ); // Flip our surfaces
}
Granted, it's better to flip since that only involves switching a pointer around, but the blit isn't too bad. One bit of advices is to load all of your surfaces except your primary into system memory at initialization, since blits from system memory to system memory are going to be quicker than a blit across the PCI or AGP bus into video memory. This way, you're guaranteed of similar performance on different systems with more/less video memory, and the only blit that ever goes across the bus is the final blit to the primary. Anyway, that's all the time I've got for now. Thanks for listening.
From my limited readings, I got the impression that page flipping from primary to back surface is not efficient in windowed mode? Is this true? If so, is there anyway to achieve smooth animations by just using primary surface drawing? Or if it is not true, then I assume I just have to use GetWindowRect() before DD_Flip? Any documentation suggestions would be great!
Thanks in advance!
I think I need a break and go play Quake3Arena :P
Thanks again guys!
All this stuff is a lot easier then trying to choose a purdy background that won't annoy the heck out of your general targetted audience. :P