#include <unistd.h>
/* return current time (in seconds) */
-static int
+static double
current_time(void)
{
struct timeval tv;
struct timezone tz;
(void) gettimeofday(&tv, &tz);
#endif
- return (int) tv.tv_sec;
+ return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
}
#else /*BENCHMARK*/
/* dummy */
-static int
+static double
current_time(void)
{
- return 0;
+ /* update this function for other platforms! */
+ static double t = 0.0;
+ static int warn = 1;
+ if (warn) {
+ fprintf(stderr, "Warning: current_time() not implemented!!\n");
+ warn = 0;
+ }
+ return t += 1.0;
}
#endif /*BENCHMARK*/
static GLint gear1, gear2, gear3;
static GLfloat angle = 0.0;
+static GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */
static GLboolean stereo = GL_FALSE; /* Enable stereo. */
static GLfloat eyesep = 5.0; /* Eye separation. */
static GLfloat fix_point = 40.0; /* Fixation point distance. */
scrnum = DefaultScreen( dpy );
root = RootWindow( dpy, scrnum );
+ if (fullscreen) {
+ x = 0; y = 0;
+ width = DisplayWidth( dpy, scrnum );
+ height = DisplayHeight( dpy, scrnum );
+ }
+
if (stereo)
visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs );
else
attr.border_pixel = 0;
attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
- mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+ attr.override_redirect = fullscreen;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
win = XCreateWindow( dpy, root, 0, 0, width, height,
0, visinfo->depth, InputOutput,
}
}
- /* next frame */
- angle += 2.0;
- if (angle > 3600.0)
- angle -= 3600.0;
-
- draw();
- glXSwapBuffers(dpy, win);
-
- /* calc framerate */
{
- static int t0 = -1;
static int frames = 0;
- int t = current_time();
+ static double tRot0 = -1.0, tRate0 = -1.0;
+ double dt, t = current_time();
+ if (tRot0 < 0.0)
+ tRot0 = t;
+ dt = t - tRot0;
+ tRot0 = t;
+
+ /* advance rotation for next frame */
+ angle += 70.0 * dt; /* 70 degrees per second */
+ if (angle > 3600.0)
+ angle -= 3600.0;
- if (t0 < 0)
- t0 = t;
+ draw();
+ glXSwapBuffers(dpy, win);
frames++;
- if (t - t0 >= 5.0) {
- GLfloat seconds = t - t0;
+ if (tRate0 < 0.0)
+ tRate0 = t;
+ if (t - tRate0 >= 5.0) {
+ GLfloat seconds = t - tRate0;
GLfloat fps = frames / seconds;
printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
fps);
- t0 = t;
+ tRate0 = t;
frames = 0;
}
}
}
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+ printf(" -stereo run in stereo mode\n");
+ printf(" -fullscreen run in fullscreen mode\n");
+ printf(" -info display OpenGL renderer info\n");
+}
+
+
int
main(int argc, char *argv[])
{
+ const int winWidth = 300, winHeight = 300;
Display *dpy;
Window win;
GLXContext ctx;
else if (strcmp(argv[i], "-stereo") == 0) {
stereo = GL_TRUE;
}
- else
- printf("Warrning: unknown parameter: %s\n", argv[i]);
+ else if (strcmp(argv[i], "-fullscreen") == 0) {
+ fullscreen = GL_TRUE;
+ }
+ else {
+ usage();
+ return -1;
+ }
}
dpy = XOpenDisplay(dpyName);
return -1;
}
- make_window(dpy, "glxgears", 0, 0, 300, 300, &win, &ctx);
+ make_window(dpy, "glxgears", 0, 0, winWidth, winHeight, &win, &ctx);
XMapWindow(dpy, win);
glXMakeCurrent(dpy, win, ctx);
init();
+ /* Set initial projection/viewing transformation.
+ * We can't be sure we'll get a ConfigureNotify event when the window
+ * first appears.
+ */
+ reshape(winWidth, winHeight);
+
event_loop(dpy, win);
+ glDeleteLists(gear1, 1);
+ glDeleteLists(gear2, 1);
+ glDeleteLists(gear3, 1);
glXDestroyContext(dpy, ctx);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);