Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: How can I add color on texture?

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    6

    How can I add color on texture?

    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..


    (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.


    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.
    Last edited by opty2001; 08-02-2013 at 03:36 AM.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    [IMG]C:\Users\JYJ\Desktop\2.png[/IMG]
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    6
    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?
    Last edited by opty2001; 08-02-2013 at 01:22 AM.

  4. #4
    Intern Newbie
    Join Date
    Jul 2013
    Posts
    35
    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.

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

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

    Code :
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    6
    Now this site don't return error message!
    The body has edited.
    Last edited by opty2001; 08-02-2013 at 02:48 AM.

  6. #6
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by opty2001 View Post
    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.
    Code :
    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.

  7. #7
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    6
    Thank you! Problem is solved!

    And in addition, Is there people who know how to change the texture's all pixel to targeted color?
    Click image for larger version. 

Name:	6.jpg 
Views:	75 
Size:	6.6 KB 
ID:	1096

    Anyway, problem is solved. Thank you again!
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	6.png 
Views:	68 
Size:	9.7 KB 
ID:	1095  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •