SetColor, dun wanna it over my Image!!!

BlitzMax Forums/BlitzMax Programming/SetColor, dun wanna it over my Image!!!

Insane Games(Posted 2005) [#1]
Well, my problem is:

if I load a TImage using LoadImage Function called myImage, it's ok :)
then in the main loop, if I do this:

SetColor( 200, 0, 0 ) 'or whatever between 0 and 255
DrawRect( 10, 10, 100, 100 )
DrawImage( myImage, 200, 10 )

so, myImage receives the SetColor too!!!
in this case, myImage receives a lot of red. and become much more red. myImage losts it's natural colors.

Can I prevent it???
I mean, do not "colorize" myImage???

thx :)


Tom Darby(Posted 2005) [#2]
SetColor( 200, 0, 0 ) 'or whatever between 0 and 255
DrawRect( 10, 10, 100, 100 )
SetColor(255, 255, 255)
DrawImage( myImage, 200, 10 )


Insane Games(Posted 2005) [#3]
no comments to myself...

thanks a lot man
it looks so obviously now...

thank u :D


IPete2(Posted 2005) [#4]
Thing is, Insane, that whatever you set will affect everything until you change it again.

IPete2.


Tom Darby(Posted 2005) [#5]
No problem--remember, scaling and rotation work the same way, too...


ImaginaryHuman(Posted 2005) [#6]
It is more efficient to do it that way, especially as BlitzMax was originally mainly designed around working with OpenGL, which is a state machine - ie you set the state of something like `current color` and it stays that way until you set it to something else. That way it is more efficient to access what color to use, rather than having to pass the color every single time with every single graphics command.

So yes, to do it `the old less efficient way`, you have to deliberately set the `current` color inbetween stuff to stop it interfering with things in an undesirable way. Or alternatively you can restructure your code with this in mind. Draw your image before the SetColor for example.


JazzieB(Posted 2005) [#7]
I actually find this way of doing things with SetColor very useful. I usually design my bitmap fonts in grey scale and then use SetColor to display any text the colour I want it. Saves having to design several different coloured fonts or pre-render them at the beginning of your code.

Has lots of other uses too, like the flashing of a big boss in a shoot'em up where it flashes red whenever you hit it.


ImaginaryHuman(Posted 2005) [#8]
You might possibly be also able to store a grayscale texture, saving lots of video mem, and then coloring it when it is drawn.


Dubious Drewski(Posted 2005) [#9]
Would that work, AngelDaniel? Blitz can't load greyscale
pngs. And even if it could, would an 8-bit instead of 32 bit
image even speed anything up? Byte and Short variables
don't give speed advantages.

Please correct me if I'm wrong.


ImaginaryHuman(Posted 2005) [#10]
I know that OpenGL can store textures in a variety of formats including RGBA or even with individual channels like just a `Red` channel texture. You could load in (somehow) a 256-color image (grayscale) and upload it as a Red image, then when you render using that data you can use a particular blend more or whatever to turn the red into RGBA representation of the grays, plus whatever color you want to tint with. It would just save video ram used to store the texture and might be a little faster since less data has to be read in order to draw it. You would have to set this all up with direct OpenGL calls yourself, BM wouldn't do it for you.


Ferminho(Posted 2005) [#11]
I use a basic (but very fast) tile lightning system based in setcolor for my sidescroller, amongst other uses. SetColor comes in pretty handy for some things :)

Only drawback is you can set the 'component percentage' from 0 to 100% but no more. Would be nice to 'overload' components.


Dubious Drewski(Posted 2005) [#12]
Ah, cool. I haven't gone into OpenGL just yet. But it sounds
as though you can do more specific and low-level creation
with it in BM. When I get some time after this semester-long
programming crunch, I'm trying it out.

(Being able to write BlitzMax programs for university credit is
very exciting.)