*/
#include <GL/freeglut.h>
+#include <GL/freeglut_ext.h>
#include <stdarg.h>
#include <stdio.h>
static GLboolean show_info = GL_TRUE;
static float ar;
static GLboolean persProject = GL_TRUE;
+static GLboolean animateXRot = GL_FALSE;
/*
* These one-liners draw particular objects, fetching appropriate
static void drawWireIcosahedron(void) { glutWireIcosahedron (); }
static void drawSolidSierpinskiSponge(void) { glutSolidSierpinskiSponge (depth, offset, orad);} /* orad doubles as size input */
static void drawWireSierpinskiSponge(void) { glutWireSierpinskiSponge (depth, offset, orad); } /* orad doubles as size input */
-static void drawSolidSphere(void) { glutSolidSphere(orad,slices,stacks); } /* orad doubles as size input */
-static void drawWireSphere(void) { glutWireSphere(orad,slices,stacks); } /* orad doubles as size input */
-#ifndef EGL_VERSION_1_0
static void drawSolidTorus(void) { glutSolidTorus(irad,orad,slices,stacks); }
static void drawWireTorus(void) { glutWireTorus (irad,orad,slices,stacks); }
+static void drawSolidSphere(void) { glutSolidSphere(orad,slices,stacks); } /* orad doubles as size input */
+static void drawWireSphere(void) { glutWireSphere(orad,slices,stacks); } /* orad doubles as size input */
static void drawSolidCone(void) { glutSolidCone(orad,orad,slices,stacks); } /* orad doubles as size input */
static void drawWireCone(void) { glutWireCone(orad,orad,slices,stacks); } /* orad doubles as size input */
static void drawSolidCylinder(void) { glutSolidCylinder(orad,orad,slices,stacks); } /* orad doubles as size input */
static void drawWireCylinder(void) { glutWireCylinder(orad,orad,slices,stacks); } /* orad doubles as size input */
-#endif
+static void drawSolidTeapot(void)
+{ glFrontFace(GL_CW); glutSolidTeapot(orad); glFrontFace(GL_CCW); /* orad doubles as size input */}
+static void drawWireTeapot(void)
+{ glFrontFace(GL_CW); glutWireTeapot(orad); glFrontFace(GL_CCW); /* orad doubles as size input */}
/*
* This structure defines an entry in our function-table.
#define ENTRY(e) {#e, drawSolid##e, drawWire##e}
static const entry table [] =
{
- ENTRY (Cube),
ENTRY (Tetrahedron),
+ ENTRY (Cube),
ENTRY (Octahedron),
ENTRY (Dodecahedron),
ENTRY (RhombicDodecahedron),
ENTRY (Icosahedron),
ENTRY (SierpinskiSponge),
+ ENTRY (Teapot),
+ ENTRY (Torus),
ENTRY (Sphere),
+ ENTRY (Cone),
+ ENTRY (Cylinder),
+ /* ENTRY (Cuboctahedron) */
};
#undef ENTRY
{
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = t*90.0;
+ const double b = (animateXRot?t:1)*60.0;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glPushMatrix();
glTranslated(0,1.2,-6);
- glRotated(60,1,0,0);
+ glRotated(b,1,0,0);
glRotated(a,0,0,1);
table [function_index].solid ();
glPopMatrix();
glPushMatrix();
glTranslated(0,-1.2,-6);
- glRotated(60,1,0,0);
+ glRotated(b,1,0,0);
glRotated(a,0,0,1);
table [function_index].wire ();
glPopMatrix();
case 'P':
case 'p': persProject=!persProject; break;
+ case 'R':
+ case 'r': animateXRot=!animateXRot; break;
+
default:
break;
}
static void
onMouseClick(int button, int state, int x, int y) {
if (state == GLUT_DOWN)
- special(GLUT_KEY_PAGE_DOWN, 0, 0);
+ special(GLUT_KEY_PAGE_UP, 0, 0);
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
/* Program entry point */
-int
-main(int argc, char *argv[])
-{
- glutInitWindowSize(640,480);
- glutInitWindowPosition(40,40);
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
-
- glutCreateWindow("FreeGLUT Shapes");
-
- glutReshapeFunc(resize);
- glutDisplayFunc(display);
- glutKeyboardFunc(key);
- glutSpecialFunc(special);
- glutIdleFunc(idle);
- glutMouseFunc(onMouseClick);
-
- glutSetOption ( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION ) ;
-
+void init_context() {
+ printf("init_context\n"); fflush(stdout);
glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
+}
+
+int
+main(int argc, char *argv[])
+{
+ glutInitWindowSize(640,480);
+ glutInitWindowPosition(40,40);
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
+
+ glutCreateWindow("FreeGLUT Shapes");
+
+ glutReshapeFunc(resize);
+ glutDisplayFunc(display);
+ glutKeyboardFunc(key);
+ glutSpecialFunc(special);
+ glutIdleFunc(idle);
+ glutMouseFunc(onMouseClick);
+ glutInitContextFunc(init_context);
+
+ glutSetOption ( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION ) ;
glutMainLoop();