I am trying to make a solar system using OpenGL for project. As I have other planets and moons too, I want to make my sun larger than radius=1, and my earth=1 since a little less than 0.18, the sphere is barely visible, and moons cannot be drawn with proper size difference.
Below is my code, if I try to make a sphere with radius > 1, it becomes donut (torus) like. Can anyone guide me on how to make spheres using gluSphere of radius > 1?
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluOrtho2D(-5.0, 5.0, -5.0, 5.0);
GLUquadric *quad;
quad = gluNewQuadric();
gluQuadricDrawStyle(quad, GLU_FILL);
//Sun
glColor3f(2,1.65, 0);
glPushMatrix();
gluSphere(quad, 1, 20, 20);
glPopMatrix();
//Earth
glColor3f(0, 0, 1);
glTranslated(2.f, 0.f, 0.f);
glPushMatrix();
gluSphere(quad, 0.18, 20, 20);
glPopMatrix();
The sphere is clipped by the near and far plane of the viewing volume (Orthographic projection). Use glOrtho
instead of gluOrtho2D
and increase the distance to the near and far plane:
gluOrtho2D(-5.0, 5.0, -5.0, 5.0);
glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
When using Orthographic Projection, the view space coordinates are mapped linearly to the clip space coordinates. The viewing volume is defined by 6 distances (left, right, bottom, top, near, far). The values for left, right, bottom, top, near and far define a cuboid (box). All of the geometry that is within the volume of the box is projected onto the two-dimensional viewport and is "visible". All geometry that is outside this volume is clipped.