home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OpenGL Superbible
/
OpenGL_Superbible_Waite_Group_Press_1996.iso
/
book
/
chapt3
/
auxsolid
/
auxsolid.c
next >
Wrap
C/C++ Source or Header
|
1996-03-08
|
3KB
|
151 lines
// AuxSolid.c
// OpenGL AUX library predefined objects
// Draws solid objects.
#include <windows.h> // Standard Windows header file
#include <gl\gl.h> // OpenGL header
#include <gl\glaux.h> // AUX library header
#include <conio.h> // Console I/O functions
// Selected object
static char cSelection = ' ';
// The window has changed size
void CALLBACK ChangeSize(GLsizei w, GLsizei h)
{
// Prevent a divide by zero
if(h == 0)
h = 1;
// Set viewport and clipping volume
glViewport(0, 0, w, h);
glLoadIdentity();
if (w <= h)
glOrtho (-100.0f, 100.0f, -100.0f, 100.0f*h/w, -100.0, 100.0);
else
glOrtho (-100.0f, 100*w/h, -100.0f, 100.0f, -100.0, 100.00);
}
// Called by AUX library to draw the scene
void CALLBACK RenderScene(void)
{
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT);
// Rotate one degree around each axis
// (Note we don't call LoadIdentity() so
// this rotation is cumulative
glRotatef(1.0f,1.0f,0.0f,0.0f);
glRotatef(1.0f,0.0f,1.0f,0.0f);
glRotatef(1.0f,0.0f,0.0f,1.0f);
// Draw the selected object
switch(cSelection)
{
case 'a':
auxSolidCone(30.0f,75.0f);
break;
case 'b':
auxSolidCylinder(30.0f, 75.0f);
break;
case 'c':
auxSolidDodecahedron(75.0f);
break;
case 'd':
auxSolidIcosahedron(75.0f);
break;
case 'e':
auxSolidOctahedron(75.0f);
break;
case 'f':
auxSolidSphere(75.0f);
break;
case 'g':
auxSolidTeapot(50.0f);
break;
case 'h':
auxSolidTetrahedron(75.0f);
break;
case 'i':
auxSolidTorus(20.0f, 50.0f);
break;
case 'j':
auxSolidCube(75.0f);
break;
case 'k':
auxSolidBox(75.0f,75.0f,75.0f);
break;
default:
break;
}
glFlush();
// Swap drawing to screen
auxSwapBuffers();
}
// Main program body
void main(void)
{
// Display a menu of objects to draw
cprintf("Select Solid object to draw:\n\n");
cprintf("a - Cone\n");
cprintf("b - Cylinder\n");
cprintf("c - Dodecahedron\n");
cprintf("d - Icosahedron\n");
cprintf("e - Octahedron\n");
cprintf("f - Sphere\n");
cprintf("g - Teapot\n");
cprintf("h - Tetrahedron\n");
cprintf("i - Torus\n");
cprintf("j - Cube\n");
cprintf("k - Box\n");
// Validate and accept selection
while(cSelection < 'a' || cSelection > 'k')
{
cprintf("\nSelection: ");
cSelection = getche();
}
// Setup the AUX library window for double buffer
auxInitDisplayMode(AUX_DOUBLE | AUX_RGBA);
auxInitPosition(100,100,250,250);
auxInitWindow("3D Aux library objects");
// Set background to blue
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
// Set drawing color to Red
glColor3f(1.0f, 0.0f, 0.0f);
// Establish window resize function
auxReshapeFunc(ChangeSize);
// Establish idle function
auxIdleFunc(RenderScene);
// Start main loop
auxMainLoop(RenderScene);
}