Sign in to follow this  

Hiding objects in orthographic projection.

This topic is 4074 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
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);
glVertex[b]3f[/b](0.0f, 0.0f, fZ);
glVertex[b]3f[/b](1.0f, 0.0f, fZ);
glVertex[b]3f[/b](1.0f, 1.0f, fZ);
glVertex[b]3f[/b](0.0f, 1.0f, fZ);
glEnd();
}

// OR
void DrawSprite(float fZ)
{
glPushMatrix();
glTranslatef(0.0f, 0.0f, fZ)
glBegin(GL_QUADS);
glVertex[b]2f[/b](0.0f, 0.0f);
glVertex[b]2f[/b](1.0f, 0.0f);
glVertex[b]2f[/b](1.0f, 1.0f);
glVertex[b]2f[/b](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

This topic is 4074 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this