PDA

View Full Version : Drawing with a hue change?



NickS
13-02-2011, 01:50 AM
I was wondering if there is a way to draw a zglPTexture with a modified hue. I'm writing a game with this (excellent!) library and I would like to add colour dye to armour or make variations of monsters with different colours.

Thank you in advance :D

chronozphere
13-02-2011, 10:11 AM
I guess you'd have to do that yourself. One thing you could do is reserve one colour like purple (255,0,255) and replace it with other colours for all your different monsters. But you'd need to change hue if you want to change your whole monster to another color.

Convert RGB to HSV:
http://delphi.about.com/od/adptips2006/qt/RgbToHsb.htm
Convert from HSV to RGB:
http://www.delphipages.com/forum/showthread.php?t=133111
More info:
http://www.efg2.com/Lab/Graphics/Colors/HSV.htm

So just write a function that takes one pixel as input, converts to HSV, changes hue, then back to RGB. Call it for every pixel and you're done. :)

One cool variation would be to use a mask. That'd give you control over which area's of the picture must be changed and which will have the same color. :)

Good luck!

Andru
13-02-2011, 10:29 AM
If there is a solution via standard OpenGL pipeline, I would implement it in ZenGL, but there is a problem with that. One solution, which can do things like this is color matrix, but latest drivers for new hardware are not support them(here the demo with grayscale effect in realtime (http://zengl.org/tmp/grayscale.7z), but seems it works only on my ArchLinux with Radeon HD 4650 and Radeon HD 5850 :)). Another way - pixel shaders, but for now ZenGL doesn't provide functionality for them. So, the only possible way for now is using different textures. You can modify them in any graphical editor and save for later using, or modify pixels during loading the texture via tex_LoadFromFile. For this - add to flags TEX_CUSTOM_EFFECT and register your own postprocess procedure via zgl_Reg and constant TEX_CURRENT_EFFECT:


procedure myHUE( var pData : Pointer; Width, Height : Word );

where pData - pointer to pixels in RGBA, which you must modify.


or make variations of monsters with different colours
One more solution - color mix(function fx2d_SetColor, see demo05), but it's not so good as changing hue.

code_glitch
13-02-2011, 10:43 AM
I think the important bit here Andru is the
ArchLinux bit. I will be the first person to admit that there is a world of difference between OpenGl on windows and almost any linux 'distro' (call them that for simplicity and not anger mobs of users). Perhaps as linux is solely dependant on OpenGl for graphics? I dont know - but I believe it may not just be the card at fault.

A thought to keep in mind.

Andru
13-02-2011, 10:55 AM
I think the important bit here Andru is the
Maybe, but there are such OpenGL extensions as GL_ARB_imaging and GL_SGI_color_matrix(this was in OpenGL 1.2), which were dropped under Windows for many videocards and drivers... and I hate developers for that >_<

code_glitch
13-02-2011, 11:32 AM
Ah yes, the infamous ARGB format (I had some nice battle with that one but won in the end) and I must say that ever since Prometheus went Gl, I am so glad I am not on windows ;) Its no surprise you see a majority of OpenGl code written on mac or linux. Thats no minority windows developers - get with the program. Excuse the pun.

NickS
15-02-2011, 12:53 PM
Thank you a bunch once again =) I used the code from demo05 for now for colour changing, will implement the more complicated way using hue in the future.

Thanks so much!