Hi all,
I don't know if dbPoint is still not working for some people (or it was already solved and I just haven't read the solution yet), but I am still having a problem with it. The function still outputs 0 and I'm not sure why. I am running Windows 7 on a MacBook Pro via Bootcamp with NVIDIA GeForce 9600M GT graphics card...so that might have something to do with it, but I don't know.
I've been trying to make another function to replace dbPoint all together and this is what I have so far.
/*int mydbPoint(int x, int y)
- Takes in a pixel on the screen(xoordinates x & y) and outputs an integer representing the combination of red, blue, and green in the specified pixel.
SYNTAX:
int mydbPoint(int x, int y);
x = x coordinate of pixel
y = y coordinate of pixel
NOTE:
- This may lose accuracy if the screen is resized. (untested)
*/
int mydbPoint(int x, int y);
int mydbPoint(int x, int y)
{
COLORREF pixelColor;
HDC hdc = GetDC(g_pGlob->hWnd);
pixelColor = GetPixel(hdc, x, y);
ReleaseDC(g_pGlob->hWnd, hdc);
return dbRGB(GetRValue(pixelColor), GetGValue(pixelColor), GetBValue(pixelColor));
}
And here's a little example with the function:
#include "DarkGDK.h"
#include "GlobStruct.h"
#include "mydbPoint.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbLoadImage("colorCheck.bmp", 1);
dbSprite(1,50,0,1);
dbSetSprite(1,1,0);
int i = 0;
int x = dbMouseX();
int y = dbMouseY();
int colour[3] = {0,0,0};
int colorTemp = 0;
while ( LoopGDK ( ) )
{
x = dbMouseX();
y = dbMouseY();
dbInk(dbRGB(0, 0, 0), dbRGB(0,0,0));
dbBox(0,0,50,100);
if(dbSpaceKey())
{
colorTemp = mydbPoint(x, y);
colour[0] = dbRGBR(colorTemp);
colour[1] = dbRGBG(colorTemp);
colour[2] = dbRGBB(colorTemp);
dbInk(dbRGB(255,255,255), dbRGB(255,255,255));
dbText(0, 5, "R\nG\nB");
for(i = 0; i<=2; i++)
{
dbSetCursor(10, 6+(i*15));
dbPrint((double)colour[i]);
}
}
dbSync ( );
}
return;
}
If anyone wants to use/add on/remove/criticize the code, you're welcome to.
So far, this function can detect pixel colors only on the screen. I've been trying to make it so the user can detect pixels on a specified bitmap from a sprite, not only the screen. My solution of doing that would be getting the bitmap handles from the ImageIDs or SpriteIDs, and then use Win32 API junk to manipulate/scan the bitmap. Afterword, the bitmap would then be stored back in the appropriate Image/Sprite. However, I have not been able to find such IDs or handles. Anyone have any ideas or better solutions?
I am also only 4 days new to dark GDK. So if there is a thread already on this, feel free to to slap me in that direction.