Archived

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

FrigidHelix

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)
++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

Share this post


Link to post
Share on other sites