Jump to content
  • Advertisement
Sign in to follow this  
Yezu

Hiding objects in orthographic projection.

This topic is 4292 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 have a problem with my fairly simple 2d game. In certain situations I want one sprite to hide behind another, or vice versa. I've figured out that painting the object which is behind first, does just that. However in my case that method is not useful. Is there an alternative?

Share this post


Link to post
Share on other sites
Advertisement
You could translate the object into the background, by either explicitly setting it's 'z' value, or by translating it.


eg.

void DrawSprite(float fZ)
{
glBegin(GL_QUADS);
glVertex3f(0.0f, 0.0f, fZ);
glVertex3f(1.0f, 0.0f, fZ);
glVertex3f(1.0f, 1.0f, fZ);
glVertex3f(0.0f, 1.0f, fZ);
glEnd();
}

// OR
void DrawSprite(float fZ)
{
glPushMatrix();
glTranslatef(0.0f, 0.0f, fZ)
glBegin(GL_QUADS);
glVertex2f(0.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
glVertex2f(0.0f, 1.0f);
glEnd();
}



You will have to enable depth test (in case your background object is draw AFTER your foreground object).

Also, you will have to make sure that translucent sprites (ie. semi see-through sprites) are always drawn last (and without depth-write), regardless of whether they are in the background or not.

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!