summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
Diffstat (limited to 'progs')
-rw-r--r--progs/demos/lodbias.c2
-rw-r--r--progs/demos/texenv.c4
-rw-r--r--progs/glsl/.gitignore3
-rw-r--r--progs/osdemos/ostest1.c7
-rw-r--r--progs/xdemos/glxgears.c187
5 files changed, 126 insertions, 77 deletions
diff --git a/progs/demos/lodbias.c b/progs/demos/lodbias.c
index c5a2a1b457..28215d46c0 100644
--- a/progs/demos/lodbias.c
+++ b/progs/demos/lodbias.c
@@ -40,7 +40,7 @@
static GLfloat Xrot = 0, Yrot = -30, Zrot = 0;
static GLboolean Anim = GL_TRUE;
-static GLint Bias = 0, BiasStepSign = +1; /* ints avoid fp precision problem */
+static GLint Bias = 4, BiasStepSign = +1; /* ints avoid fp precision problem */
static GLint BiasMin = -400, BiasMax = 400;
diff --git a/progs/demos/texenv.c b/progs/demos/texenv.c
index 590867b494..c4174dc173 100644
--- a/progs/demos/texenv.c
+++ b/progs/demos/texenv.c
@@ -76,6 +76,7 @@ int textureWidth = 64;
int textureHeight = 64;
int winWidth = 580, winHeight = 720;
+int win;
struct formatInfo {
GLenum baseFormat;
@@ -288,6 +289,7 @@ static void keyboard( unsigned char c, int x, int y )
displayLevelInfo = !displayLevelInfo;
break;
case 27: /* Escape key should force exit. */
+ glutDestroyWindow(win);
exit(0);
break;
default:
@@ -785,7 +787,7 @@ int main( int argc, char *argv[] )
glutInitWindowSize( winWidth, winHeight );
glutInitWindowPosition( 0, 0 );
- glutCreateWindow( "Texture Environment Test" );
+ win = glutCreateWindow( "Texture Environment Test" );
initialize();
instructions();
diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore
index 7865753ea9..1e0aecebef 100644
--- a/progs/glsl/.gitignore
+++ b/progs/glsl/.gitignore
@@ -4,10 +4,13 @@ bump
deriv
extfuncs.h
mandelbrot
+multitex
noise
points
readtex.c
readtex.h
+shaderutil.c
+shaderutil.h
texdemo1
toyball
trirast
diff --git a/progs/osdemos/ostest1.c b/progs/osdemos/ostest1.c
index 2c7adfc353..000b8c4a78 100644
--- a/progs/osdemos/ostest1.c
+++ b/progs/osdemos/ostest1.c
@@ -407,7 +407,10 @@ test(GLenum type, GLint bits, const char *filename)
glGetIntegerv(GL_ALPHA_BITS, &cBits);
assert(cBits == bits);
- printf("Rendering %d bit/channel image: %s\n", bits, filename);
+ if (WriteFiles)
+ printf("Rendering %d bit/channel image: %s\n", bits, filename);
+ else
+ printf("Rendering %d bit/channel image\n", bits);
OSMesaColorClamp(GL_TRUE);
@@ -458,6 +461,8 @@ main( int argc, char *argv[] )
{
int i;
+ printf("Use -f to write image files\n");
+
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-f") == 0)
WriteFiles = GL_TRUE;
diff --git a/progs/xdemos/glxgears.c b/progs/xdemos/glxgears.c
index ec431c16f0..c98c3157b5 100644
--- a/progs/xdemos/glxgears.c
+++ b/progs/xdemos/glxgears.c
@@ -88,12 +88,18 @@ current_time(void)
#endif
+/** Event handler results: */
+#define NOP 0
+#define EXIT 1
+#define DRAW 2
+
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
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 GLboolean animate = GL_TRUE; /* Animation */
static GLfloat eyesep = 5.0; /* Eye separation. */
static GLfloat fix_point = 40.0; /* Fixation point distance. */
static GLfloat left, right, asp; /* Stereo frustum params. */
@@ -239,7 +245,7 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
static void
-do_draw(void)
+draw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -269,8 +275,9 @@ do_draw(void)
glPopMatrix();
}
+
static void
-draw(void)
+draw_gears(void)
{
if (stereo) {
/* First left eye. */
@@ -284,7 +291,7 @@ draw(void)
glPushMatrix();
glTranslated(+0.5 * eyesep, 0.0, 0.0);
- do_draw();
+ draw();
glPopMatrix();
/* Then right eye. */
@@ -298,10 +305,50 @@ draw(void)
glPushMatrix();
glTranslated(-0.5 * eyesep, 0.0, 0.0);
- do_draw();
+ draw();
glPopMatrix();
- } else
- do_draw();
+ }
+ else {
+ draw();
+ }
+}
+
+
+/** Draw single frame, do SwapBuffers, compute FPS */
+static void
+draw_frame(Display *dpy, Window win)
+{
+ static int frames = 0;
+ static double tRot0 = -1.0, tRate0 = -1.0;
+ double dt, t = current_time();
+
+ if (tRot0 < 0.0)
+ tRot0 = t;
+ dt = t - tRot0;
+ tRot0 = t;
+
+ if (animate) {
+ /* advance rotation for next frame */
+ angle += 70.0 * dt; /* 70 degrees per second */
+ if (angle > 3600.0)
+ angle -= 3600.0;
+ }
+
+ draw_gears();
+ glXSwapBuffers(dpy, win);
+
+ frames++;
+
+ 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);
+ tRate0 = t;
+ frames = 0;
+ }
}
@@ -319,7 +366,8 @@ reshape(int width, int height)
left = -5.0 * ((w - 0.5 * eyesep) / fix_point);
right = 5.0 * ((w + 0.5 * eyesep) / fix_point);
- } else {
+ }
+ else {
GLfloat h = (GLfloat) height / (GLfloat) width;
glMatrixMode(GL_PROJECTION);
@@ -430,6 +478,7 @@ make_window( Display *dpy, const char *name,
attr.border_pixel = 0;
attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ /* XXX this is a bad way to get a borderless window! */
attr.override_redirect = fullscreen;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
@@ -463,79 +512,70 @@ make_window( Display *dpy, const char *name,
}
+/**
+ * Handle one X event.
+ * \return NOP, EXIT or DRAW
+ */
+static int
+handle_event(Display *dpy, Window win, XEvent *event)
+{
+ switch (event->type) {
+ case Expose:
+ return DRAW;
+ case ConfigureNotify:
+ reshape(event->xconfigure.width, event->xconfigure.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event->xkey, 0);
+ if (code == XK_Left) {
+ view_roty += 5.0;
+ }
+ else if (code == XK_Right) {
+ view_roty -= 5.0;
+ }
+ else if (code == XK_Up) {
+ view_rotx += 5.0;
+ }
+ else if (code == XK_Down) {
+ view_rotx -= 5.0;
+ }
+ else {
+ r = XLookupString(&event->xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == 27) {
+ /* escape */
+ return EXIT;
+ }
+ else if (buffer[0] == 'a' || buffer[0] == 'A') {
+ animate = !animate;
+ }
+ }
+ return DRAW;
+ }
+ }
+ return NOP;
+}
+
+
static void
event_loop(Display *dpy, Window win)
{
while (1) {
- while (XPending(dpy) > 0) {
+ int op;
+ while (!animate || XPending(dpy) > 0) {
XEvent event;
XNextEvent(dpy, &event);
- switch (event.type) {
- case Expose:
- /* we'll redraw below */
- break;
- case ConfigureNotify:
- reshape(event.xconfigure.width, event.xconfigure.height);
- break;
- case KeyPress:
- {
- char buffer[10];
- int r, code;
- code = XLookupKeysym(&event.xkey, 0);
- if (code == XK_Left) {
- view_roty += 5.0;
- }
- else if (code == XK_Right) {
- view_roty -= 5.0;
- }
- else if (code == XK_Up) {
- view_rotx += 5.0;
- }
- else if (code == XK_Down) {
- view_rotx -= 5.0;
- }
- else {
- r = XLookupString(&event.xkey, buffer, sizeof(buffer),
- NULL, NULL);
- if (buffer[0] == 27) {
- /* escape */
- return;
- }
- }
- }
- }
+ op = handle_event(dpy, win, &event);
+ if (op == EXIT)
+ return;
+ else if (op == DRAW)
+ break;
}
- {
- static int frames = 0;
- 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;
-
- draw();
- glXSwapBuffers(dpy, win);
-
- frames++;
-
- 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);
- tRate0 = t;
- frames = 0;
- }
- }
+ draw_frame(dpy, win);
}
}
@@ -548,8 +588,7 @@ usage(void)
printf(" -stereo run in stereo mode\n");
printf(" -fullscreen run in fullscreen mode\n");
printf(" -info display OpenGL renderer info\n");
- printf(" -winwidth <width> window width (default: 300)\n");
- printf(" -winheight <height> window height (default: 300)\n");
+ printf(" -geometry WxH+X+Y window geometry\n");
}