Sign in to follow this  

Problem with objects being drawn wrong

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

Hello everyone, I have following problem, I can't seem to solve: When I call the function below, I want to draw a series of of Quads (consisting of two Triangles) with a texture on it to create a game map (comparable with Zelda, but with "a little 3D"). The whole thing draws just fine, but some "quads" that should be underneath another are drawn above it - it somehow overwrites the higher quad although it has a lower y (height) value. Sorry, I don't know how to explain it exactly. I tried sorting my quads by height (y axis), that the scene will be drawn from top to bottom, but that didn't solve the problem either.
GLvoid DrawMap(GLvoid)
{
	TilesInGame *ActMapElement=NULL;
	glLoadIdentity(); // Reset The Current Modelview Matrix	
	glColor3f(1.0f,1.0f,1.0f);
	glEnable(GL_TEXTURE_2D);
	glTranslatef(-2.0f,-2.0f,-25.0f);
	glRotatef(MapRoty,0,1.0f,0);
	glRotatef(MapRotx,1.0f,0,0);
	for(int x=0;x<GridCountx;x++)
	{
		for(int z=0;z<GridCounty;z++)
		{
			if((ActMapElement=GetMapElement(x,z))!=NULL)
			{
				glBindTexture(GL_TEXTURE_2D, texture[ActMapElement->Texture]); 
					glBegin(GL_TRIANGLES);
						glTexCoord2f(0.0f,1.0f);glVertex3d(MapRelx+ActMapElement->Posx,     ActMapElement->Height, MapRelz+ActMapElement->Posz);
						glTexCoord2f(1.0f,1.0f);glVertex3d(MapRelx+ActMapElement->Posx,     ActMapElement->Height, MapRelz+ActMapElement->Posz+1.0f);
						glTexCoord2f(1.0f,0.0f);glVertex3d(MapRelx+ActMapElement->Posx+1.0f,ActMapElement->Height, MapRelz+ActMapElement->Posz+1.0f);

						glTexCoord2f(1.0f,0.0f);glVertex3d(MapRelx+ActMapElement->Posx+1.0f,ActMapElement->Height, MapRelz+ActMapElement->Posz+1.0f);
						glTexCoord2f(0.0f,0.0f);glVertex3d(MapRelx+ActMapElement->Posx+1.0f,ActMapElement->Height, MapRelz+ActMapElement->Posz);
						glTexCoord2f(0.0f,1.0f);glVertex3d(MapRelx+ActMapElement->Posx,     ActMapElement->Height, MapRelz+ActMapElement->Posz);
					glEnd();
			}
		}
	}
	glDisable(GL_TEXTURE_2D);
}

Can anyone see something I must have missed?

Share this post


Link to post
Share on other sites

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