stanley John wrote:
The program uses glaux library, which was a part of the GLUT library and is now obsolete. we need to rewrite the program using GLUT.
I'm not an OpenGL expert but from what I recall, GLAUX was never a part of GLUT; the latter was intended as a replacement for GLAUX.
Some sleuthing
reveals[
^] that many of the calls to the GLAUX library in this example program can be replaced with equivalent GLUT functions with two exceptions.
The first is
auxKeyFunc() where each call wires an event to a single key. GLUT uses the function
glutKeyboardFunc()/
glutKeyboardUpFunc() to read most keys and
glutSpecialFunc()</i>/<i>glutSpecialUpFunc() for the rest. Inside of each, a
switch statement is used to decode the keystroke and proceed acoordingly.
The second is the call to
auxWireSphere(). The GLAUX version requires only the radius; GLUT requires radius, number of slices (longitude), & number of stacks (latitude).
With that in mind, here's my solution:
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include "glut.h"
#define ESCAPE_KEY 0x1B
#define SPACE_KEY 0x20
static GLenum spinMode = GL_TRUE;
static int HourOfDay = 0, DayOfYear = 0;
static int AnimateIncrement = 24;
#define NUM_SLICES_STACKS 16
void KeyboardHandler(unsigned char key, int x, int y)
{
switch (key)
{
case ESCAPE_KEY:
case 'Q':
case 'q':
exit(0);
break;
case SPACE_KEY:
case 'A':
case 'a':
spinMode = !spinMode;
break;
case GLUT_KEY_UP:
case 'U':
case 'u':
if (AnimateIncrement == 0)
AnimateIncrement = 1;
else
AnimateIncrement *= 2;
break;
case GLUT_KEY_DOWN:
case 'D':
case 'd':
AnimateIncrement /= 2;
break;
}
glutPostRedisplay();
}
void SpecialKeyboardHandler(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_UP:
KeyboardHandler(GLUT_KEY_UP, x, y);
break;
case GLUT_KEY_DOWN:
KeyboardHandler(GLUT_KEY_DOWN, x, y);
break;
}
}
void Animate (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (spinMode) {
HourOfDay += AnimateIncrement;
DayOfYear += HourOfDay/24;
HourOfDay = HourOfDay%24;
DayOfYear = DayOfYear%365;
}
glLoadIdentity ();
glTranslatef (0.0f, 0.0f, -5.0f);
glRotatef (5.0f, 1.0f, 0.0f, 0.0f);
glColor3f (1.0, 0.75, 0.0);
glutWireSphere (1.0, NUM_SLICES_STACKS, NUM_SLICES_STACKS);
glRotatef ((GLfloat) (360.0*DayOfYear/365.0), 0.0, 1.0, 0.0);
glTranslatef (4.0, 0.0, 0.0);
glPushMatrix ();
glRotatef ((GLfloat) (360.0*HourOfDay/24.0), 0.0, 1.0, 0.0);
glColor3f (0.2, 0.2, 1.0);
glutWireSphere (0.2, NUM_SLICES_STACKS, NUM_SLICES_STACKS);
glPopMatrix ();
glRotatef ((GLfloat) (360.0*12.5*DayOfYear/365.0), 0.0, 1.0, 0.0);
glTranslatef (0.5, 0.0, 0.0);
glColor3f (0.3, 0.3, 0.3);
glutWireSphere (0.05, NUM_SLICES_STACKS, NUM_SLICES_STACKS);
glFlush ();
glutSwapBuffers ();
}
void OpenGLInit (void)
{
glShadeModel (GL_FLAT);
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth (1.0f);
glDepthFunc (GL_LEQUAL);
glEnable (GL_DEPTH_TEST);
}
void ResizeWindow (int w, int h)
{
h = (h == 0) ? 1 : h;
w = (w == 0) ? 1 : w;
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (45.0, (GLfloat) w / (GLfloat) h, 1.0f, 20.0f);
glMatrixMode (GL_MODELVIEW);
}
int main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(620, 160);
glutInitWindowPosition(100, 150);
glutCreateWindow("Solar System Example (GLUT)");
OpenGLInit ();
glutDisplayFunc(Animate);
glutIdleFunc(Animate);
glutReshapeFunc(ResizeWindow);
glutKeyboardFunc(KeyboardHandler);
glutSpecialFunc(SpecialKeyboardHandler);
glutMainLoop ();
return (0);
}