Jump to content
  • Advertisement
Sign in to follow this  
CHollman82

getpixel() from a directdraw7 surface?

This topic is 4884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
-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

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!