Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Having difficulty getting dbPoint() to work

Author
Message
afaik
14
Years of Service
User Offline
Joined: 12th Jun 2010
Location: NYC
Posted: 13th Jun 2010 06:03 Edited at: 13th Jun 2010 06:10
Hi everybody. Usually I would keep to myself and keep at it until I either figure it out or give up, but I really want to figure this out so I'm here posting and hopefully someone wiser will direct me.

I am going by the book Games and Graphics in C++ by Tony Gaddis and am having some difficulty getting one of the programs to work right. I know from other posts that their is an issue with vista/7 and some of the functions but I am using XP and am having trouble.

The point of this program is to go pixel by pixel through the bitmap and count whether it is a pure blue pixel (0, 0, 255) or not. If it is, increment totalBlue. When done, output the result but the output is always 0. Here is the code word for word from the book.



Any help will be appreciated.

Attachments

Login to view attachments
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 13th Jun 2010 06:51
This may sound a bit stupid, but it may not be working because of that "const" you have in there.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
afaik
14
Years of Service
User Offline
Joined: 12th Jun 2010
Location: NYC
Posted: 13th Jun 2010 07:16
Thanks for your input. Same result. The code compiles but I still get a 0 for an answer. Very frustrating this is.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 13th Jun 2010 08:57
Bingo, the const value is the problem. If you put a breakpoint in the debugger and inspect the value of the const BLUE, compared to the value returned by dbPoint, you will see the issue.

dbRGB(0,0,255) not only puts the 255 into the number, but it puts a value FF into the highest bits of the hexadecimal value as well (which is, I suppose, the alpha channel). Therefore the value will not be 255 which is 0000FF in hexa, but it will be hexa FF0000FF which is a very high number in decimal and it is never equal to 255.

Make your const equal simply 255 and it will work.
haliop
User Banned
Posted: 13th Jun 2010 10:08
btw i dont know if you got it to work.
if you did, you can insert
dbLockPixels(); before the for loop.
and dbUnlockPixels(); after.

dbPoint works much faster with it.
you may not notice it on a small bitmap, but big ones will show you the speed.
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 13th Jun 2010 17:16
@Mireben

Yea, that's probably the real issue, but quick question.

How do you use Hexcode color values in C++. I've been wondering how to do this, since I don't want to have to use dbRGB() all the time.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 13th Jun 2010 18:35
@Cuddle Bunniezzz 12: Assuming a 32-bit color value, you can simply bit-shift the various color components into place. ie:



This works fine if you know that your internal color representation is 32-bit ARGB value; however, problems arise if the internal format is XRGB, R5G6B5, X1R5G5B5 etc. In those cases, you would probably be better off using the dbRGB() function instead. Saves alot of headaches as you don't have to be aware of the internal color format being used by the graphics hardware.

Presumably, though, I think that any of the GDK functions that take an dbRGB() color as a parameter provides the appropriate conversions internally (although I'm not sure on this point) in which case the above macro would be ok to use and most likely faster since you avoid the function call overhead...

JTK
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 13th Jun 2010 22:57
@JTK, can't I do something like this:



http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 13th Jun 2010 23:21 Edited at: 13th Jun 2010 23:21
Yes you can, but that particular color isn't blue. You are setting both the Green and Blue components to a value of 255 which is equivalent to dbRGB(0,255,255); not what you want...

The color component breakdown from above goes as follows:



Remember, each component is one-byte, and each character of a hex-value represents a nibble (4-bits) so it takes 2-nibbles to make a full byte...

JTK
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 14th Jun 2010 01:43
What? - a NIBBLE?!

(Sorry, my native language isn't english, but it just sounded so funny. Like isn't there a creature called "Nibbler" in Futurama?)

But lots of color theory going on - nice. Keep the info coming.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 14th Jun 2010 04:29
@JTK

Ah thanks, I thought that the Alpha value was the last two nibbles of the Hexcode.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
afaik
14
Years of Service
User Offline
Joined: 12th Jun 2010
Location: NYC
Posted: 16th Jun 2010 02:14
Hey guys. I'm not sure if I'm doing something right or wrong. I found out I can get the program to look for blue pixels by doing this:

CONST DWORD BLUE = 255;

I have not been able to get this to work:

CONST DWORD BLUE = dbRGB(0, 0, 255);

which is the way the book is teaching. Removing the CONST hasn't changed anything. I'm using visual c++ express 2008.

Is it only me that this is not working for or do others have this problem also? I can move on, but I would like to know why this is happening. Thanks alot

Login to post a reply

Server time is: 2024-11-19 23:22:31
Your offset time is: 2024-11-19 23:22:31