DirectDraw pixel plot

Started by
1 comment, last by FrigidHelix 23 years, 2 months ago
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?
Advertisement
char r=0, g=0, b=0;
for(int n = 1; n<65536; n<<=1)
{
if(ddPixelFormat.dwRBitMask & n)
++r;
if(ddPixelFormat.dwRBitMask & n)
++g;
if(ddPixelFormat.dwRBitMask & n)
++b;
}

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

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

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

DDSURFACEDESC2 DDSurfDesc;


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) |
(b);

pixels[10] = Pixel;


g_pDDSBack->Unlock(NULL);

g_pDDSPrimary->Flip(NULL,0);

this should work
thx

This topic is closed to new replies.

Advertisement