Does any of you guys now if there is an easy way to show a greyscale version of a texture ? I am trying to make a disabled state for some pictures (and it would be too big to have separate pngs).
Greysclaling a texture ?
(12 posts) (4 voices)-
Posted 2 years ago #
-
I know its not what you asked - but you could also easily draw the texture at 50% translucency so it appears faded to connote that its disabled.
Posted 2 years ago # -
I guess the problem is that i don't really understand riq's answer :-/
I am not sure how I am supposed to "tint" a node greyscale.
Posted 2 years ago # -
That's not a bad idea Codemattic. although it might look strange because of the background.
Posted 2 years ago # -
Make it two sprites - first draw the button background/outline which is always solid, then draw your icon over it - 50% for disabled, 100% for enabled.
Posted 2 years ago # -
Get's complicated. :-D I might just put a lock icon over the sprite.
Posted 2 years ago # -
I can't think of any solution that won't use more texture memory. Riq's suggestion of rendering to an FBO will require more texture memory. I assume when you say it is too big to have separate pngs the problem is texture memory?
You can use glColorMask to turn on or off the color and alpha channels, you can use this to easily make a red version (or green, or blue, or yellow etc). You can also use glAlphaFunc to mask out pixels with a certain level of alpha - if you had a sprite with a glow around it this would allow you to create a non glowing disabled version.
Posted 2 years ago # -
It is also easier to color a texture than to try and take the color out. Maybe you could experiment with trying to create the grayscale version (in Photoshop for example) so that when you apply color to it (just set the CocosNode's color property) it looks correct.
Posted 2 years ago # -
Thanks Steve. The problem is still that all those openGL commands are foreign to me. I don't know what an FBO is either. I guess I should make a sprite subclass and modify "draw". (I will buy an openGL book when I am less stressed out I promise).
Texture memory is not a problem, it's mainly preload time in fact that I am worried about.
Since I am pretty out of my time budget, I guess a lock icon will do fine.
Posted 2 years ago # -
Basically if you execute those commands in a draw method they will apply to everything drawn after.
For example glColorMask(1,0,0,1) will make everything drawn after it look red (the last 1 is for the alpha channel and the zeroes turn off the green and blue channels).
FBO is a frame buffer object, it basically allows you to redirect OpenGL drawing commands to a texture, sometimes people call it "render to texture". It is very powerful but you still need some texture memory.
I think coloring a greyscale image could work well. Another technique you can use if the image always stays in the same place is to have the disabled version drawn on the background image and then only draw something when the option is enabled.
Posted 2 years ago # -
I will look into it more closely if I get time, thanks.
Posted 2 years ago #
Reply
You must log in to post.