Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075928 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:57:53 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)OpenGLES blend function for silhoette
Pages: [1]
Print
Author Topic: OpenGLES blend function for silhoette  (Read 850 times)
Charybdis
Level 1
*


View Profile WWW Email
« on: April 16, 2012, 05:10:35 AM »

Hi there
I am currently trying to set the blend system in opengles to render sprites as a white silhouette. Basically, I want to simply draw the alpha channel of a sprite. So, a pixel should be white where the src alpha is 1 and background colour when src alpha is 0. That is, I want it to completely ignore src colour.
It's turning out to be more difficult than I thought.
The problem is that no matter what I set for the first argument of glBlendFunc, it will always MULTIPLY the src colour.
So I thought the answer must lie with glBlendEquation or glBlendFuncSeparate. I have read the description of how they work but I just dont get it.
Can anyone help? I hope I have made the problem clear. Perhaps I should mention that I am also using premultipled alpha textures although I think it's irrelevant for this problem.
Cheers
Logged

rivon
Level 10
*****



View Profile
« Reply #1 on: April 16, 2012, 06:47:22 AM »

I don't know OGL but isn't it possible, when loading the sprites, to just rewrite the color part with white and leave only the alpha unchanged?
Logged
Christian Knudsen
Level 10
*****



View Profile WWW Email
« Reply #2 on: April 16, 2012, 07:04:57 AM »

I don't know much about OpenGLES, so this might only be possible in regular OpenGL. But you can have a texture that's white, then draw the sprite with the alpha values onto this texture as an FBO, but setting glColorMask to only write to the alpha buffer. That'll leave you with the white texture with the alpha values from the sprite.
Logged

Laserbrain Studios
Currently working on Hidden Asset (TIGSource DevLog)
Charybdis
Level 1
*


View Profile WWW Email
« Reply #3 on: April 16, 2012, 06:29:13 PM »

I don't know OGL but isn't it possible, when loading the sprites, to just rewrite the color part with white and leave only the alpha unchanged?

That is certainly esy to do, but my reason for wanting to do this is to flash the agent sprites white when taking damage, oldskool style. I dont want to have a duplicate textures for all agents in memory just for that.
I'm sure it must be possible with blend modes.
Logged

Charybdis
Level 1
*


View Profile WWW Email
« Reply #4 on: April 16, 2012, 06:31:39 PM »

I don't know much about OpenGLES, so this might only be possible in regular OpenGL. But you can have a texture that's white, then draw the sprite with the alpha values onto this texture as an FBO, but setting glColorMask to only write to the alpha buffer. That'll leave you with the white texture with the alpha values from the sprite.

Good suggestion, thanks. But it seems like overkill for what I want to do.
I can't believe its so difficult. All I want to do is draw an alpha mask by fiddling with blend modes/equations.
Logged

wademcgillis
Guest
« Reply #5 on: April 16, 2012, 06:44:48 PM »

OpenGLES X.Y

What are the values of X.Y that you are using?

Edit:
Or, to elaborate:

If 1.X, use fog. GL_FOG_START should be zero GL_FOG_END should be zero. TADA! Instant flash to a color.

Code:
Enable fog.
Set start and end distances to zero.
Set color to whatever you want.
Set mode to whatever.
DRAW THE THING.
Disable fog.

If 2.X, use fragment shaders to change the colors of your image.
Code:
Enable shader and pass the color you want to it
DRAW THE THING.
Disable shader
Logged
Xienen
Level 3
***


Greater Good Games


View Profile WWW
« Reply #6 on: April 18, 2012, 09:58:02 AM »

Wade has good suggestions for both versions of OpenGLES, but I can tell you that if you'd like to go the glBlend route for either of them, you'll definitely want to use glBlendFuncSeparate.  These parameters might work for you, but you'll have to test it: GL_ONE, GL_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
Logged

Evan Balster
Level 10
*****


I live in this head.


View Profile WWW Email
« Reply #7 on: April 18, 2012, 10:26:27 AM »

I will also nudge you towards writing a simple shader.  That's the proper way to approach GL programming these days when you're doing anything nontrivial.  No blend mode will do what you want for black source and black destination, as they always multiply by source and destination color by definition.
Logged

Creativity births expression.  Curiosity births exploration.
Our work is as soil to these seeds; our art is what grows from them...


Wreath, SoundSelf, Infinite Blank, Cave Story+, <plaid/audio>
Xienen
Level 3
***


Greater Good Games


View Profile WWW
« Reply #8 on: April 20, 2012, 09:32:36 AM »

I will also nudge you towards writing a simple shader.  That's the proper way to approach GL programming these days when you're doing anything nontrivial.  No blend mode will do what you want for black source and black destination, as they always multiply by source and destination color by definition.

Ah, Evan is correct.  There's no good way to do that with blend modes.
Logged

Charybdis
Level 1
*


View Profile WWW Email
« Reply #9 on: May 21, 2012, 05:27:56 PM »

use fog

Brilliant! Why the hell didnt I think of that? You, sir, are a bloody genius. Cheers!!!!   Toast Left  My Word!
Logged

Charybdis
Level 1
*


View Profile WWW Email
« Reply #10 on: May 21, 2012, 05:34:57 PM »

Nooooooooo!!
Fog not playing nice with premultiplied alpha
Waaaaagh!!!  Cry

Logged

Charybdis
Level 1
*


View Profile WWW Email
« Reply #11 on: May 21, 2012, 05:40:27 PM »

Phew, alpha test to save the day. Lucky I have no soft edges.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic