Mesa (master): demos/readpix: add option to draw triangle instead of drawpix

Keith Whitwell keithw at kemper.freedesktop.org
Fri Apr 24 09:09:35 UTC 2009


Module: Mesa
Branch: master
Commit: eb5d96968fd37b4598a7b50df1a8f4f7805d897d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=eb5d96968fd37b4598a7b50df1a8f4f7805d897d

Author: Keith Whitwell <keithw at vmware.com>
Date:   Wed Apr 22 15:19:44 2009 +0100

demos/readpix:  add option to draw triangle instead of drawpix

---

 progs/demos/readpix.c |   67 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/progs/demos/readpix.c b/progs/demos/readpix.c
index c0aac22..bbb3a68 100644
--- a/progs/demos/readpix.c
+++ b/progs/demos/readpix.c
@@ -17,6 +17,7 @@
 #define IMAGE_FILE "../images/girl.rgb"
 
 static int ImgWidth, ImgHeight;
+static int WinWidth, WinHeight;
 static GLenum ImgFormat;
 static GLubyte *Image = NULL;
 
@@ -27,6 +28,7 @@ static int CPosX, CPosY;  /* copypixels */
 static GLboolean DrawFront = GL_FALSE;
 static GLboolean ScaleAndBias = GL_FALSE;
 static GLboolean Benchmark = GL_FALSE;
+static GLboolean Triangle = GL_FALSE;
 static GLubyte *TempImage = NULL;
 
 #define COMBO 1
@@ -150,11 +152,60 @@ Display( void )
    /* draw original image */
    glRasterPos2i(APosX, 5);
    PrintString("Original");
-   glRasterPos2i(APosX, APosY);
-   glEnable(GL_DITHER);
-   SetupPixelTransfer(GL_FALSE);
-   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-   glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);
+   if (!Triangle) {
+      glRasterPos2i(APosX, APosY);
+      glEnable(GL_DITHER);
+      SetupPixelTransfer(GL_FALSE);
+      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+      glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);
+   }
+   else {
+      float z = 0;
+
+      glViewport(APosX, APosY, ImgWidth, ImgHeight);
+      glMatrixMode( GL_PROJECTION );
+      glLoadIdentity();
+      glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
+      glDisable(GL_CULL_FACE);
+
+      /* Red should never be seen
+       */
+      glBegin(GL_POLYGON);
+      glColor3f(1,0,0); 
+      glVertex3f(-2, -2, z);
+      glVertex3f(-2, 2, z);
+      glVertex3f(2, 2, z);
+      glVertex3f(2, -2, z);
+      glEnd();
+
+      /* Blue background
+       */
+      glBegin(GL_POLYGON);
+      glColor3f(.5,.5,1); 
+      glVertex3f(-1, -1, z);
+      glVertex3f(-1, 1, z);
+      glVertex3f(1, 1, z);
+      glVertex3f(1, -1, z);
+      glEnd();
+
+      /* Triangle
+       */
+      glBegin(GL_TRIANGLES);
+      glColor3f(.8,0,0); 
+      glVertex3f(-0.9, -0.9, z);
+      glColor3f(0,.9,0); 
+      glVertex3f( 0.9, -0.9, z);
+      glColor3f(0,0,.7); 
+      glVertex3f( 0.0,  0.9, z);
+      glEnd();
+      
+      glColor3f(1,1,1);
+
+      glViewport( 0, 0, WinWidth, WinHeight );
+      glMatrixMode( GL_PROJECTION );
+      glLoadIdentity();
+      glOrtho( 0.0, WinWidth, 0.0, WinHeight, -1.0, 1.0 );
+   }
 
    /* might try alignment=4 here for testing */
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -218,6 +269,9 @@ Display( void )
 static void
 Reshape( int width, int height )
 {
+   WinWidth = width;
+   WinHeight = height;
+
    glViewport( 0, 0, width, height );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
@@ -236,6 +290,9 @@ Key( unsigned char key, int x, int y )
       case 'b':
          Benchmark = GL_TRUE;
          break;
+      case 't':
+         Triangle = !Triangle;
+         break;
       case 's':
          ScaleAndBias = !ScaleAndBias;
          break;




More information about the mesa-commit mailing list