Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3230164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:53:41+00:00 2026-05-17T16:53:41+00:00

We’re in the process of creating an iPhone game using cocos2d . We’re trying

  • 0

We’re in the process of creating an iPhone game using cocos2d. We’re trying to layer several sprites on top of each other and have them cast shadows.

Right now the shadows are rendered as sprites which works fine for the most part. But we only want the shadows to hit the closest layer.

I’ve made an image that hopefully explains what we’re trying to accomplish:

And here’s what we have at the moment:

Basically we want the sprite to only render the part of the shadow that is at the same depth as the z-buffer.

We’ve played around with glDepthFunc and GL_DEPTH_TEST but nothing seems to work.

Here’s how we’re rendering the shadow sprite (subclassed CCSprite):

- (void)draw {

    glDisable( GL_BLEND );

    glEnable( GL_DEPTH_TEST );
    glDepthFunc( GL_LESS );

    glDepthMask( GL_FALSE );
    [super draw];
    glDepthMask( GL_TRUE );

    glDisable( GL_DEPTH_TEST );

    glEnable( GL_BLEND );
}

The GL_BLEND calls are only there so we can see the sprite at all times.

All sprites that aren’t shadows use glDepthMask( GL_TRUE ) and we’re clearing the depth buffer on each frame.

Any help would be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:53:42+00:00Added an answer on May 17, 2026 at 4:53 pm
    glDepthFunc(GL_LESS)
    

    is actually the default value; it means “draw the pixel only if the thing currently in the depth buffer is further away”. If you wanted exactly equal you’d use glDepthFunc(GL_EQUAL), but in practice you’ll get all sorts of rounding oddities if you do that.

    Assuming you’re able to use depth values for this purpose, if you have ten objects then I’d suggest you:

    1. set glClearDepth to 0 before you glClear; this’ll fill the depth buffer with the nearest storable value so that with normal depth buffering nothing else would be drawn.
    2. disable the depth and draw the shadows such as they’re supposed to fall on the back plane; at this point your depth buffer will still be full of the nearest possible value.
    3. enable the depth test but set glDepthFunc to GL_ALWAYS. Then draw all your solid rectangles in back to front order with their depth values set appropriately.
    4. set glDepthFunc to GL_LESS and draw the shadows that are meant to fall on other sprites, each positioned further back than the sprite they’re associated with but in front of the sprite behind.

    By the time you get to step 4, you’ll have correct depth information everywhere a sprite was drawn and you’ll have the closest possible value set wherever the background plane was. So normal depth testing will work on the intermediate shadows — they’ll draw on top of anything drawn in step 3 but not on top of anything drawn in step 2.

    You’re sort of using the depth buffer as a surrogate stencil, which the older iPhones don’t support.

    If you can’t afford to use the depth buffer for this task then all I can think of is projecting the shadows as textures in the second texture unit, using the first for a mask texture (or not if you’re actually drawing rectangles, but I guess you’re probably not) and doing one rendering pass per sprite per shadow that falls upon it. Is that a passable solution?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.