Demo 6.2 p257

Selecting video mode setDisplay(640,480,8) last parameter is bits per pixel

 

Direct draw

 

Displayable memory = surface

Primary surface = visible video screen (mapped to vram)

  1. Surface can be any size primary surface must current screen resolution
  2. Surface created in video memory or system memory
  3. All surfaces have the same property as far as (bit depth, color space)

 

Windows game

  1. Typically have primary display surface (visible video)
  2. Secondary display surface usually used for animation (known as back buffer)
  3. Off screen surfaces
    1. Bit maps
    2. Sprites
    3. Other screen items (icons etc) faster than using CD player or memory

 

P265 talk about how to put surfaces together

 

Create a primary surface

  1. CreateSurface( );

 

Linear vs. non-linear memory

  1. Linear memory mode º horizontal pixel pitch is equal to horizontal memory pitch
    1. 640 pixels in 8 bit mode à640 bytes per video line

 

Example code from demo 6.3

UCHAR *videobuffer;

Videobuffer[x + 640 * y] = color;

 

Palletized color

  1. Set up the surface and lock the primary surface
  2. Get video pointer
  3. Draw pixels
  4. Unlock the surface

 

END OF CHAPTER 6

 

Standard 640 x 480 pixel frame buffer has around 307200 pixels

Several 16 bit high color encoding’s

            Alpha 5.5.5

                 X   5.5.5

                       5.6.5 (most common or most card support)

P291 table 7.1

Steps to write a pixel to the screen P294

  1. Lock the primary surface using Lock( ); gives the program control over the surface
  2. Build an RGB word for 16 bit mode (define macros to do this)
  3. Write the pixel (using ushort and vram)
  4. Unlock the primary surface using unlock( );

Animation

  1. Page flipping – done largely using primary and secondary surfaces
  2. Double buffering – system memory is used for back buffer and programmer manually flips

 

Note: what normally happens is the next screen is drawn off screen and then switched with the on screen view

 

Demo 7.4 P309

Create primary surface with back buffer attached (complex surface)

  1. Add ddsd_backbuffer to dwflag – dwbackbuffcount field º valid and will contain the number of back buffers
  2. Add control flags ddscaps_complex and dscaps_flip to word and DDSURFACEDSC2 (a direct draw surface)
  3. Create primary surface as usual

 

Double buffering at a high level

  1. Allocate memory for the double buffer – same pixel dimensions as primary surface
  2. In main loop – erase double buffer
  3. Perform game logic
  4. Render next frame into double buffer
  5. Copy double buffer to primary surface
  6. Synchronize the display to a specific frame rate
  7. Go to step 2

 

Page flipping P311

  1. Clear the back buffer
  2. Render the scene to the back buffer
  3. Flip primary surface for back buffer
  4. Lock frame rate – get to 30 frames per second
  5. Go to step 2

 

Demo 7.6 ~P318

UCHAR *videoBuffer;

UCHAR bitmap(8 * 8);

for ( index_y = 0; index_y < 8; index_y++)

            {

            for (index_x = 0;index_x < 8; index_x++)

                        videoBuffer(x + index_x , (y + index_y) * 640) = bitmap(index_x + index_y * 8);

}

}

// Problem is this is incredibly slow and doesn’t take transparency into account

 

Steps to work with blitter 

  1. Clear out DDBLTFX structure
  2. Set dwSize field to the size of DDBLTFX and set dwFillColor
  3. Fill in the area
  4. Call BLT( )  function

 

Clipper ~P339

Making Draw clipper

  1. Create direct draw object
  2. Create a clipping list
  3. Send clipping list to clipper
  4. Attach clipper to window

 

 

 

 

 

 

 

 

 

 

 

 

 

Bitmapped Sprites º

  1. A object that moves around
  2. Displayed as a bit map
  3. Typically displayed on a background
  4. Methods
    1. Store
    2. Display
    3. Move
    4. Animate
    5. Collide

 

Sprites in files

  1. Create a sprite with a 2D or 3D drawing package
  2. Set it up so that each pixel has 8 bits
  3. Formats
    1. PCX – run length encoded files – encodes the number of successive pixels of the same color

                                                    i.     Transparent background special code 255 (arbitrary choice)

                                                  ii.     SHOW TANK PICTURES

 

 

    1. BMP

 

Movement and display

 

  1. Compute new position of the sprite
  2. If Sprite moved erase sprite by restoring saved background
  3. Save background where sprite goes
  4. Draw the sprite

 

Sprite scaling

  1. Can be used to show depth (big vs. little people picture goes here)
  2. Options
    1. Dynamic computations (pretty slow)
    2. Pre-store different sizes
    3. A couple of major sizes

 

Sprite rotation

  1. Drawing of
  2. Multiple happy faces go here each one changing like an animated gif
  3. 8 to 16 pictures

 

Animate

  1. Changes in state
    1. Standing
    2. Sitting
    3. Shooting
    4. Standing
    5. Dying
  2. Use a timer to select a state
  3. Storage space
    1. Number of bitmaps = # angles * # states

 

Sprite collisions

  1. Easiest way to handle – use a bounding box

 

Depth

  1. Can fake depth by scaling
    1. Need to set things up so that the closer object obscures the farther object
    2. Associate a depth with each sprite

 

Note: Z-ordering – sort on the z-axis the things closer obscure the objects farther away