3
* glDrawPixels demo/test/benchmark
5
* Brian Paul September 25, 1997 This file is in the public domain.
16
#define IMAGE_FILE "../images/girl.rgb"
18
static int ImgWidth, ImgHeight;
19
static GLenum ImgFormat;
20
static GLubyte *Image = NULL;
22
static int Xpos, Ypos;
23
static int SkipPixels, SkipRows;
24
static int DrawWidth, DrawHeight;
25
static int Scissor = 0;
27
static GLfloat Zpos = -1.0;
28
static float Xzoom, Yzoom;
29
static GLboolean DrawFront = GL_FALSE;
30
static GLboolean Dither = GL_TRUE;
33
static void Reset( void )
37
DrawHeight = ImgHeight;
38
SkipPixels = SkipRows = 0;
46
static void Display( void )
48
glClear( GL_COLOR_BUFFER_BIT );
51
glRasterPos2i(Xpos, Ypos);
53
/* This allows negative raster positions: */
54
glRasterPos3f(0, 0, Zpos);
55
glBitmap(0, 0, 0, 0, Xpos, Ypos, NULL);
58
glPixelStorei(GL_UNPACK_SKIP_PIXELS, SkipPixels);
59
glPixelStorei(GL_UNPACK_SKIP_ROWS, SkipRows);
61
glPixelZoom( Xzoom, Yzoom );
64
glEnable(GL_SCISSOR_TEST);
69
glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);
71
glDisable(GL_SCISSOR_TEST);
81
static void Benchmark( void )
83
int startTime, endTime;
85
double seconds, pixelsPerSecond;
87
printf("Benchmarking...\n");
89
glPixelStorei(GL_UNPACK_SKIP_PIXELS, SkipPixels);
90
glPixelStorei(GL_UNPACK_SKIP_ROWS, SkipRows);
91
glPixelZoom( Xzoom, Yzoom );
93
glEnable(GL_SCISSOR_TEST);
98
glDrawBuffer(GL_FRONT);
100
glDrawBuffer(GL_BACK);
102
/* Run timing test */
104
startTime = glutGet(GLUT_ELAPSED_TIME);
106
glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);
108
endTime = glutGet(GLUT_ELAPSED_TIME);
109
} while (endTime - startTime < 4000); /* 4 seconds */
112
glDisable(GL_SCISSOR_TEST);
116
seconds = (double) (endTime - startTime) / 1000.0;
117
pixelsPerSecond = draws * DrawWidth * DrawHeight / seconds;
118
printf("Result: %d draws in %f seconds = %f pixels/sec\n",
119
draws, seconds, pixelsPerSecond);
123
static void Reshape( int width, int height )
125
glViewport( 0, 0, width, height );
126
glMatrixMode( GL_PROJECTION );
128
glOrtho( 0.0, width, 0.0, height, 0.0, 2.0 );
129
glMatrixMode( GL_MODELVIEW );
132
glScissor(width/4, height/4, width/2, height/2);
136
static void Key( unsigned char key, int x, int y )
149
glDisable(GL_DITHER);
196
printf("RasterPos Z = %g\n", Zpos);
200
printf("RasterPos Z = %g\n", Zpos);
207
printf("Fog %d\n", Fog);
210
DrawFront = !DrawFront;
212
glDrawBuffer(GL_FRONT);
214
glDrawBuffer(GL_BACK);
215
printf("glDrawBuffer(%s)\n", DrawFront ? "GL_FRONT" : "GL_BACK");
225
static void SpecialKey( int key, int x, int y )
247
static void Init( GLboolean ciMode, const char *filename )
249
static const GLfloat fogColor[4] = {0, 1, 0, 0};
251
printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
252
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
254
Image = LoadRGBImage( filename, &ImgWidth, &ImgHeight, &ImgFormat );
256
printf("Couldn't read %s\n", filename);
261
/* Convert RGB image to grayscale */
262
GLubyte *indexImage = (GLubyte *) malloc( ImgWidth * ImgHeight );
264
for (i=0; i<ImgWidth*ImgHeight; i++) {
265
int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2];
266
indexImage[i] = gray / 3;
270
ImgFormat = GL_COLOR_INDEX;
272
for (i=0;i<255;i++) {
274
glutSetColor(i, g, g, g);
278
printf("Loaded %d by %d image\n", ImgWidth, ImgHeight );
280
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
281
glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth);
283
glFogi(GL_FOG_MODE, GL_LINEAR);
284
glFogf(GL_FOG_START, 0);
285
glFogf(GL_FOG_END, 2);
286
glFogfv(GL_FOG_COLOR, fogColor);
292
static void Usage(void)
295
printf(" SPACE Reset Parameters\n");
296
printf(" Up/Down Move image up/down\n");
297
printf(" Left/Right Move image left/right\n");
298
printf(" x Decrease X-axis PixelZoom\n");
299
printf(" X Increase X-axis PixelZoom\n");
300
printf(" y Decrease Y-axis PixelZoom\n");
301
printf(" Y Increase Y-axis PixelZoom\n");
302
printf(" w Decrease glDrawPixels width*\n");
303
printf(" W Increase glDrawPixels width*\n");
304
printf(" h Decrease glDrawPixels height*\n");
305
printf(" H Increase glDrawPixels height*\n");
306
printf(" p Decrease GL_UNPACK_SKIP_PIXELS*\n");
307
printf(" P Increase GL_UNPACK_SKIP_PIXELS*\n");
308
printf(" r Decrease GL_UNPACK_SKIP_ROWS*\n");
309
printf(" R Increase GL_UNPACK_SKIP_ROWS*\n");
310
printf(" s Toggle GL_SCISSOR_TEST\n");
311
printf(" F Toggle GL_FOG\n");
312
printf(" z Decrease RasterPos Z\n");
313
printf(" Z Increase RasterPos Z\n");
315
printf(" f Toggle front/back buffer drawing\n");
316
printf(" b Benchmark test\n");
317
printf(" ESC Exit\n");
318
printf("* Warning: no limits are imposed on these parameters so it's\n");
319
printf(" possible to cause a segfault if you go too far.\n");
323
int main( int argc, char *argv[] )
325
GLboolean ciMode = GL_FALSE;
326
const char *filename = IMAGE_FILE;
329
if (argc > i && strcmp(argv[i], "-ci")==0) {
337
glutInit( &argc, argv );
338
glutInitWindowPosition( 0, 0 );
339
glutInitWindowSize( 500, 400 );
342
glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE );
344
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE);
346
glutCreateWindow(argv[0]);
348
Init(ciMode, filename);
351
glutReshapeFunc( Reshape );
352
glutKeyboardFunc( Key );
353
glutSpecialFunc( SpecialKey );
354
glutDisplayFunc( Display );