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


DirectDraw pixel plot

Recommended Posts

hmm, sorry if this question has already been asked before (im sure its a popular one). Can someone please provide code, or pointers for the following scenario: I have a DWORD called dwColor. This contains the color value of the pixel to be plotted (it may contain only a WORD when in 16 bit, or the full 32 bits when in 32 bit mode). I use a word, for simplicity, as my application could be running on any color mode. Now, I want to plot that color at position x,y on the screen. This much I know: I lock the back buffer, then I get the lpSurface pointer. The problem is that I don''t know how to write only the amount I need. If I get lpSurface as a DWORD, and then write my DWORD it will yield incorrect results under 16 bit mode. How do I set the right amount of memory, and copy the correct portion of dwColor?

Share this post

Link to post
Share on other sites
char r=0, g=0, b=0;
for(int n = 1; n<65536; n<<=1)
if(ddPixelFormat.dwRBitMask & n)
if(ddPixelFormat.dwRBitMask & n)
if(ddPixelFormat.dwRBitMask & n)

dwRBitMask = ddPixelFormat.dwRBitMask;
Position.rgbRed = g + b;

dwGBitMask = ddPixelFormat.dwGBitMask;
Position.rgbGreen = b;

dwBBitMask = ddPixelFormat.dwBBitMask;
Position.rgbBlue = 0;


ZeroMemory( &DDSurfDesc, sizeof( DDSurfDesc ));
DDSurfDesc.dwSize = sizeof( DDSurfDesc );

g_pDDSBack->Lock( 0, &DDSurfDesc, DDLOCK_WAIT, 0 );


int rv,gv;
rv = 8;gv = 100;bv = 50;

WORD *pixels = (WORD *)DDSurfDesc.lpSurface;

WORD Pixel;
Pixel = (r << Position.rgbRed) |
(g << Position.rgbGreen) |

pixels[10] = Pixel;



this should work

Share this post

Link to post
Share on other sites