Skip to main content
gamedev.net
🔒 Locked

DirectDraw Pixels

Started by klubbkid Sep 15, 2000 at 11:31 AM 3 replies 300+ views
Original Post
klubbkid
klubbkid
Hi... Damn ddraw keeps screwin'' with my head!! >:| void PlotSinglePixel( LPDIRECTDRAWSURFACE7 pDDS, int x, int y, int r, int g, int b ) { // Safety net if (pDDS == NULL) return; if (x < 0 || x >= 640) return; if (y < 0 || y >= 480) return; DDSURFACEDESC2 ddsd; ZeroMemory( &ddsd, sizeof( ddsd )); ddsd.dwSize = sizeof( ddsd ); pDDS->Lock( 0, &ddsd, DDLOCK_WAIT, 0 ); DWORD *pDDSPixel16 = ( DWORD* )ddsd.lpSurface; pDDSPixel16 [((ddsd.lPitch / 2) * y) + x] = RGBToColour(r,g,b); pDDS->Unlock(NULL); } Whats wrong with this?! If I draw a pixel at 0, 0 it''s fine, but at 1, 0 it''s actually at 2,0, and the pixel than should be at 2,0 is at 4,0.. so it''s spacing them improperly... oh and the pixel at 639,0 is at 639,1... it''s like the screen it only 320 wide - Derek
Meduzza
Meduzza
Your pDDSPixel16 is pointer to DWORD instead of WORD.
Make is WORD* and everything will be allright.
klubbkid
klubbkid
Wow that worked great!!

Now how can I convert the WORD in the surface to r, g, b values?

- Derek
real_man
real_man
Wow, i never heard of PlotSinglePixel(). I can''t find it in thte DirectX documentation at all.

It seems to pass more parameters than my current code so I may never have to use it at all cause it might be slower

Ahhh heck I am tired of this stuff! maybe I will make my own routine to plot a single pixel faster then SetPixelV.
Ironblayde
Ironblayde
To extract the intensities of red, green, and blue, use this:

For 16-bit (565) display:
r = (pixel & 0xF800) >> 11; // value is between 0-31
g = (pixel & 0x07E0) >> 5; // value is between 0-63
b = (pixel & 0x001F); // value is between 0-31

For 16-bit (555) display:
r = (pixel & 0x7C00) >> 10; // all values between 0-31
g = (pixel & 0x03E0) >> 5;
b = (pixel & 0x001F);

For 32-bit display:
r = (pixel & 0x00FF0000) >> 16; // all values between 0-255
g = (pixel & 0x0000FF00) >> 8;
b = (pixel & 0x000000FF);

In a 24-bit display mode you'll need to read the red, green, and blue values out of the buffer one byte at a time because there's no 24-bit data type.

One other thing... that pixel-plotting function you're using is going to be unusable. First of all, locking the surface every time you want to plot a pixel is extremely slow. Lock the surface once per frame, then plot all your pixels, then unlock. Second, you're using the = operator where you should be using ==. The result here is that every call to this function will return without doing anything. Finally, once you've eliminated those problems, the function body will be small enough that the actual plot takes less time than passing all those parameters, so use a macro or an inline function instead.

-Ironblayde
 Aeon Software

Edited by - Ironblayde on September 16, 2000 3:03:20 PM
"Your superior intellect is no match for our puny weapons!"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.