summaryrefslogtreecommitdiffstats
path: root/PerlQt/examples/opengl/box/GLBox.pm
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-12-18 03:08:08 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-12-18 03:08:08 -0600
commitbcc95cd92ca12c1783464b8ada6816d430dc0e98 (patch)
tree4701c447365db5392df0174b4bb00b5b5c369da4 /PerlQt/examples/opengl/box/GLBox.pm
downloadlibtqt-perl-bcc95cd92ca12c1783464b8ada6816d430dc0e98.tar.gz
libtqt-perl-bcc95cd92ca12c1783464b8ada6816d430dc0e98.zip
Initial import of libqt-perl (not yet TQt compatible)
Diffstat (limited to 'PerlQt/examples/opengl/box/GLBox.pm')
-rw-r--r--PerlQt/examples/opengl/box/GLBox.pm149
1 files changed, 149 insertions, 0 deletions
diff --git a/PerlQt/examples/opengl/box/GLBox.pm b/PerlQt/examples/opengl/box/GLBox.pm
new file mode 100644
index 0000000..dd6ceb9
--- /dev/null
+++ b/PerlQt/examples/opengl/box/GLBox.pm
@@ -0,0 +1,149 @@
+package GLBox;
+
+use OpenGL qw(:all);
+
+use strict;
+
+use Qt;
+use Qt::isa qw(Qt::GLWidget);
+use Qt::slots
+ setXRotation => ['int'],
+ setYRotation => ['int'],
+ setZRotation => ['int'];
+use Qt::attributes qw(
+ xRot
+ yRot
+ zRot
+ scale
+ object
+ list
+);
+
+sub NEW {
+ shift->SUPER::NEW(@_);
+ xRot = yRot = zRot = 0.0;
+ scale = 1.25;
+ object = undef;
+}
+
+sub paintGL
+{
+ glClear( GL_COLOR_BUFFER_BIT );
+ glClear( GL_DEPTH_BUFFER_BIT );
+
+ glLoadIdentity();
+ glTranslatef( 0.0, 0.0, -10.0 );
+ glScalef( scale, scale, scale );
+
+ glRotatef( xRot, 1.0, 0.0, 0.0 );
+ glRotatef( yRot, 0.0, 1.0, 0.0 );
+ glRotatef( zRot, 0.0, 0.0, 1.0 );
+
+ glCallList( object );
+}
+
+sub initializeGL
+{
+ qglClearColor( &black ); # Let OpenGL clear to black
+ object = makeObject(); # Generate an OpenGL display list
+ glShadeModel( GL_FLAT );
+ glEnable( GL_DEPTH_TEST );
+}
+
+# Set up the OpenGL view port, matrix mode, etc.
+
+sub resizeGL
+{
+ my $w = shift;
+ my $h = shift;
+ glViewport( 0, 0, $w, $h );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
+ glMatrixMode( GL_MODELVIEW );
+}
+
+# Generate an OpenGL display list for the object to be shown, i.e. the box
+
+sub makeObject
+{
+ my $list = glGenLists( 1 );
+
+ glNewList( $list, GL_COMPILE );
+
+ qglColor( &darkGreen ); # Shorthand for glColor3f or glIndex
+
+ glLineWidth( 2.0 );
+
+ glBegin( GL_QUADS );
+ glVertex3f( 1.0, 0.5, -0.4 );
+ glVertex3f( 1.0, -0.5, -0.4 );
+ glVertex3f( -1.0, -0.5, -0.4 );
+ glVertex3f( -1.0, 0.5, -0.4 );
+ glEnd();
+
+ qglColor( &blue );
+
+ glBegin( GL_QUADS );
+ glVertex3f( 1.0, 0.5, 0.4 );
+ glVertex3f( 1.0, -0.5, 0.4 );
+ glVertex3f( -1.0, -0.5, 0.4 );
+ glVertex3f( -1.0, 0.5, 0.4 );
+ glEnd();
+
+ qglColor( &darkRed );
+
+ glBegin( GL_QUAD_STRIP );
+ glVertex3f( 1.0, 0.5, -0.4 ); glVertex3f( 1.0, 0.5, 0.4 );
+ glVertex3f( 1.0, -0.5, -0.4 ); glVertex3f( 1.0, -0.5, 0.4 );
+ qglColor( &yellow );
+ glVertex3f( -1.0, -0.5, -0.4 ); glVertex3f( -1.0, -0.5, 0.4 );
+ qglColor( &green );
+ glVertex3f( -1.0, 0.5, -0.4 ); glVertex3f( -1.0, 0.5, 0.4 );
+ qglColor( &lightGray );
+ glVertex3f( 1.0, 0.5, -0.4 ); glVertex3f( 1.0, 0.5, 0.4 );
+ glEnd();
+
+ glEndList();
+
+ return $list;
+}
+
+
+
+# Set the rotation angle of the object to \e degrees around the X axis.
+
+sub setXRotation
+{
+ my $deg = shift;
+ xRot = $deg % 360;
+ updateGL();
+}
+
+
+# Set the rotation angle of the object to \e degrees around the Y axis.
+
+sub setYRotation
+{
+ my $deg = shift;
+ yRot = $deg % 360;
+ updateGL();
+}
+
+
+# Set the rotation angle of the object to \e degrees around the Z axis.
+
+sub setZRotation
+{
+ my $deg = shift;
+ zRot = $deg % 360;
+ updateGL();
+}
+
+sub DESTROY
+{
+# makeCurrent();
+ glDeleteLists( object, 1 );
+}
+
+1;