But I need a perspective projection since it is a sphere and I need it to be 3D. Is there any way I can fix this problem??
void init()
{
// clear the color buffer (set to black)
glClearColor(0.0, 0.0,0.0, 0.0);
// enable depth testing so it appears black
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
// do flat shading (the most efficient)
glShadeModel(GL_FLAT);
// cull back facing polygons that we aren’t going to see anyway
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// set up the viewing - this is set up to be the window
// size
glViewport(0, 0,
static_cast(globeFormWidth_),
static_cast(globeFormHeight_));
// set the viewing to projection
glMatrixMode(GL_PROJECTION);
// put the identity matrix on the stack
glLoadIdentity();
// set near and far clipping planes
nearClip_ = 5;
farClip_ = globeFormWidth_;
// determine the width to height aspect ratio
aspect_ = (static_cast(globeFormWidth_))/
(static_cast(globeFormHeight_));
// set the perspective camera. We will use 20 as our FOV angle, as it seems
// to work the best for eliminating corner distortion. Please note that if
// you change the FOV angle, the radius of the globe will have to change to
// compensate for it. The formula used to figure out the news radius is
// globeFormWidth/(DeltaFOV/10) * 6;
gluPerspective(20,
aspect_,
// the values where the z plane are on
nearClip_, farClip_);
// now we are going into model view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
startZ_ = attributes_.globeRadius_ * -2;
//zoom along the z-axis so that we can see the objects
glTranslatef(0.0, 0.0, startZ_);
// do some font related stuff
} // end init
void draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
if (!attributes_.isHidden_) {
// first determine the density and set hi/low
determineDensity();
// now do the globe work. First push the matrix on the stack
glPushMatrix();
// move it to where it should be
glTranslatef(attributes_.currentPos_.x_,
attributes_.currentPos_.y_,
attributes_.zoomDist_);
// set the pixel zoom where 1.0 is no zoom. This is for drawing text
//
double pixelZoom = attributes_.zoomDist_/280.0;
if (pixelZoom < 0) {
pixelZoom = pixelZoom * -1;
}
glPixelZoom(pixelZoom, pixelZoom);
glPushMatrix();
// because we are rotating the globe by 90, the x and y
// rotation need to be on the other axis
glRotatef(attributes_.yRotation_.measuredIn(degree), 1.0, 0.0, 0.0);
glRotatef(attributes_.xRotation_.measuredIn(degree), 0.0, 1.0, 0.0);
// if the globe needs to be created again
//
if (attributes_.createGlobeDisplayList_) {
createGlobeDisplayList();
}
// enable the texture
glEnable(GL_TEXTURE_2D);
// We are enabling Polygon Offsetting to help eliminate
// Z fighting of the overlays that come close to or are
// directly on top of the globe's surface.
glPolygonOffset(1.0, 1.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);
// call the display list that contains the earth
glCallList(attributes_.globeDisplayList_);
//nothing else should have a texture
//
glDisable(GL_TEXTURE_2D);
glPopMatrix();
glDisable(GL_POLYGON_OFFSET_FILL);
// draw some other junk here
// While glXSwapBuffers will call a glFlush before it swaps the buffers,
// we want to make sure that all the openGL calls are finished before
// we swap the bufffers.
glFinish();
// this pushes all the information out of the back buffer onto the screen
//
glXSwapBuffers(display_, window_);
// make sure this is done drawing before leaving
glXWaitGL();
} // end draw
void zoom()
{
// get mouse movement
attributes_.zoomDist_ = currentZ - mouseMovement;
}