Running Windowed With DirectDrawHelper

The DirectDrawHelper modules have been updated to allow you to run windowed or full screen. Additional changes have been made to allow you to run you game in multiple full screen resolutions or windowed with changing any game code.

Running Windowed...

To start a VB game in windowed mode, simply pass Windowed as the mode parameter to the ddInit routine.

This creates a window with a backbuffer the same size as the window surface. When you window is resized, the backbuffer must be updated.
To do this, add the line
ddOnResize to your forms Resize event.

Scaling...

One of the major snags of running windowed is resizing. If you don't take special action, whenever the user resizes, you end up with a blank area, or only able to see a small portion of your games display.

This version of DirectDrawHelper overcomes this problem by introducing scaling.

How it works...

When you design you game, deceide on a default full screen resolution. This is usually the resolution you would set as a default for optimum game play. This could be chosen low (640x480) for speed and memory savings, or  high (e.g. 1024x768) for best visual appeal. The resolution you choose makes no difference to the module, it need not even be a valid full screen resolution.

Once you have deceided on a resolution, create all your graphics relative to that resolution. I.E, if you chose, say, 500x400, to create a bitmap which would cover the whole, create a bitmap of 500x400.

Now, when you code your game, write all the code as if you where in a 500x400 full screen display mode. I.E if you want to draw a bitmap 100 pixels from the right edge, and 100 pixels from the bottom, blt at (400,300)

The DirectDrawHelper needs to know what resolution you picked, so before any ddInit calls, you MUST call ddSetDefaultScale(xRes, yRes),
E.G ddSetDefaultScale 500, 400
This tells the module that the all the graphics calls will be relative to a screen this size.

Now go ahead and initialize DirectDraw using any of the ddInit... calls, in either full screen or windowed mode, at any resolution you want.

Whenever you want to draw a bitmap, use the helper routine ddBlt. This
will ensure the bitmaps are correctly scaled and placed on the screen.

If you are running windowed, the size of the client area is taken as the screen size, and thus the graphics is scaled to fit entirely within the client area, thus allowing you to shrink the window pretty small, and still see what is going on.

If you select a full screen display resolution that matchs the default, ddBlt will use the fast DirectDrawSurface2.BltFast routine instead of .Blt.

If you neglect to call ddSetDefaultScale, then for full screen modes, the first mode set is taken as the default. For windowed, the intial client area size is taken as the default.

What happens to the displayXRes variables...

For  a full screen mode, displayHRes and displayVRes contain the actual screen horizontal and vertical resolutions of the current display mode.

In windowed mode, displayXRes contains the horizontal/verticle dimension of the windows client area.

 

Interface extensions...

Sub ddSetDefaultScale(ByVal fX As Integer, ByVal fY As Integer)

   Use this routine to specify the default full screen display resolution.

Sub ddBlt(Byval X as Integer, Byval Y as Integer, Surface as DirectDrawSurface2, clipRect as Rect)

    Use this routine to do all the blts when using a the scaling system.

    (X,Y) is the position relative to default resolution to blit at.
    Surface if the bitmap to use.
    clipRect is the portion of the bitmap to use.

 

fireline.gif (5182 bytes)

Back to DirectX Tutorial Back to DirectX Tutorial

fireline.gif (5182 bytes)

TN00018A.gif (1390 bytes) Return to Digital Zone Software Homepage

fireline.gif (5182 bytes)

Copyright © 1998 Digital Zone Software. All rights reserved.
Author: Mark Hewitt