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)
- Surface
can be any size primary surface must current screen resolution
- Surface
created in video memory or system memory
- All
surfaces have the same property as far as (bit depth, color space)
Windows game
- Typically
have primary display surface (visible video)
- Secondary
display surface usually used for animation (known as back buffer)
- Off
screen surfaces
- Bit
maps
- Sprites
- Other
screen items (icons etc) faster than using CD player or memory
P265 talk about how to put surfaces together
Create a primary surface
- CreateSurface(
);
Linear vs. non-linear memory
- Linear
memory mode º
horizontal pixel pitch is equal to horizontal memory pitch
- 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
- Set up
the surface and lock the primary surface
- Get
video pointer
- Draw
pixels
- 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
- Lock
the primary surface using Lock( ); gives the program control over the
surface
- Build
an RGB word for 16 bit mode (define macros to do this)
- Write
the pixel (using ushort and vram)
- Unlock
the primary surface using unlock( );
Animation
- Page
flipping – done largely using primary and secondary surfaces
- 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)
- Add
ddsd_backbuffer to dwflag – dwbackbuffcount field º
valid and will contain the number of back buffers
- Add
control flags ddscaps_complex and dscaps_flip to word and DDSURFACEDSC2 (a
direct draw surface)
- Create
primary surface as usual
Double buffering at a high level
- Allocate
memory for the double buffer – same pixel dimensions as primary surface
- In
main loop – erase double buffer
- Perform
game logic
- Render
next frame into double buffer
- Copy
double buffer to primary surface
- Synchronize
the display to a specific frame rate
- Go to
step 2
Page flipping P311
- Clear
the back buffer
- Render
the scene to the back buffer
- Flip
primary surface for back buffer
- Lock
frame rate – get to 30 frames per second
- 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
- Clear
out DDBLTFX structure
- Set
dwSize field to the size of DDBLTFX and set dwFillColor
- Fill
in the area
- Call
BLT( ) function
Clipper ~P339
Making Draw clipper
- Create
direct draw object
- Create
a clipping list
- Send
clipping list to clipper
- Attach
clipper to window

Bitmapped Sprites º
- A
object that moves around
- Displayed
as a bit map
- Typically
displayed on a background
- Methods
- Store
- Display
- Move
- Animate
- Collide
Sprites in files
- Create
a sprite with a 2D or 3D drawing package
- Set
it up so that each pixel has 8 bits
- Formats
- 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
- BMP
Movement and display
- Compute
new position of the sprite
- If
Sprite moved erase sprite by restoring saved background
- Save
background where sprite goes
- Draw
the sprite
Sprite scaling
- Can
be used to show depth (big vs. little people picture goes here)
- Options
- Dynamic
computations (pretty slow)
- Pre-store
different sizes
- A
couple of major sizes
Sprite rotation
- Drawing
of
- Multiple
happy faces go here each one changing like an animated gif
- 8 to
16 pictures
Animate
- Changes
in state
- Standing
- Sitting
- Shooting
- Standing
- Dying
- Use a
timer to select a state
- Storage
space
- Number
of bitmaps = # angles * # states
Sprite collisions
- Easiest
way to handle – use a bounding box
Depth
- Can
fake depth by scaling
- Need
to set things up so that the closer object obscures the farther object
- Associate
a depth with each sprite
Note: Z-ordering – sort on the z-axis the things closer
obscure the objects farther away