BMP files

 

 

  1. Open file
  2. Read header
  3. Read bitmap info, biwidth, biHeight
  4. Read data in

 

Note: in many instances the bit map is stored inverted if inverted biHeight is positive if not inverted it is negative

 

Blitter (some allow scaling and rotation) with directx must have hardware support for rotation no hardware support needed for scaling

 

  1. Create direct draw application
  2. Create a primary and secondary surface
  3. Load bitmap off screen onto secondary surface
  4. Load palette in primary screen
  5. Scan out arbitrary rectangles on secondary surface and blit them to primary

 

Color keying ~P360

 

Source key color keying (prevalent way of doing color keying) – blit setting color key using setColorKey( ) allows a range of colors to be transparent

 

Destination key color keying – works in theory but not many people use it… i.e. doesn’t work as well

 

Scaling – 1x4 pixel rectangle

 

0          20

1          5

2          12

3          86

 

Array || color code

 

1x8 pixel rectangle

0          20  

1          20

2          5

3          5

4          12

5          12

6          86

7          86

 

When scaled you now have 2x as many à starts to distort

 

When you scale the other direction you start losing information

Scale down to 1x2

0          20

1          2

we lost the color 5 and 86 oops

 

Crude filter

Source height = 4

Destination height = 3

Sample = 4/3 = 1.33 algorithm is on Page371

Based on the ratio of the heights you pick up more information

Demo 7.14 shows the scaling effects

 

Simulated animation with blinking lights

  1. Pick 2 or 3 colors and reserve them 2553, 254, 255…i.e. as place holders
  2. Write code to toggle the entries (function called setEntry() and a function named blinkColors() to get this to work

 

Algorithm for shifting P380

 

 

 

 

SetEntries( );

getEntries( );

 

Mixing GDI with directx – cooperative level is set to full screen and exclusive

Why do this? GDI is much better at drawing text menu’s dialog boxes etc.

 

3 choices

  1. Via high level controls—message boxes etc no graphics device context
  2. Via graphics device context inside of direct draw
  3. Via one standard window mode

 

P384

 

 

2D raster graphics or vector graphics (Asteroids/battle zone)

 

Advantages of vector graphics –

  1. No jagged lines
  2.  Can only draw what is on the screen
  3. Control electron gun itself à can be fast
  4. Store line end points

 

Disadvantage of vector graphics

  1. Best for wire frames
  2. Have to draw everything as lines including circles (no TV technology)

 

Advantages of using raster graphics

  1. Chd edgeeaper
  2. Can easily draw solid surfaces
  3. Can move blocks and images around
  4. Can control individual pixels

 

Disadvantage of raster graphics

  1. Memory intensive
  2. Alias problems (jagged edges)

 

2D graphics

Drawing lines – problem making a chain of pixels to come up with the picture

Breghems algorithm Chapter 8 P403

 

  1. Starts at x0, y0
  2. Plots x0, y0
  3. xi < xi + 1
  4. When advancing yi decide between (xi, yi) or (xi,yold)
  5. Algorithm treats separately
    1. m < 1 (<450)
    2. m > 1 (>450)
    3. By symmetry

 

 

 

 

Clipping

 

  1. Border – doing work with bitmaps… the border is as wide as the object itself

 

 


  1. Image space test each point – draw or no draw pixel represents the complete image—easy to implement but expensive to test every pixel
  2. Object space –
    1.  Change the object so no clipping needed –
    2.  Taking a triangle and chop part off making it a trapezoid –
    3.  Normally more efficient than image space—
    4. Need different algorithms for different types of objects

 

Cohen-Sutherland algorithm P428 – see book

 

 

  1. Each region is assigned a bit code
  2. End points P1and P2
  3. y < min Y or y > max Y
  4. x < min x or x > max x
  5. Sign bits of P1 and P2

 

accept

P0 + P1 = 0

 

reject

P0 & P2 != 0

 

Polygons

  1. Defined by their vertices
  2. Closed polygons à can be draw 1 line at a time
  3. Convex or concave
  4. Many games make use of polygons

 

Required data to draw polygons

  1. Number of vertices
  2. Color
  3. General position
  4. List of vertices

 

 

 

Position the object

  1. If we move the object do we have to change all vertices?
    1. Yes if use world coordinates
    2. No if use local coordinates

 

Motion/transformation

  1. Translation x0 = x0 + 2x  and y0 = y0 +2y
  2. Scaling (size change)

 

 

 

X0 = x0 * 5x

Y0 = y0 * 5y

  1. Rotation

 

X1 = x0 * cos (q) – y0sin (q)

Y1 = y0 * cos (q) + x0sin (q)

 

 

 

 

Matrix operations

 

Translations º [x y 1] … treats point as a row vector

 

           

 

[x

Y

1]

1

0

0

0

1

0

sx

sy

1

 

 

 

 

Transformation matrix

[x

Y

1]

sx

0

0

0

sy

0

0

0

1

 

 

 

 

Scaling matrix

[x

Y

1]

Cos q

-sinq

0

Sin q

cosq

0

0

0

1

 

 

 

 

Rotation matrix