Advertisement

Two examples from "Trick of the Windows Game Programming Gurus"

Started by March 01, 2002 11:04 PM
1 comment, last by game_beginner 22 years, 9 months ago
I don''t understand the two examples on page 277. The function is: inline void Plot8(int x, int y, // position of pixel UCHAR color, // color index of pixel UCHAR *buffer, // pointer to surface memory int mempitch) // memory pitch per line { //this function plots a single pixel buffer[x+y*mempitch] = color; } // end Plot8 For Plot8, the plotting is: buffer[x+y*mempitch] = color; For Plot16, the plotting is: buffer[x+y*(mempitch>>1)] = _RGB16BIT65(red, green blue); Who do these plotting and the marco _RGB16BIT65 work? The shifting and marco drive me crazy
This shifting is because in 16 bit mode, each pixel is 2 bytes rather than 1 in 8 bit mode. The buffer is the actual surface display, and looks something like this:


( 640x480 )
0 1 2 3 4 5 6 ........ 639
640 641 642 643 644 645 646 ........ 1279
1280 etc.

And this continues on for the length of the screen. So if you wanted to access pixel ( 5, 2 ) on your screen, you first multiply the y value by 640( which is the memory pitch of this screen ), and then add in x to get the right column. So the statement

buffer[ x + y*mempitch ] = color;

assigns that certain pixel the color that was sent. For 8 bit mode, the color can range from 0-255 because these are all the palette entries, but in 16 bit mode it requires a mix of colors. The macro _RGB16BIT65 receives 3 different values for each of the colors, and then combine them to create a certain color.
Advertisement
Thanks, you are my GOD!!!
Why the operator(%) is used in the marco?
Can you represent this terrible thing in a graph? please

This topic is closed to new replies.

Advertisement