Merge branch 'mesa_7_5_branch'
[mesa.git] / progs / demos / pointblast.c
index 8786e36e3a1147ffba0046bc55a23b4d47105f7c..2d70b72589418fdd389642fc6ba8f4ecb7aadca7 100644 (file)
    is present , the particle size is attenuated based on eye distance. */
 
 
-/*
- * $Log: pointblast.c,v $
- * Revision 1.3  2002/01/16 00:48:43  kschultz
- * Demo updates for Windows (Robert Bergkvist)
- *
- * Revision 1.2  2000/06/27 17:04:43  brianp
- * fixed compiler warnings
- *
- * Revision 1.1.1.1  1999/08/19 00:55:40  jtg
- * Imported sources
- *
- * Revision 3.3  1998/07/26 01:24:27  brianp
- * removed include of gl.h
- *
- * Revision 3.2  1998/02/14 18:51:46  brianp
- * fixed a small compiler warning
- *
- * Revision 3.1  1998/02/14 18:45:25  brianp
- * optimized to use flat shading, don't blend ground polygon
- *
- * Revision 3.0  1998/02/14 18:42:29  brianp
- * initial rev
- *
- */
-
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -44,7 +18,7 @@
 #ifdef _WIN32
 #include <windows.h>
 #endif
-#define GL_GLEXT_LEGACY
+#include <GL/glew.h>
 #include <GL/glut.h>
 
 /* Some <math.h> files do not define M_PI... */
@@ -105,7 +79,6 @@ static float float_rand(void) { return rand() / (float) RAND_MAX; }
 
 #define MEAN_VELOCITY 3.0
 #define GRAVITY 2.0
-#define TIME_DELTA 0.025  /* The speed of time. */
 
 /* Modeling units of ground extent in each X and Z direction. */
 #define EDGE 12
@@ -140,6 +113,13 @@ updatePointList(void)
   float distance;
   int i;
 
+  static double t0 = -1.;
+  double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
+  if (t0 < 0.0)
+    t0 = t;
+  dt = t - t0;
+  t0 = t;
+
   motion = 0;
   for (i=0; i<numPoints; i++) {
     distance = pointVelocity[i][0] * theTime;
@@ -165,9 +145,9 @@ updatePointList(void)
       pointTime[i] = 0.0;  /* Reset the particles sense of up time. */
     }
     motion = 1;
-    pointTime[i] += TIME_DELTA;
+    pointTime[i] += dt;
   }
-  theTime += TIME_DELTA;
+  theTime += dt;
   if (!motion && !spin) {
     if (repeat) {
       makePointList();
@@ -214,11 +194,11 @@ redraw(void)
 {
   int i;
 
+  glDepthMask(GL_TRUE);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   if (newModel)
     recalcModelView();
 
-  glDepthMask(GL_FALSE);
 
   /* Draw the floor. */
 /*  glEnable(GL_TEXTURE_2D);*/
@@ -235,7 +215,7 @@ redraw(void)
   glEnd();
 
   /* Allow particles to blend with each other. */
-  glDepthMask(GL_TRUE);
+  glDepthMask(GL_FALSE);
 
   if (blend)
      glEnable(GL_BLEND);
@@ -290,15 +270,15 @@ menu(int option)
   case 0:
     makePointList();
     break;
-#if GL_EXT_point_parameters
+#ifdef GL_ARB_point_parameters
   case 1:
-    glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, constant);
+    glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, constant);
     break;
   case 2:
-    glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, linear);
+    glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, linear);
     break;
   case 3:
-    glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, theQuad);
+    glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad);
     break;
 #endif
   case 4:
@@ -307,12 +287,12 @@ menu(int option)
   case 5:
     blend = 0;
     break;
-#if GL_EXT_point_parameters
+#ifdef GL_ARB_point_parameters
   case 6:
-    glPointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT, 1.0);
+    glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1.0);
     break;
   case 7:
-    glPointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT, 10.0);
+    glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 10.0);
     break;
 #endif
   case 8:
@@ -449,6 +429,8 @@ main(int argc, char **argv)
   int i;
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
+  glutInitWindowPosition(0, 0);
+  glutInitWindowSize(300, 300);
 
   for (i=1; i<argc; i++) {
     if(!strcmp("-noms", argv[i])) {
@@ -462,6 +444,7 @@ main(int argc, char **argv)
   }
 
   glutCreateWindow("point burst");
+  glewInit();
   glutDisplayFunc(redraw);
   glutMouseFunc(mouse);
   glutMotionFunc(mouseMotion);
@@ -489,13 +472,18 @@ main(int argc, char **argv)
   glutAddMenuEntry("Quit", 666);
   glutAttachMenu(GLUT_RIGHT_BUTTON);
 
+  if (!glutExtensionSupported("GL_ARB_point_parameters")) {
+    fprintf(stderr, "Sorry, GL_ARB_point_parameters is not supported.\n");
+    return -1;
+  }
+
   glShadeModel(GL_FLAT);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_POINT_SMOOTH);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glPointSize(8.0);
-#if GL_EXT_point_parameters
-  glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, theQuad);
+#if GL_ARB_point_parameters
+  glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad);
 #endif
   glMatrixMode(GL_PROJECTION);
   gluPerspective( /* field of view in degree */ 40.0,