1 /* $Id: trispd.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
4 * Simple GLUT program to measure triangle strip rendering speed.
5 * Brian Paul February 15, 1997 This file is in the public domain.
10 * Revision 1.1 1999/08/19 00:55:40 jtg
13 * Revision 3.4 1999/03/28 18:24:37 brianp
16 * Revision 3.3 1999/03/18 08:16:52 joukj
18 * cmpstr needs string.h to included to avoid warnings
20 * Revision 3.2 1998/07/08 03:02:00 brianp
21 * added Marten Stromberg's texture options
23 * Revision 3.1 1998/06/29 02:36:58 brianp
24 * removed unneeded includes
26 * Revision 3.0 1998/02/14 18:42:29 brianp
39 static float MinPeriod
= 2.0; /* 2 seconds */
40 static float Width
= 400.0;
41 static float Height
= 400.0;
44 static int Texture
= 0;
48 static void Idle( void )
54 static void Display( void )
64 float red
[3] = { 1.0, 0.0, 0.0 };
65 float blue
[3] = { 0.0, 0.0, 1.0 };
67 xStep
= yStep
= sqrt( 2.0 * Size
);
69 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
72 t0
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
74 float uStep
= xStep
/ Width
;
75 float vStep
= yStep
/ Height
;
77 for (i
=0; i
<Loops
; i
++) {
78 for (y
=1.0, v
=0.0f
; y
<Height
-yStep
; y
+=yStep
, v
+=vStep
) {
79 glBegin(GL_TRIANGLE_STRIP
);
80 for (x
=1.0, u
=0.0f
; x
<Width
; x
+=xStep
, u
+=uStep
) {
85 glTexCoord2f(u
, v
+vStep
);
86 glVertex2f(x
, y
+yStep
);
95 for (i
=0; i
<Loops
; i
++) {
96 for (y
=1.0; y
<Height
-yStep
; y
+=yStep
) {
97 glBegin(GL_TRIANGLE_STRIP
);
98 for (x
=1.0; x
<Width
; x
+=xStep
) {
102 glVertex2f(x
, y
+yStep
);
110 t1
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
112 if (t1
-t0
< MinPeriod
) {
113 /* Next time draw more triangles to get longer elapsed time */
118 triRate
= triCount
/ (t1
-t0
);
119 pixelRate
= triRate
* Size
;
120 printf("Rate: %d tri in %gs = %g tri/s %d pixels/s\n",
121 triCount
, t1
-t0
, triRate
, (int)pixelRate
);
127 static void Reshape( int width
, int height
)
131 glViewport( 0, 0, width
, height
);
132 glMatrixMode( GL_PROJECTION
);
134 glOrtho(0.0, width
, 0.0, height
, -1.0, 1.0);
135 glMatrixMode( GL_MODELVIEW
);
140 static void Key( unsigned char key
, int x
, int y
)
153 static void LoadTex(int comp
, int filter
)
157 pixels
= malloc(4*256*256);
158 for (y
= 0; y
< 256; ++y
)
159 for (x
= 0; x
< 256; ++x
) {
160 pixels
[(y
*256+x
)*4+0] = (int)(128.5 + 127.0 * cos(0.024544 * x
));
161 pixels
[(y
*256+x
)*4+1] = 255;
162 pixels
[(y
*256+x
)*4+2] = (int)(128.5 + 127.0 * cos(0.024544 * y
));
163 pixels
[(y
*256+x
)*4+3] = 255;
165 glEnable(GL_TEXTURE_2D
);
166 glTexImage2D(GL_TEXTURE_2D
, 0, comp
, 256, 256, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, pixels
);
167 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, filter
);
168 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, filter
);
169 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
170 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
171 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
172 printf("Texture: GL_MODULATE, %d comps, %s\n", comp
, filter
== GL_NEAREST
? "GL_NEAREST" : "GL_LINEAR");
176 static void Init( int argc
, char *argv
[] )
179 GLint rBits
, gBits
, bBits
;
180 int filter
= GL_NEAREST
, comp
= 3;
183 for (i
=1; i
<argc
; i
++) {
184 if (strcmp(argv
[i
],"-dither")==0)
185 glDisable(GL_DITHER
);
186 else if (strcmp(argv
[i
],"+dither")==0)
188 else if (strcmp(argv
[i
],"+smooth")==0)
189 glShadeModel(GL_SMOOTH
);
190 else if (strcmp(argv
[i
],"+flat")==0)
191 glShadeModel(GL_FLAT
);
192 else if (strcmp(argv
[i
],"+depth")==0)
193 glEnable(GL_DEPTH_TEST
);
194 else if (strcmp(argv
[i
],"-depth")==0)
195 glDisable(GL_DEPTH_TEST
);
196 else if (strcmp(argv
[i
],"-size")==0) {
197 Size
= atoi(argv
[i
+1]);
200 else if (strcmp(argv
[i
],"-texture")==0)
202 else if (strcmp(argv
[i
],"+texture")==0)
204 else if (strcmp(argv
[i
],"-linear")==0)
206 else if (strcmp(argv
[i
],"+linear")==0)
208 else if (strcmp(argv
[i
],"-persp")==0)
209 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_FASTEST
);
210 else if (strcmp(argv
[i
],"+persp")==0)
211 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_NICEST
);
212 else if (strcmp(argv
[i
],"-comp")==0) {
213 comp
= atoi(argv
[i
+1]);
217 printf("Unknown option: %s\n", argv
[i
]);
220 glGetIntegerv(GL_SHADE_MODEL
, &shade
);
222 printf("Dither: %s\n", glIsEnabled(GL_DITHER
) ? "on" : "off");
223 printf("ShadeModel: %s\n", (shade
==GL_FLAT
) ? "flat" : "smooth");
224 printf("DepthTest: %s\n", glIsEnabled(GL_DEPTH_TEST
) ? "on" : "off");
225 printf("Size: %d pixels\n", Size
);
228 LoadTex(comp
, filter
);
230 glGetIntegerv(GL_RED_BITS
, &rBits
);
231 glGetIntegerv(GL_GREEN_BITS
, &gBits
);
232 glGetIntegerv(GL_BLUE_BITS
, &bBits
);
233 printf("RedBits: %d GreenBits: %d BlueBits: %d\n", rBits
, gBits
, bBits
);
237 static void Help( const char *program
)
239 printf("%s options:\n", program
);
240 printf(" +/-dither enable/disable dithering\n");
241 printf(" +/-depth enable/disable depth test\n");
242 printf(" +flat flat shading\n");
243 printf(" +smooth smooth shading\n");
244 printf(" -size pixels specify pixels/triangle\n");
245 printf(" +/-texture enable/disable texture\n");
246 printf(" -comp n texture format\n");
247 printf(" +/-linear bilinear texture filter\n");
248 printf(" +/-persp perspective correction hint\n");
252 int main( int argc
, char *argv
[] )
254 printf("For options: %s -help\n", argv
[0]);
255 glutInit( &argc
, argv
);
256 glutInitWindowSize( (int) Width
, (int) Height
);
257 glutInitWindowPosition( 0, 0 );
259 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
261 glutCreateWindow( argv
[0] );
263 if (argc
==2 && strcmp(argv
[1],"-help")==0) {
270 glutReshapeFunc( Reshape
);
271 glutKeyboardFunc( Key
);
272 glutDisplayFunc( Display
);
273 glutIdleFunc( Idle
);