PDA

View Full Version : How can I add color on texture?



opty2001
08-02-2013, 12:19 AM
Hello.

I'm developing a 2d game, that use glOrtho and some texture, source is png file(includes alpha value).

I have a problem. I don't know how can I add colors in texture. Example of image file is this..

http://i.stack.imgur.com/CtR3e.png
(It's existing online game's sprite)

Now I want to add color in this pixels(consider alpha value).

If that color is white, I set color's alpha value each frame, and that image effects such as shining, I expect.
http://i.stack.imgur.com/T31l8.png

I've tried a method that 'make other file with Photoshop and put on original image', but it's looks like too stupid, and too static.

If I use this method, whenever add another image files I must make another 'color' image files too!

And.. I've used glColor4f(3,3,3,1) or glColor4f(100,100,100,1), glC... whatever, the value of glColor4f did not exceed '1'.(edit : '1' -> 'original')
it was useless in this case.

So I ask for help to this site.

How can I add color on texture? and what is the best method?

--------------------------
Now I find a way to upload image on this site, image has uploaded successfully. But problem of openGL is still exist.

thokra
08-02-2013, 12:56 AM
C:\Users\JYJ\Desktop\2.png

Srsly?


the value of glColor4f did not exceed '1'

That's because values are clamped to 1.f ...

You need to provide arguments in [0,1]. You simply divide your integer color values by 255 and pass the result to glColor4f.

opty2001
08-02-2013, 12:57 AM
Sorry, I can't find a way to upload image files.
I input address in text, it send me an error message.
"Post denied", I saw this message over than 10 times..
And.. I means original -> image's all pixel turns to wanted rgb value or add rgb value like blend color on original image, consider alpha value.
when I use glColor4f(?.0f,?.0f,?.0f,1.0f), it display only less rgb value.. How can I use glColor4f in correct way?

Quaver
08-02-2013, 01:22 AM
To make anything have half transparency, set it's RGB values to 1 so the color is unchanged, then modify the 4'th parameter which is for alpha.


glColor4f(1.0f, 1.0f, 1.0f, 0.5f);

Make sure to reset the color after you have drawn it by doing:


glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

opty2001
08-02-2013, 01:25 AM
Now this site don't return error message!
The body has edited.

GClements
08-02-2013, 12:27 PM
And.. I means original -> image's all pixel turns to wanted rgb value or add rgb value like blend color on original image, consider alpha value.
when I use glColor4f(?.0f,?.0f,?.0f,1.0f), it display only less rgb value.. How can I use glColor4f in correct way?
glTexEnv(). E.g.


glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);

will add the current colour to the texture's colour rather than multiplying it.

If you set the mode to GL_COMBINE (requires OpenGL 1.3 or later), then you can combine colours and textures using complex expressions. But that feature has largely been superseded by shaders.

opty2001
08-02-2013, 10:51 PM
Thank you! Problem is solved!

And in addition, Is there people who know how to change the texture's all pixel to targeted color?
1096

Anyway, problem is solved. Thank you again!