Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Question on pixels and modes

This topic is 5737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

OK, I''m on page 272 of Tricks of the Windows Game Programming Gurus. I''m stuck on this... //Formula to locate position in the video buffer: // assume this points to VRAM or the surface memory UCHAR *video_buffer8; video_buffer[x + y*memory_pitchB] = pixel_color_8; "Of course, this is not exactly true because this formula works only for 8-bit modes, or modes that have one BYTE per pixel." Now, I''m ok with the above. I''m pretty sure I understand whats going on there. Below is what bothers me :/ "For a 16-bit mode, or two BYTEs per pixel, you would have to do something like this:" // assume this points to VRAM or the surface memory USHORT *video_buffer16; video_buffer16[x + y*(memory_pitchB >> 1)] = pixel_color_16; "There''s a lot going on here, so let''s take a look at the code carefully. Since we''re in a 16-bit mode, I''m using a USHORT pointer to the VRAM. What this does is let me use array access, but with 16-bit pointer arithmetic. Hence, when I say video_buffer16[1], this really accesses the second SHORT or byte pair 2,3." Huh? Can someone explain how he gets byte pair 2,3? I''m really confused now, hehe. If you could elaborate on what is actually happening here, it would be MUCH appreciated. Sorry for the long post :/

##### Share on other sites
OK, you understand that in 16 bit mode, two bytes are used for each pixel, right? video_buffer16[1] references the second pixel in the buffer (the first is video_buffer16[0]).

video_buffer16[0] uses byte #0 and byte #1 to store its color value.

video_buffer16[1] uses byte #2 and byte #3. Hence, byte pair 2,3.

Understand?

##### Share on other sites

I knew it had to be simple! There I go overcomplicating things again... Thanks micepick

• 32
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631352
• Total Posts
2999483
×