132001f49Smrg/*
232001f49Smrg * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
332001f49Smrg *
432001f49Smrg * Permission is hereby granted, free of charge, to any person obtaining a
532001f49Smrg * copy of this software and associated documentation files (the "Software"),
632001f49Smrg * to deal in the Software without restriction, including without limitation
732001f49Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
832001f49Smrg * and/or sell copies of the Software, and to permit persons to whom the
932001f49Smrg * Software is furnished to do so, subject to the following conditions:
1032001f49Smrg *
1132001f49Smrg * The above copyright notice and this permission notice shall be included
1232001f49Smrg * in all copies or substantial portions of the Software.
1332001f49Smrg *
1432001f49Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1532001f49Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1632001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1732001f49Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1832001f49Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1932001f49Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2032001f49Smrg */
2132001f49Smrg
2232001f49Smrg/*
2332001f49Smrg * This is a port of the infamous "glxgears" demo to straight EGL
2432001f49Smrg * Port by Dane Rushton 10 July 2005
2532001f49Smrg *
2632001f49Smrg * No command line options.
2732001f49Smrg * Program runs for 5 seconds then exits, outputing framerate to console
2832001f49Smrg */
2932001f49Smrg
3032001f49Smrg#define EGL_EGLEXT_PROTOTYPES
3132001f49Smrg
3232001f49Smrg#include <assert.h>
3332001f49Smrg#include <math.h>
3432001f49Smrg#include <stdlib.h>
3532001f49Smrg#include <stdio.h>
3632001f49Smrg#include <string.h>
3732001f49Smrg#include "gl_wrap.h"
3832001f49Smrg#include <EGL/egl.h>
3932001f49Smrg#include <EGL/eglext.h>
4032001f49Smrg
4132001f49Smrg#define MAX_CONFIGS 10
4232001f49Smrg#define MAX_MODES 100
4332001f49Smrg
4432001f49Smrg#define BENCHMARK
4532001f49Smrg
4632001f49Smrg#ifdef BENCHMARK
4732001f49Smrg
4832001f49Smrg/* XXX this probably isn't very portable */
4932001f49Smrg
5032001f49Smrg#include <sys/time.h>
5132001f49Smrg#include <unistd.h>
5232001f49Smrg
5332001f49Smrg/* return current time (in seconds) */
5432001f49Smrgstatic double
5532001f49Smrgcurrent_time(void)
5632001f49Smrg{
5732001f49Smrg   struct timeval tv;
5832001f49Smrg#ifdef __VMS
5932001f49Smrg   (void) gettimeofday(&tv, NULL );
6032001f49Smrg#else
6132001f49Smrg   struct timezone tz;
6232001f49Smrg   (void) gettimeofday(&tv, &tz);
6332001f49Smrg#endif
6432001f49Smrg   return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
6532001f49Smrg}
6632001f49Smrg
6732001f49Smrg#else /*BENCHMARK*/
6832001f49Smrg
6932001f49Smrg/* dummy */
7032001f49Smrgstatic double
7132001f49Smrgcurrent_time(void)
7232001f49Smrg{
7332001f49Smrg   /* update this function for other platforms! */
7432001f49Smrg   static double t = 0.0;
7532001f49Smrg   static int warn = 1;
7632001f49Smrg   if (warn) {
7732001f49Smrg      fprintf(stderr, "Warning: current_time() not implemented!!\n");
7832001f49Smrg      warn = 0;
7932001f49Smrg   }
8032001f49Smrg   return t += 1.0;
8132001f49Smrg}
8232001f49Smrg
8332001f49Smrg#endif /*BENCHMARK*/
8432001f49Smrg
8532001f49Smrg
8632001f49Smrg#ifndef M_PI
8732001f49Smrg#define M_PI 3.14159265
8832001f49Smrg#endif
8932001f49Smrg
9032001f49Smrg
9132001f49Smrgstatic GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
9232001f49Smrgstatic GLint gear1, gear2, gear3;
9332001f49Smrgstatic GLfloat angle = 0.0;
9432001f49Smrg
9532001f49Smrg#if 0
9632001f49Smrgstatic GLfloat eyesep = 5.0;		/* Eye separation. */
9732001f49Smrgstatic GLfloat fix_point = 40.0;	/* Fixation point distance.  */
9832001f49Smrgstatic GLfloat left, right, asp;	/* Stereo frustum params.  */
9932001f49Smrg#endif
10032001f49Smrg
10132001f49Smrg
10232001f49Smrg/*
10332001f49Smrg *
10432001f49Smrg *  Draw a gear wheel.  You'll probably want to call this function when
10532001f49Smrg *  building a display list since we do a lot of trig here.
10632001f49Smrg *
10732001f49Smrg *  Input:  inner_radius - radius of hole at center
10832001f49Smrg *          outer_radius - radius at center of teeth
10932001f49Smrg *          width - width of gear
11032001f49Smrg *          teeth - number of teeth
11132001f49Smrg *          tooth_depth - depth of tooth
11232001f49Smrg */
11332001f49Smrgstatic void
11432001f49Smrggear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
11532001f49Smrg     GLint teeth, GLfloat tooth_depth)
11632001f49Smrg{
11732001f49Smrg   GLint i;
11832001f49Smrg   GLfloat r0, r1, r2;
11932001f49Smrg   GLfloat angle, da;
12032001f49Smrg   GLfloat u, v, len;
12132001f49Smrg
12232001f49Smrg   r0 = inner_radius;
12332001f49Smrg   r1 = outer_radius - tooth_depth / 2.0;
12432001f49Smrg   r2 = outer_radius + tooth_depth / 2.0;
12532001f49Smrg
12632001f49Smrg   da = 2.0 * M_PI / teeth / 4.0;
12732001f49Smrg
12832001f49Smrg   glShadeModel(GL_FLAT);
12932001f49Smrg
13032001f49Smrg   glNormal3f(0.0, 0.0, 1.0);
13132001f49Smrg
13232001f49Smrg   /* draw front face */
13332001f49Smrg   glBegin(GL_QUAD_STRIP);
13432001f49Smrg   for (i = 0; i <= teeth; i++) {
13532001f49Smrg      angle = i * 2.0 * M_PI / teeth;
13632001f49Smrg      glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
13732001f49Smrg      glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
13832001f49Smrg      if (i < teeth) {
13932001f49Smrg	 glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
14032001f49Smrg	 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
14132001f49Smrg		    width * 0.5);
14232001f49Smrg      }
14332001f49Smrg   }
14432001f49Smrg   glEnd();
14532001f49Smrg
14632001f49Smrg   /* draw front sides of teeth */
14732001f49Smrg   glBegin(GL_QUADS);
14832001f49Smrg   da = 2.0 * M_PI / teeth / 4.0;
14932001f49Smrg   for (i = 0; i < teeth; i++) {
15032001f49Smrg      angle = i * 2.0 * M_PI / teeth;
15132001f49Smrg
15232001f49Smrg      glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
15332001f49Smrg      glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
15432001f49Smrg      glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
15532001f49Smrg		 width * 0.5);
15632001f49Smrg      glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
15732001f49Smrg		 width * 0.5);
15832001f49Smrg   }
15932001f49Smrg   glEnd();
16032001f49Smrg
16132001f49Smrg   glNormal3f(0.0, 0.0, -1.0);
16232001f49Smrg
16332001f49Smrg   /* draw back face */
16432001f49Smrg   glBegin(GL_QUAD_STRIP);
16532001f49Smrg   for (i = 0; i <= teeth; i++) {
16632001f49Smrg      angle = i * 2.0 * M_PI / teeth;
16732001f49Smrg      glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
16832001f49Smrg      glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
16932001f49Smrg      if (i < teeth) {
17032001f49Smrg	 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
17132001f49Smrg		    -width * 0.5);
17232001f49Smrg	 glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
17332001f49Smrg      }
17432001f49Smrg   }
17532001f49Smrg   glEnd();
17632001f49Smrg
17732001f49Smrg   /* draw back sides of teeth */
17832001f49Smrg   glBegin(GL_QUADS);
17932001f49Smrg   da = 2.0 * M_PI / teeth / 4.0;
18032001f49Smrg   for (i = 0; i < teeth; i++) {
18132001f49Smrg      angle = i * 2.0 * M_PI / teeth;
18232001f49Smrg
18332001f49Smrg      glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
18432001f49Smrg		 -width * 0.5);
18532001f49Smrg      glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
18632001f49Smrg		 -width * 0.5);
18732001f49Smrg      glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
18832001f49Smrg      glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
18932001f49Smrg   }
19032001f49Smrg   glEnd();
19132001f49Smrg
19232001f49Smrg   /* draw outward faces of teeth */
19332001f49Smrg   glBegin(GL_QUAD_STRIP);
19432001f49Smrg   for (i = 0; i < teeth; i++) {
19532001f49Smrg      angle = i * 2.0 * M_PI / teeth;
19632001f49Smrg
19732001f49Smrg      glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
19832001f49Smrg      glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
19932001f49Smrg      u = r2 * cos(angle + da) - r1 * cos(angle);
20032001f49Smrg      v = r2 * sin(angle + da) - r1 * sin(angle);
20132001f49Smrg      len = sqrt(u * u + v * v);
20232001f49Smrg      u /= len;
20332001f49Smrg      v /= len;
20432001f49Smrg      glNormal3f(v, -u, 0.0);
20532001f49Smrg      glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
20632001f49Smrg      glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
20732001f49Smrg      glNormal3f(cos(angle), sin(angle), 0.0);
20832001f49Smrg      glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
20932001f49Smrg		 width * 0.5);
21032001f49Smrg      glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
21132001f49Smrg		 -width * 0.5);
21232001f49Smrg      u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
21332001f49Smrg      v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
21432001f49Smrg      glNormal3f(v, -u, 0.0);
21532001f49Smrg      glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
21632001f49Smrg		 width * 0.5);
21732001f49Smrg      glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
21832001f49Smrg		 -width * 0.5);
21932001f49Smrg      glNormal3f(cos(angle), sin(angle), 0.0);
22032001f49Smrg   }
22132001f49Smrg
22232001f49Smrg   glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
22332001f49Smrg   glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
22432001f49Smrg
22532001f49Smrg   glEnd();
22632001f49Smrg
22732001f49Smrg   glShadeModel(GL_SMOOTH);
22832001f49Smrg
22932001f49Smrg   /* draw inside radius cylinder */
23032001f49Smrg   glBegin(GL_QUAD_STRIP);
23132001f49Smrg   for (i = 0; i <= teeth; i++) {
23232001f49Smrg      angle = i * 2.0 * M_PI / teeth;
23332001f49Smrg      glNormal3f(-cos(angle), -sin(angle), 0.0);
23432001f49Smrg      glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
23532001f49Smrg      glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
23632001f49Smrg   }
23732001f49Smrg   glEnd();
23832001f49Smrg}
23932001f49Smrg
24032001f49Smrg
24132001f49Smrgstatic void
24232001f49Smrgdraw(void)
24332001f49Smrg{
24432001f49Smrg   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
24532001f49Smrg
24632001f49Smrg   glPushMatrix();
24732001f49Smrg   glRotatef(view_rotx, 1.0, 0.0, 0.0);
24832001f49Smrg   glRotatef(view_roty, 0.0, 1.0, 0.0);
24932001f49Smrg   glRotatef(view_rotz, 0.0, 0.0, 1.0);
25032001f49Smrg
25132001f49Smrg   glPushMatrix();
25232001f49Smrg   glTranslatef(-3.0, -2.0, 0.0);
25332001f49Smrg   glRotatef(angle, 0.0, 0.0, 1.0);
25432001f49Smrg   glCallList(gear1);
25532001f49Smrg   glPopMatrix();
25632001f49Smrg
25732001f49Smrg   glPushMatrix();
25832001f49Smrg   glTranslatef(3.1, -2.0, 0.0);
25932001f49Smrg   glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
26032001f49Smrg   glCallList(gear2);
26132001f49Smrg   glPopMatrix();
26232001f49Smrg
26332001f49Smrg   glPushMatrix();
26432001f49Smrg   glTranslatef(-3.1, 4.2, 0.0);
26532001f49Smrg   glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
26632001f49Smrg   glCallList(gear3);
26732001f49Smrg   glPopMatrix();
26832001f49Smrg
26932001f49Smrg   glPopMatrix();
27032001f49Smrg}
27132001f49Smrg
27232001f49Smrg
27332001f49Smrg/* new window size or exposure */
27432001f49Smrgstatic void
27532001f49Smrgreshape(int width, int height)
27632001f49Smrg{
27732001f49Smrg   GLfloat h = (GLfloat) height / (GLfloat) width;
27832001f49Smrg
27932001f49Smrg   glViewport(0, 0, (GLint) width, (GLint) height);
28032001f49Smrg
28132001f49Smrg   glMatrixMode(GL_PROJECTION);
28232001f49Smrg   glLoadIdentity();
28332001f49Smrg   glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
28432001f49Smrg
28532001f49Smrg   glMatrixMode(GL_MODELVIEW);
28632001f49Smrg   glLoadIdentity();
28732001f49Smrg   glTranslatef(0.0, 0.0, -40.0);
28832001f49Smrg}
28932001f49Smrg
29032001f49Smrg
29132001f49Smrg
29232001f49Smrgstatic void
29332001f49Smrginit(void)
29432001f49Smrg{
29532001f49Smrg   static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
29632001f49Smrg   static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
29732001f49Smrg   static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
29832001f49Smrg   static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
29932001f49Smrg
30032001f49Smrg   glLightfv(GL_LIGHT0, GL_POSITION, pos);
30132001f49Smrg   glEnable(GL_CULL_FACE);
30232001f49Smrg   glEnable(GL_LIGHTING);
30332001f49Smrg   glEnable(GL_LIGHT0);
30432001f49Smrg   glEnable(GL_DEPTH_TEST);
30532001f49Smrg
30632001f49Smrg   /* make the gears */
30732001f49Smrg   gear1 = glGenLists(1);
30832001f49Smrg   glNewList(gear1, GL_COMPILE);
30932001f49Smrg   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
31032001f49Smrg   gear(1.0, 4.0, 1.0, 20, 0.7);
31132001f49Smrg   glEndList();
31232001f49Smrg
31332001f49Smrg   gear2 = glGenLists(1);
31432001f49Smrg   glNewList(gear2, GL_COMPILE);
31532001f49Smrg   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
31632001f49Smrg   gear(0.5, 2.0, 2.0, 10, 0.7);
31732001f49Smrg   glEndList();
31832001f49Smrg
31932001f49Smrg   gear3 = glGenLists(1);
32032001f49Smrg   glNewList(gear3, GL_COMPILE);
32132001f49Smrg   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
32232001f49Smrg   gear(1.3, 2.0, 0.5, 10, 0.7);
32332001f49Smrg   glEndList();
32432001f49Smrg
32532001f49Smrg   glEnable(GL_NORMALIZE);
32632001f49Smrg}
32732001f49Smrg
32832001f49Smrg
32932001f49Smrg
33032001f49Smrg
33132001f49Smrgstatic void run_gears(EGLDisplay dpy, EGLSurface surf, int ttr)
33232001f49Smrg{
33332001f49Smrg	double st = current_time();
33432001f49Smrg	double ct = st;
33532001f49Smrg	int frames = 0;
33632001f49Smrg	GLfloat seconds, fps;
33732001f49Smrg
33832001f49Smrg	while (ct - st < ttr)
33932001f49Smrg	{
34032001f49Smrg		double tt = current_time();
34132001f49Smrg		double dt = tt - ct;
34232001f49Smrg		ct = tt;
34332001f49Smrg
34432001f49Smrg		/* advance rotation for next frame */
34532001f49Smrg		angle += 70.0 * dt;  /* 70 degrees per second */
34632001f49Smrg		if (angle > 3600.0)
34732001f49Smrg			angle -= 3600.0;
34832001f49Smrg
34932001f49Smrg		draw();
35032001f49Smrg
35132001f49Smrg		eglSwapBuffers(dpy, surf);
35232001f49Smrg
35332001f49Smrg
35432001f49Smrg		frames++;
35532001f49Smrg	}
35632001f49Smrg
35732001f49Smrg	seconds = ct - st;
35832001f49Smrg	fps = frames / seconds;
35932001f49Smrg	printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps);
36032001f49Smrg	fflush(stdout);
36132001f49Smrg
36232001f49Smrg}
36332001f49Smrg
36432001f49Smrg
36532001f49Smrgint
36632001f49Smrgmain(int argc, char *argv[])
36732001f49Smrg{
36832001f49Smrg	int major, minor;
36932001f49Smrg	EGLContext ctx;
37032001f49Smrg	EGLSurface surface;
37132001f49Smrg	EGLConfig configs[MAX_CONFIGS];
37232001f49Smrg	EGLint numConfigs, i;
37332001f49Smrg	EGLBoolean b;
37432001f49Smrg	EGLDisplay d;
37532001f49Smrg	EGLint configAttribs[10];
37632001f49Smrg	EGLint screenAttribs[10];
37732001f49Smrg	GLboolean printInfo = GL_FALSE;
37832001f49Smrg	EGLint width = 300, height = 300;
37932001f49Smrg
38032001f49Smrg        /* parse cmd line args */
38132001f49Smrg	for (i = 1; i < argc; i++)
38232001f49Smrg	{
38332001f49Smrg		if (strcmp(argv[i], "-info") == 0)
38432001f49Smrg		{
38532001f49Smrg			printInfo = GL_TRUE;
38632001f49Smrg		}
38732001f49Smrg		else
38832001f49Smrg			printf("Warning: unknown parameter: %s\n", argv[i]);
38932001f49Smrg	}
39032001f49Smrg
39132001f49Smrg	/* DBR : Create EGL context/surface etc */
39232001f49Smrg	d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
39332001f49Smrg	assert(d);
39432001f49Smrg
39532001f49Smrg	if (!eglInitialize(d, &major, &minor)) {
39632001f49Smrg		printf("peglgears: eglInitialize failed\n");
39732001f49Smrg		return 0;
39832001f49Smrg	}
39932001f49Smrg
40032001f49Smrg	printf("peglgears: EGL version = %d.%d\n", major, minor);
40132001f49Smrg	printf("peglgears: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
40232001f49Smrg
40332001f49Smrg	i = 0;
40432001f49Smrg	configAttribs[i++] = EGL_RENDERABLE_TYPE;
40532001f49Smrg	configAttribs[i++] = EGL_OPENGL_BIT;
40632001f49Smrg	configAttribs[i++] = EGL_SURFACE_TYPE;
40732001f49Smrg	configAttribs[i++] = EGL_PBUFFER_BIT;
40832001f49Smrg	configAttribs[i++] = EGL_NONE;
40932001f49Smrg
41032001f49Smrg	numConfigs = 0;
41132001f49Smrg	if (!eglChooseConfig(d, configAttribs, configs, MAX_CONFIGS, &numConfigs) ||
41232001f49Smrg	    !numConfigs) {
41332001f49Smrg		printf("peglgears: failed to choose a config\n");
41432001f49Smrg		return 0;
41532001f49Smrg	}
41632001f49Smrg
41732001f49Smrg	eglBindAPI(EGL_OPENGL_API);
41832001f49Smrg
41932001f49Smrg	ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
42032001f49Smrg	if (ctx == EGL_NO_CONTEXT) {
42132001f49Smrg		printf("peglgears: failed to create context\n");
42232001f49Smrg		return 0;
42332001f49Smrg	}
42432001f49Smrg
42532001f49Smrg	/* build up screenAttribs array */
42632001f49Smrg	i = 0;
42732001f49Smrg	screenAttribs[i++] = EGL_WIDTH;
42832001f49Smrg	screenAttribs[i++] = width;
42932001f49Smrg	screenAttribs[i++] = EGL_HEIGHT;
43032001f49Smrg	screenAttribs[i++] = height;
43132001f49Smrg	screenAttribs[i++] = EGL_NONE;
43232001f49Smrg
43332001f49Smrg	surface = eglCreatePbufferSurface(d, configs[0], screenAttribs);
43432001f49Smrg	if (surface == EGL_NO_SURFACE) {
43532001f49Smrg		printf("peglgears: failed to create pbuffer surface\n");
43632001f49Smrg		return 0;
43732001f49Smrg	}
43832001f49Smrg
43932001f49Smrg	b = eglMakeCurrent(d, surface, surface, ctx);
44032001f49Smrg	if (!b) {
44132001f49Smrg		printf("peglgears: make current failed\n");
44232001f49Smrg		return 0;
44332001f49Smrg	}
44432001f49Smrg
44532001f49Smrg	if (printInfo)
44632001f49Smrg	{
44732001f49Smrg		printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
44832001f49Smrg		printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
44932001f49Smrg		printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
45032001f49Smrg		printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
45132001f49Smrg	}
45232001f49Smrg
45332001f49Smrg	init();
45432001f49Smrg	reshape(width, height);
45532001f49Smrg
45632001f49Smrg	glDrawBuffer( GL_BACK );
45732001f49Smrg
45832001f49Smrg	run_gears(d, surface, 5.0);
45932001f49Smrg
46032001f49Smrg	eglDestroySurface(d, surface);
46132001f49Smrg	eglDestroyContext(d, ctx);
46232001f49Smrg	eglTerminate(d);
46332001f49Smrg
46432001f49Smrg	return 0;
46532001f49Smrg}
466