#!/usr/local/bin/perl
#
#           double
#
#  This program demonstrates double buffering for 
#  flicker-free animation.  
#  Adapted from "double", chapter 1, listing 1-3,
#  page 17, OpenGL Programming Guide 

BEGIN{ unshift(@INC,"../blib"); }  # in case OpenGL is built but not installed
use OpenGL;
 
$spin = 0.0;


sub myReshape {
    # glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho (-50.0, 50.0, -50.0,50.0,-1.0,1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
}

sub display{
    glClear(GL_COLOR_BUFFER_BIT);

    glPushMatrix();
    glRotatef($spin, 0.0, 0.0, 1.0);
    glRectf(-25.0, -25.0, 25.0, 25.0);
    glPopMatrix();

    glFlush();
    glXSwapBuffers;
}

sub spinDisplay {
    $spin = $spin + 2.0;
    if ($spin > 360.0) {
	$spin = $spin - 360.0;
    }
    display();
}

glpOpenWindow(400,400,GLX_RGBA,GLX_DOUBLEBUFFER);
glClearColor(0,0,0,1);
glColor3f (1.0, 1.0, 1.0);
glShadeModel (GL_FLAT);
myReshape();

while(1) {
	spinDisplay();
}
