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 / Color help

Author
Message
Hashmark
13
Years of Service
User Offline
Joined: 6th Jul 2011
Location:
Posted: 7th Jul 2011 06:06
Hey all I am new to C++ and the GDK.

I am needing to write a small program Displays an image which i have down pat. after a key press the program steps through each pixel and then swaps the red component with the blue component. here is what i have so far, As far as i can tell it does not work, but some of the previous components of the GDK did not show up when i start to debug. I am not looking for a complete answer but some help in the right direction. thank you a head of time.


Thank you for helping!
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 7th Jul 2011 22:33
pixelColor=dbPoint(x,0);

did you mean to not use the y component?

dbDot(blue, green, red);

I'm not at my home pc right now, but isn't that supposed to be dbDot(x,y,color)?
(the color is an DWORD representation of the pixil color)

The fastest code is the code never written.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 7th Jul 2011 22:55 Edited at: 7th Jul 2011 23:28
Believe it or not, there are at least five different problems with that seemingly simple program.

- If you construct a color with Blue = dbRGB(0,0,255) and then try to compare it with the color returned by dbPoint, there is a good chance that they will never be equal. That's because dbRGB adds an alpha component to the created colour, but dbPoint does not add the alpha, so even if the colour is matching, the value will not match. (I remember reading on the forum that it may or may not add alpha depending on the operating system and bitmap version, but I'm not sure.) To solve this, I suggest comparing the individual colour parts:




2. pixelColor=dbPoint(x,0); should be pixelColor=dbPoint(x,y);
otherwise you only check the first row repeatedly, not the whole picture.


3. dbDot(blue, green, red); is a mistake. The parameters of dbDot are: x, y, color. So the first two integers that you give to the function are interpreted as coordinates, not as colour, and the position of the dot will be wrong. Correct this to:


4. EDIT: Disregard this. I was referring to a bug with dbDot not working, but it seems that it works now... at least in this program. Anyway, post again if you have a problem with dbDot (or dbCircle) on your machine.

5. Nothing is drawn if you don't use dbSync() to update the screen. I suggest to sync after every processed line (not after every pixel because that will be VERY slow):



When all that is done, the program should finally work.
Hashmark
13
Years of Service
User Offline
Joined: 6th Jul 2011
Location:
Posted: 7th Jul 2011 23:25
I am using Nvidia 470GTX SLI on Win 7 64bit. Really makes this class class a lot harder than I feel it should be.


Still nothing is showing even after trying the fixes.



Maybe I am still placing something wrong. It also no longer closes out the program. just frozen on my desktop lol.

I will be in class tonight to test it on the XP computers. Thank you for the help really appreciated.

Thank you for helping!
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 8th Jul 2011 00:24
If he/she does a sync even once, the image he posted before will not show up at all and will be lost.

The most efficient way to do what you want is to use memblocks. If you want to try that approach, I'll help you with understanding them.

The fastest code is the code never written.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 8th Jul 2011 08:15
I see that you tried the program before I edited my post. It seems that dbDot actually works in this case, so you won't need the box workaround. (I have NVidia+Win7-64 configuration too.) Also, you put dbSync in the wrong place, inside the inner for loop. That will take an hour to complete the picture. I put it outside the X loop and inside the Y loop.

This morning I tested the program again and it seems that it works even without dbSync, since it is in auto-sync mode. So, getting rid of both the box workaround and dbSync, this should work:



Note that you have to wait a few seconds before the picture appears and in the meantime it looks like nothing is happening (going through several thousand pixels takes time). In the above code I commented out dbSync but if you remove the comment sign there, then you will see progress line-by-line.

@Hawkblood: the image won't be lost with dbSync in this case. But it's true that memblocks would be much faster than working directly on the screen.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 8th Jul 2011 08:33
P.S. If it still doesn't work, check if the blue colour on your image is really RGB 0,0,255. You can remove the "if" and just paint the whole image, to see if the problem is with the "if" comparison or with dbDot. Note that the "box workaround" makes the program unbearably slow, so I hope dbDot will work for you too.
tangy
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location:
Posted: 10th Jul 2011 21:12
if you're taking this course at CCC, tsk tsk, it was due last week(i'm in your class). this is what I did. You're on the right track, just a couple of hick ups.


I have an nVidia card as well, but if you un-remark the dbSetWindowOff() function, dbDot() will work like a charm.

-hahahahaha
Hashmark
13
Years of Service
User Offline
Joined: 6th Jul 2011
Location:
Posted: 14th Jul 2011 06:43
I am in your Class and turned it in on time orig post was prior to it being due.

I have tried all work arounds that have been listed some of these functions just do not work. It is ok i figured out that since they just dont work i go about getting frustrated and start moving things around and messing up the code completely. thank you all for your help.

Now if anyone would like to help me yet again.

Here is what i am working on for class fortunately the functions are working correctly for me.

I have read the chapter over and over and the previous chapter, I have to get this program to move a spaceship which Drew and the BG i Drew as well. I have the UFO moving up and down like it is supposed to everything loads correctly and works smoothly, Except i cannot for the life of me figure out the last line of code i need to get the UFO to here the kicker "FALL SLOWLY" back to its starting point IF dbSpaceKey is false. now for my code.



Thank you all in advance for the help and welcoming me to the community.

Thank you for helping!

Login to post a reply

Server time is: 2024-11-19 09:44:41
Your offset time is: 2024-11-19 09:44:41