Resolved Rendering texture solid white for taking damaging effect?

Discussion in 'iOS Programming' started by charmofmaking, Mar 24, 2013.

  1. charmofmaking, Mar 24, 2013
    Last edited: Mar 27, 2013

    charmofmaking macrumors member

    Joined:
    Feb 2, 2013
    #1
    Can you remember arcade games where the enemies turned solid white as you shot them to indicate that they were taking damage? Wasn't it great!

    I can change the amount of red, green or blue using glColor which is cool:
    glColor4f(1.f, 0.f, 0.f, 1.0f);//r,g,b,alpha

    What I want to do now is render the sprite with all colour as white, while preserving the alpha channel so we get the silhouette in white...

    Anyone out there know how to do this without shaders, as my code is using opengl 1.1 based on the Apple GLsprite example code.
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    Just a random idea... what happens if you give it numbers greater than 1 (say 255 for the R, G, and B components?) Disclaimer: I've never worked with OpenGL kit, but if I wanted to try something, I might try that based on my understanding of what you're asking.
     
  3. charmofmaking thread starter macrumors member

    Joined:
    Feb 2, 2013
    #3
    I can see where you are coming from, 255,255,255 is usually r,g,b for white but in this case the values are between 0.0 to 1.0!

    0,0,0 renders the shape solid black so maybe I can invert it somehow...

    Maybe 1,0,0 isn't so bad as red is a common damage colour whereas people might think the white mask is a glitch rather than a bit of retro nostalgia!
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    My understanding is your have input sets of numbers RGBA, between 0 and 255, and each of those is multiplied by their corresponding number that you provide. If you provide numbers less than 1, you'll end up with an image darker than you started with.

    I've never seen it tried before, but what if you provide a number greater than 1? My guess is it either does nothing or it might saturate the component. If you saturate R, G, and B, you'll end up with white (unless the original R, G, or B was exactly 0, in which case you might end up with a undesired color.) I suggested 255 because if the input was 1, it'll be 255 after multiplication.

    But that's totally just a guess. Did you try it?
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Any values greater than 1.0 are capped at 1.0.
     
  6. Sonnestah macrumors regular

    Joined:
    Mar 2, 2013
    #6
    glColor4f(255, 255, 255, 255);

    gives me a white shape

    :confused:
     
  7. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #7
    So would
    Code:
    glColor4f(1.0, 1.0, 1.0, 1.0);
    As the other poster says, values above 1.0 get clamped to 1.0.
     
  8. charmofmaking thread starter macrumors member

    Joined:
    Feb 2, 2013
    #8
    Yes that does draw a white shape but I was trying to render a texture with its RGB elements set to white while keeping the alpha value so you would see the sprite turn soild white but keeping its outline.

    I was hoping there was a glReplicateAmiga500CodeOnIOS command!

    Perhaps its time to move on :D

    Anyway setting 1,0,0 actually looks rather nice as you can still see the detail of the sprite but it is in shades of red. Red being damage so I think I will go with that.

    Many thanks.
     
  9. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #10
    Amiga! Wow, that goes back a ways. (Like early 1990s.) Some of my friends and coworkers were big fans of the Amiga.

    What are your sprites, textures?

    I haven't tried using OpenGLES 1.x on iOS. I've used 2.0, and would simply add a drawInWhite flag to my pixel shader that ignored the color from my texture and drew all non-transparent pixels of the texture in white.

    What happens if you set the color using a 3 value call to glColor? (specify RGB, but not alpha?) There should be a drawing mode that ignores the color of each pixel from the source texture and instead uses the current color.

    I've done a fair amount of OpenGL now, but I still have to slog through the books and dig whenever I want to do something new.

    If you can't figure out a drawing mode that ignores the colors in your texture, you might need to write code that extracts the alpha channel out of your texture into a new alpha-only texture and then draw with THAT.
     
  10. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #11
    You could just add "damaged" sprites that have the same alpha mask and swap them in/out as appropriate. Might be the easiest way if there's no better way.
     
  11. charmofmaking thread starter macrumors member

    Joined:
    Feb 2, 2013
    #12
    Yes that would do it :)

    Long term I should also go with Duncan C and update the code to OpenGLES 2.0 as that has Shaders that can modify the output in all manner of ways.

    Thanks everyone for the suggestions.

     

Share This Page