-/* $Id: texcyl.c,v 1.2 1999/10/21 16:39:06 brianp Exp $ */
/*
* Textured cylinder demo: lighting, texturing, reflection mapping.
* Brian Paul May 1997 This program is in the public domain.
*/
-/*
- * $Log: texcyl.c,v $
- * Revision 1.2 1999/10/21 16:39:06 brianp
- * added -info command line option
- *
- * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
- * Imported sources
- *
- * Revision 3.3 1999/03/28 18:24:37 brianp
- * minor clean-up
- *
- * Revision 3.2 1998/11/05 04:34:04 brianp
- * moved image files to ../images/ directory
- *
- * Revision 3.1 1998/06/23 03:16:51 brianp
- * added Point/Linear sampling menu items
- *
- * Revision 3.0 1998/02/14 18:42:29 brianp
- * initial rev
- *
- */
-
-
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
+#include <string.h>
#include <GL/glut.h>
-#include "../util/readtex.c" /* I know, this is a hack. */
+#include "readtex.h"
#define TEXTURE_FILE "../images/reflect.rgb"
static GLboolean Animate = GL_TRUE;
static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0;
-static GLfloat DXrot = 1.0, DYrot = 2.5;
+static GLfloat DXrot = 50.0, DYrot = 125.0;
+
+/* performance info */
+static GLint T0 = 0;
+static GLint Frames = 0;
static void Idle( void )
{
+ static double t0 = -1.;
+ double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
+ if (t0 < 0.0)
+ t0 = t;
+ dt = t - t0;
+ t0 = t;
+
if (Animate) {
- Xrot += DXrot;
- Yrot += DYrot;
+ Xrot += DXrot * dt;
+ Yrot += DYrot * dt;
glutPostRedisplay();
}
}
glPopMatrix();
glutSwapBuffers();
+
+ if (Animate) {
+ GLint t = glutGet(GLUT_ELAPSED_TIME);
+ Frames++;
+ if (t - T0 >= 5000) {
+ GLfloat seconds = (t - T0) / 1000.0;
+ GLfloat fps = Frames / seconds;
+ printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
+ T0 = t;
+ Frames = 0;
+ }
+ }
}
{
if (entry==ANIMATE) {
Animate = !Animate;
+ if (Animate)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
}
else if (entry==POINT_FILTER) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
(void) x;
(void) y;
switch (key) {
+ case ' ':
+ Animate = !Animate;
+ if (Animate)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
+ break;
case 27:
exit(0);
break;
{
glutInit( &argc, argv );
glutInitWindowSize( 400, 400 );
+ glutInitWindowPosition( 0, 0 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );