[comp.windows.ms] Dithering and SetPixel

ks26+@andrew.cmu.edu (Kenneth Sykes) (02/03/89)

As part of a 3-D rendering package, I am implementing Z-buffer based algorithms
to
do hidden surface removal and shading.  The problem I'm having is that the
algorithms
are pixel-based, yet I want to display polyhedron using dithered colors.

Currently Windows maps a logical color to a device color when using SetPixel() -
not
any type of dithering pattern.  Their reasoning is that dithering a single pixel
doesn't
make sense.  Thus, when plotting a pixel at a time, you are limited to the
device colors.

What makes sense to me is to conceptually divide the screen into a grid, where
each
grid element contains the, say 8x8, dither pattern for a given color.  When
SetPixel is
called, it determines the relative offset of the pixel into the dither pattern,
and plots
that color.  That way, if you plot several pixels with the same color in the
same area,
you will get the approximate color that you want.

My questions are the following:

1.  Has anyone found a "reasonable" way around this?  The approach I will
probably
     take (unless someone has an easier solution :-) is to use Floyd-Steinberg
dithering.
     The SetPixel() routine returns the actual color displayed so this technique
is possible.

2.  Is the alternative method I suggested reasonable/useful/desirable/etc.?  If
so, what kind
    of portability issues are there? (i.e. if this technique was implemented in
a future version
    of windows, would there be a problem with doing this automatically?  Should
there be
    a flag to enable/disable this option? ...)

Suggestions, flames, etc., are very much welcome!

Sincerely,
   Ken Sykes