Need a way to mask a quad

Started by
4 comments, last by dpadam450 12 years, 5 months ago
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.
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.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement