X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=progs%2Fdemos%2Fdrawpix.c;h=9bc7086e04b4cfcdb4bd051200ffaba073c9ebab;hb=6ef1d6040738f5a3d93644a782ee7b600b8420b6;hp=7c858da697b1fba1b43038f72235e4f4b983d936;hpb=d13c0a90c7b57d8e29b9105290bc05f21f2c97d8;p=mesa.git diff --git a/progs/demos/drawpix.c b/progs/demos/drawpix.c index 7c858da697b..9bc7086e04b 100644 --- a/progs/demos/drawpix.c +++ b/progs/demos/drawpix.c @@ -1,4 +1,3 @@ -/* $Id: drawpix.c,v 1.2 1999/10/21 22:13:58 brianp Exp $ */ /* * glDrawPixels demo/test/benchmark @@ -6,35 +5,13 @@ * Brian Paul September 25, 1997 This file is in the public domain. */ -/* - * $Log: drawpix.c,v $ - * Revision 1.2 1999/10/21 22:13:58 brianp - * added f key to toggle front/back drawing - * - * Revision 1.1.1.1 1999/08/19 00:55:40 jtg - * Imported sources - * - * Revision 3.3 1999/03/28 18:18:33 brianp - * minor clean-up - * - * Revision 3.2 1998/11/05 04:34:04 brianp - * moved image files to ../images/ directory - * - * Revision 3.1 1998/02/22 16:43:17 brianp - * added a few casts to silence compiler warnings - * - * Revision 3.0 1998/02/14 18:42:29 brianp - * initial rev - * - */ - - #include #include #include +#include #include -#include "../util/readtex.c" /* a hack, I know */ +#include "readtex.h" #define IMAGE_FILE "../images/girl.rgb" @@ -46,9 +23,12 @@ static int Xpos, Ypos; static int SkipPixels, SkipRows; static int DrawWidth, DrawHeight; static int Scissor = 0; +static int Fog = 0; +static GLfloat Zpos = -1.0; static float Xzoom, Yzoom; static GLboolean DrawFront = GL_FALSE; - +static GLboolean Dither = GL_TRUE; +static int win = 0; static void Reset( void ) @@ -58,6 +38,8 @@ static void Reset( void ) DrawHeight = ImgHeight; SkipPixels = SkipRows = 0; Scissor = 0; + Fog = 0; + Zpos = -1.0; Xzoom = Yzoom = 1.0; } @@ -70,7 +52,7 @@ static void Display( void ) glRasterPos2i(Xpos, Ypos); #else /* This allows negative raster positions: */ - glRasterPos2i(0, 0); + glRasterPos3f(0, 0, Zpos); glBitmap(0, 0, 0, 0, Xpos, Ypos, NULL); #endif @@ -82,11 +64,17 @@ static void Display( void ) if (Scissor) glEnable(GL_SCISSOR_TEST); + if (Fog) + glEnable(GL_FOG); + glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); glDisable(GL_SCISSOR_TEST); + glDisable(GL_FOG); - if (!DrawFront) + if (DrawFront) + glFinish(); + else glutSwapBuffers(); } @@ -104,6 +92,8 @@ static void Benchmark( void ) glPixelZoom( Xzoom, Yzoom ); if (Scissor) glEnable(GL_SCISSOR_TEST); + if (Fog) + glEnable(GL_FOG); if (DrawFront) glDrawBuffer(GL_FRONT); @@ -121,6 +111,7 @@ static void Benchmark( void ) /* GL clean-up */ glDisable(GL_SCISSOR_TEST); + glDisable(GL_FOG); /* Results */ seconds = (double) (endTime - startTime) / 1000.0; @@ -135,7 +126,7 @@ static void Reshape( int width, int height ) glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); - glOrtho( 0.0, width, 0.0, height, -1.0, 1.0 ); + glOrtho( 0.0, width, 0.0, height, 0.0, 2.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); @@ -151,6 +142,13 @@ static void Key( unsigned char key, int x, int y ) case ' ': Reset(); break; + case 'd': + Dither = !Dither; + if (Dither) + glEnable(GL_DITHER); + else + glDisable(GL_DITHER); + break; case 'w': if (DrawWidth > 0) DrawWidth--; @@ -194,9 +192,21 @@ static void Key( unsigned char key, int x, int y ) case 'Y': Yzoom += 0.1; break; + case 'z': + Zpos -= 0.1; + printf("RasterPos Z = %g\n", Zpos); + break; + case 'Z': + Zpos += 0.1; + printf("RasterPos Z = %g\n", Zpos); + break; case 'b': Benchmark(); break; + case 'F': + Fog = !Fog; + printf("Fog %d\n", Fog); + break; case 'f': DrawFront = !DrawFront; if (DrawFront) @@ -206,6 +216,7 @@ static void Key( unsigned char key, int x, int y ) printf("glDrawBuffer(%s)\n", DrawFront ? "GL_FRONT" : "GL_BACK"); break; case 27: + glutDestroyWindow(win); exit(0); break; } @@ -235,20 +246,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 1 && strcmp(argv[1], "-ci")==0) { + glutInitWindowSize( 500, 400 ); + glutInit( &argc, argv ); + + if (argc > i && strcmp(argv[i], "-ci")==0) { ciMode = GL_TRUE; + i++; + } + if (argc > i) { + filename = argv[i]; } - - glutInit( &argc, argv ); - glutInitWindowPosition( 0, 0 ); - glutInitWindowSize( 500, 400 ); if (ciMode) glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE ); else - glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE); - glutCreateWindow(argv[0]); + win = glutCreateWindow(argv[0]); - Init(ciMode); + Init(ciMode, filename); Usage(); glutReshapeFunc( Reshape );