getpixel() from a directdraw7 surface?

Started by
7 comments, last by CHollman82 18 years, 10 months ago
I want a function that takes an x,y coordinate and a dd7 surface and returns to me a color value at that location. I've looked all over online and haven't found anything.
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
Advertisement
You need to look into "locking" and "direct memory access" (DMA) for surfaces.

Sadly, it's nowhere near as trivial as the GetPixel() from the GDI/Win32 camp, and it's prone to a large number of hurdles.

You need to specify
- Language of choice; presumably VB6 or C++
- Whether you have any solid format assumptions, or you want a general purpose solution
- Do you need a single pixel, or do you want all pixels?

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

-C++
-I use SetDisplayMode to set a 32bit display but am using 24bit bitmaps, I don't know what format
-Just a single pixel at a time.

Thanks for any help
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
This is my load bitmap function maybe it will help you determine what color format I would get back from a getpixel call? I'm using it to load 24bpp bitmaps made in mspaint.

int LoadBitmapResource(LPDIRECTDRAWSURFACE7 lpdds, int xDest, int yDest, char* fname)
{
HDC hSrcDC;
HDC hDestDC;
HBITMAP hbitmap;
BITMAP bmp;
hbitmap = (HBITMAP)LoadImage(ghinstance, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
hSrcDC = CreateCompatibleDC(NULL);
SelectObject(hSrcDC, hbitmap);
GetObject(hbitmap, sizeof(BITMAP), &bmp);
lpdds->GetDC(&hDestDC);
BitBlt(hDestDC, xDest, yDest, bmp.bmWidth, bmp.bmHeight, hSrcDC, 0, 0, SRCCOPY);
lpdds->ReleaseDC(hDestDC);
DeleteDC(hSrcDC);
return(TRUE);
}
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
If you want to use GetPixel() then you have to:

COLORREF GetBackBufferPixel(int x, int y)
{
HDC hDC;

//Get the backbuffer DC
//This changes everyframe, because the DC is changed.
BackBuffer->GetDC(&hDC);

COLORREF rgb = GetPixel(hDC,x,y);

//Release the DC, if you do not, you will get an error on next update
BackBuffer->ReleaseDC(hDC);

return rgb;
}

Now you'll want to use GetRValue(rgb), GetGValue(rgb), GetBValue(rgb)

Sadly, GetPixel I believe is way slower than the locking method which is also VERY slow. There is no nice way to deal with the backbuffer directly.

[Edited by - Halsafar on June 1, 2005 8:30:05 PM]
Thanks, Ill try that. Fortunately it doesn't have to be very fast for my immediate purpost.
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
Awesome, that worked, thank you so much.
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
No problem.
I made a little error when typing that up for you but I bet you quickly caught it. I didn't put x,y in the GetPixel call. Anyway good luck with your project.
I'm working on pacman. I did it years ago in DOS mode 13h but now (after learning Win32) I am working on teaching myself DirectDraw and DirectInput, and then later Direct3D.
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();

This topic is closed to new replies.

Advertisement