Jump to content
  • Advertisement
Sign in to follow this  
Headkaze

OpenGL Need a way to mask a quad

This topic is 2594 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

I am making a titlescreen for a game on the iPhone using OpenGL ES. It is basically made up of the following quads

1. Scrolling sky (using texture coords to scroll)
2. Hills overlay (where the sky shows through its alpha channel)
3. Shadow of the clouds overlayed on the hills (which is just another quad that scrolls in the reverse direction of the sky)

The problem I'm having is with the shadow overlay on the hills. When I overlay the shadow quad I want it to only show where the hills are. I can't seem to figure out a way to do this. In Flash you would use a mask. I'm sure there is a way using OpenGL ES blending or something.

Share this post


Link to post
Share on other sites
Advertisement
1Draw the terrain regular first with depth testing on. depth = 1
2Draw the shadow next with glDepthMask(true/or false) which it wont write any depth information. But will blend over the terrain and sky.
3Turn depth testing back on, draw your sky at depth = 2. It wont draw over the terrain at depth 1, and it will overwrite the sky because it has no depth information from step 2.

Share this post


Link to post
Share on other sites
dpadam450: I can't seem to get your method to work. If I draw the sky after the hills then they do not seem to draw through the alpha area (around the hills). It just remains black.

Share this post


Link to post
Share on other sites
Then you are using GL_BLEND and not GL_ALPHA_TEST. Which means it still blends alpha = 0*black = black, but it is also writing a depth value. with alpha test on, any alpha values that are below alpha = .1, 0.001, or whatever value you want to discard. This way the alpha pixels are not even blended, they are just completely rejected.Your alpha portions basically are writing depth currently.

Share this post


Link to post
Share on other sites
I got it working now thanks.

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.9f);

m_hillsQuad->Render();

glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);

m_shadowQuad->Render();

glEnable(GL_DEPTH_TEST);

m_skyQuad->Render();


Is using alpha testing the only way? The edges of the hills are a little blocky.

Share this post


Link to post
Share on other sites
Then go into photoshop and blur the edges:
Make 2 layers of the same image. Take the one on the bottom and blur it so that only the edges blur and the top one is still the original.

This of course means keep blending on. You can do both.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!