Jump to content
  • Advertisement
Sign in to follow this  
SteveForever

OpenGL Need some advice on a 2d blending technique

This topic is 4037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey. I've been working on a 2d classic shooter demo in openGL for a few months now and I had an idea for creating a particular effect, I'm just not sure how to do it. I need some advice... The idea is to create a kind of gooey translucent blob that would trail along another texture, blending with it. I figured I could create a daisy chain of GL_QUADS that are in themselves masked textures of circles of varying sizes. This isn't too hard to get that moving blob effect if I had a solid color for all the circles (which is what I might resort to if this it too hard) But what I'd like to do is have the whole blob outlined in, say, black. Here's a picture of my thoughts so far: Free Image Hosting at www.ImageShack.us Fig 1. is all the GL_QUADS each containing a texture of a green circle outlined in black. Fig 2. is how I'd like the blob to be rendered, the middle black lines are somehow blended to pure green. Fig 3. is kind of how I'd like objects rendered before the blob to be blended with, so its like the blob is translucent. So far I've done masking effectively from one of the NEHE tutorials but this has me a little baffled. How do i tell OpenGL to render all the pixels where the black lines intersect another texture to solid green? Any ideas would be most helpful! Thanks in advance. -Steve

Share this post


Link to post
Share on other sites
Advertisement
I do exactly this kind of effect in some of my games. Heres the result on one of the snowmen:



Basically, first render all the sprites but slightly expanded and with black vertex colours to get a silluette. Then draw the coloured versions over the top normally. You don't need any fancy blending - just regular sprite blending (glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)) works fine.

To get the slightly larger version for the silluette, you can either manually draw a bigger sprite or draw the same sprite several times but offset different amounts each time. I find that offsetting by two pixels in each of the eight compass directions generates a nice outline.

Share this post


Link to post
Share on other sites
This is perfect thank you! The only difference might be that I want to blend some object within the blob (Fig 3) so I'm guessing I'll have to:
1: Render the slightly expanded siloutte circles in black.
2: Render the normal sized colored circles.
3: Flip on blending and render the object within the blob.

Does this sound about right? Oh, and your snowman looks amazing.
-Steve

Share this post


Link to post
Share on other sites
Yes, thats how the snowman decals are done - they're just regular blended sprites drawn last so they appear over the top.

Share this post


Link to post
Share on other sites
Ok, I almost got the whole thing how I'd like it. Except I couldn't figure out how to:

1. Have the black border solid.
2. Have the background show through the green middle.
3. Have the spinny blade thing also blend with the green and the background.
4. Still use all the masking.
(I know, I'm asking a lot)
Here's some pics of it so far:


I like how it turned out, I just think it would look even more interesting and more blobby if it were see through. Thanks for all your help so far OrangyTang!
-Steve

Share this post


Link to post
Share on other sites
I don't think you're going to be able to easily make the whole thing transparent, the trick relies on hiding the interiour edges with the fill colour. If it becomes transparent then the inside edges will start to show through.

If you really need transparency then you'll have to draw the whole blob into a texture, then draw that texture to screen with the required transparency.

Share this post


Link to post
Share on other sites
You could try using the depth or stencil buffers and render the middle area and blade things first with blending (and writing to the depth or stencil buffer) and then set up the depth or stencil test properly so that when you render the outline it doesn't render over the middle area. That way the middle will blend with the background correctly first, and then you render just the outline around it.

Share this post


Link to post
Share on other sites
Hmm, I'm definitely going to have to look that one up. I never used the stencil buffer before... I'll see what I can do, thanks for the help guys!
-Steve

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!