free display lists and destroy window upon exit
[mesa.git] / progs / demos / drawpix.c
index 222c8209c1c9e8175c4f1fafede892f94a5df5ae..82d32b0705c29b8a1204c81f7fe4d4bd06704ad9 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: drawpix.c,v 1.7 2002/04/22 16:03:37 brianp Exp $ */
 
 /*
  * glDrawPixels demo/test/benchmark
@@ -9,9 +8,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <string.h>
 #include <GL/glut.h>
 
-#include "readtex.c"
+#include "readtex.h"
 
 #define IMAGE_FILE "../images/girl.rgb"
 
@@ -242,22 +242,22 @@ static void SpecialKey( int key, int x, int y )
 }
 
 
-static void Init( GLboolean ciMode )
+static void Init( GLboolean ciMode, const char *filename )
 {
    static const GLfloat fogColor[4] = {0, 1, 0, 0};
 
    printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
    printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
 
-   Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
+   Image = LoadRGBImage( filename, &ImgWidth, &ImgHeight, &ImgFormat );
    if (!Image) {
-      printf("Couldn't read %s\n", IMAGE_FILE);
+      printf("Couldn't read %s\n", filename);
       exit(0);
    }
 
    if (ciMode) {
       /* Convert RGB image to grayscale */
-      GLubyte *indexImage = malloc( ImgWidth * ImgHeight );
+      GLubyte *indexImage = (GLubyte *) malloc( ImgWidth * ImgHeight );
       GLint i;
       for (i=0; i<ImgWidth*ImgHeight; i++) {
          int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2];
@@ -321,9 +321,15 @@ static void Usage(void)
 int main( int argc, char *argv[] )
 {
    GLboolean ciMode = GL_FALSE;
+   const char *filename = IMAGE_FILE;
+   int i = 1;
 
-   if (argc > 1 && strcmp(argv[1], "-ci")==0) {
+   if (argc > i && strcmp(argv[i], "-ci")==0) {
       ciMode = GL_TRUE;
+      i++;
+   }
+   if (argc > i) {
+      filename = argv[i];
    }
 
    glutInit( &argc, argv );
@@ -337,7 +343,7 @@ int main( int argc, char *argv[] )
 
    glutCreateWindow(argv[0]);
 
-   Init(ciMode);
+   Init(ciMode, filename);
    Usage();
 
    glutReshapeFunc( Reshape );