3D Globe - Polygon hidden vertices problem
I have a problem when I rotate a 3D globe (of earth) around the edges the polygons that fill the earth become "clipped" because the vertices that bound the polygon are no longer visible.
I have a screenshot of the problem; http://www.craig-phillips.co.uk/sbs/globe.jpg
I got a feeling that I might have to use the stencil buffer, but I have no experience using the stencil buffer... so if somebody could put me in the right direction it would be much appreciated.
The following is the code to render the 3D globe (C#):
public static void Draw3DScene()
{
// Clear what we already have on screen
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT | Gl.GL_STENCIL_BUFFER_BIT);
// Set the Model Matrix and Load it
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Gl.glOrtho(-1, 1, -1, 1, -10, 1);
if (m_3DZoom > 2)
Gl.glTranslatef(0, 0, -(float)m_3DZoom + 1);
else if (m_3DZoom <= 2)
Gl.glTranslatef(0, 0, -1);
//Gl.glViewport(m_OGLControl.ClientRectangle.Width / 2 - m_OGLControl.ClientRectangle.Height , -m_OGLControl.ClientRectangle.Height / 2, 2 * m_OGLControl.ClientRectangle.Height, 2 * m_OGLControl.ClientRectangle.Height);
Gl.glScaled(m_3DZoom, m_3DZoom, m_3DZoom);
Gl.glScaled((double)m_OGLControl.ClientRectangle.Height / (double)m_OGLControl.ClientRectangle.Width, 1, 1);
Gl.glRotated(m_Center.Lat, -1, 0, 0);
Gl.glRotated(m_Center.Lon, 0, -1, 0);
SetColour(new DisplayColour(120, 180, 240));
Gl.glCallList(m_3D_Globe);
SetColour(new DisplayColour(0, 150, 0));
Gl.glCallList(m_3D_LandPolyDisplay);
SetColour(new DisplayColour(120, 180, 240));
Gl.glCallList(m_3D_WaterPolyDisplay);
// Draw Coastline
SetColour(new DisplayColour(0, 90, 0));
Gl.glCallList(m_3D_CoastLineDisplay);
SetColour(new DisplayColour(80, 80, 80));
Gl.glCallList(m_3D_LatLonLines);
}
Many Thanks
Craig
Assuming that's a convex globe that you're drawing, you shouldn't need a z or stencil test to get correct rendering - back face culling will do everything you need. The z test might be causing your problems.
Try disabling them and see if it helps.
Try disabling them and see if it helps.
Are you sure the far plane is set far enough away so it doesn't clip the globe? And how close is your near plane? The closer you set the near plane to zero, the more inaccurate the Z test becomes. I can only guess as I can't see anything useful from your screenshot
Providing I enable GL_CULL_FACE; could you provide some code (based on the code above that uses culling? I tried the following (but it made it worse);
Gl.glCullFace(Gl.GL_FRONT);
SetColour(new DisplayColour(0, 150, 0));
Gl.glCallList(m_3D_LandPolyDisplay);
SetColour(new DisplayColour(120, 180, 240));
Gl.glCallList(m_3D_WaterPolyDisplay);
// Draw Coastline
SetColour(new DisplayColour(0, 90, 0));
Gl.glCallList(m_3D_CoastLineDisplay);
SetColour(new DisplayColour(80, 80, 80));
Gl.glCallList(m_3D_LatLonLines);
Gl.glCullFace(Gl.GL_BACK);
Gl.glRotated(180, 0, -1, 0);
SetColour(new DisplayColour(0, 150, 0));
Gl.glCallList(m_3D_LandPolyDisplay);
SetColour(new DisplayColour(120, 180, 240));
Gl.glCallList(m_3D_WaterPolyDisplay);
// Draw Coastline
SetColour(new DisplayColour(0, 90, 0));
Gl.glCallList(m_3D_CoastLineDisplay);
SetColour(new DisplayColour(80, 80, 80));
Gl.glCallList(m_3D_LatLonLines);
Many Thanks
Gl.glCullFace(Gl.GL_FRONT);
SetColour(new DisplayColour(0, 150, 0));
Gl.glCallList(m_3D_LandPolyDisplay);
SetColour(new DisplayColour(120, 180, 240));
Gl.glCallList(m_3D_WaterPolyDisplay);
// Draw Coastline
SetColour(new DisplayColour(0, 90, 0));
Gl.glCallList(m_3D_CoastLineDisplay);
SetColour(new DisplayColour(80, 80, 80));
Gl.glCallList(m_3D_LatLonLines);
Gl.glCullFace(Gl.GL_BACK);
Gl.glRotated(180, 0, -1, 0);
SetColour(new DisplayColour(0, 150, 0));
Gl.glCallList(m_3D_LandPolyDisplay);
SetColour(new DisplayColour(120, 180, 240));
Gl.glCallList(m_3D_WaterPolyDisplay);
// Draw Coastline
SetColour(new DisplayColour(0, 90, 0));
Gl.glCallList(m_3D_CoastLineDisplay);
SetColour(new DisplayColour(80, 80, 80));
Gl.glCallList(m_3D_LatLonLines);
Many Thanks
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement