summaryrefslogtreecommitdiffstats
path: root/PerlTQt/examples/opengl/box
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2012-01-01 18:29:30 -0600
committerTimothy Pearson <[email protected]>2012-01-01 18:29:30 -0600
commitb2af005db21bd8fd068cb79b2ae700953128af2c (patch)
treeabd0ed633726bf0bbecb57d30e92836c31e02695 /PerlTQt/examples/opengl/box
parentc1b9383f2032d82db5eb8918dca885e37a901dde (diff)
downloadlibtqt-perl-b2af005db21bd8fd068cb79b2ae700953128af2c.tar.gz
libtqt-perl-b2af005db21bd8fd068cb79b2ae700953128af2c.zip
Move PerlQt
Diffstat (limited to 'PerlTQt/examples/opengl/box')
-rw-r--r--PerlTQt/examples/opengl/box/GLBox.pm149
-rw-r--r--PerlTQt/examples/opengl/box/glbox90
2 files changed, 239 insertions, 0 deletions
diff --git a/PerlTQt/examples/opengl/box/GLBox.pm b/PerlTQt/examples/opengl/box/GLBox.pm
new file mode 100644
index 0000000..1c6ceb8
--- /dev/null
+++ b/PerlTQt/examples/opengl/box/GLBox.pm
@@ -0,0 +1,149 @@
+package GLBox;
+
+use OpenGL qw(:all);
+
+use strict;
+
+use TQt;
+use TQt::isa qw(TQt::GLWidget);
+use TQt::slots
+ setXRotation => ['int'],
+ setYRotation => ['int'],
+ setZRotation => ['int'];
+use TQt::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_TQUADS );
+ 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_TQUADS );
+ 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_TQUAD_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;
diff --git a/PerlTQt/examples/opengl/box/glbox b/PerlTQt/examples/opengl/box/glbox
new file mode 100644
index 0000000..fed74a3
--- /dev/null
+++ b/PerlTQt/examples/opengl/box/glbox
@@ -0,0 +1,90 @@
+
+package GLObjectWindow;
+
+use strict;
+
+use TQt;
+use TQt::isa qw(TQt::Widget);
+use TQt::attributes qw(
+ file
+ frame
+ menu
+ box
+ xpos
+ ypos
+ zpos
+);
+
+use GLBox;
+
+sub NEW
+{
+ shift->SUPER::NEW(@_);
+
+ # Create a menu
+ file = TQt::PopupMenu( this );
+ file->insertItem( "Exit", TQt::app(), TQT_SLOT 'quit()', TQt::KeySequence(int &CTRL + &Key_Q ));
+
+ # Create a menu bar
+ menu = TQt::MenuBar( this );
+ menu->setSeparator( &TQt::MenuBar::InWindowsStyle );
+ menu->insertItem("&File", file );
+
+ # Create a nice frame to put around the OpenGL widget
+ frame = TQt::Frame( this, "frame" );
+ frame->setFrameStyle( &TQt::Frame::Sunken | &TQt::Frame::Panel );
+ frame->setLineWidth( 2 );
+
+ # Create our OpenGL widget
+ box = GLBox( frame, "glbox");
+
+ # Create the three sliders; one for each rotation axis
+ xpos = TQt::Slider ( 0, 360, 60, 0, &TQt::Slider::Vertical, this, "xsl" );
+ xpos->setTickmarks( &TQt::Slider::Left );
+ TQt::Object::connect( xpos, TQT_SIGNAL 'valueChanged(int)', box, TQT_SLOT 'setXRotation(int)' );
+
+ ypos = TQt::Slider ( 0, 360, 60, 0, &TQt::Slider::Vertical, this, "ysl" );
+ ypos->setTickmarks( &TQt::Slider::Left );
+ TQt::Object::connect( ypos, TQT_SIGNAL 'valueChanged(int)', box, TQT_SLOT 'setYRotation(int)' );
+
+ zpos = TQt::Slider ( 0, 360, 60, 0, &TQt::Slider::Vertical, this, "zsl" );
+ zpos->setTickmarks( &TQt::Slider::Left );
+ TQt::Object::connect( zpos, TQT_SIGNAL 'valueChanged(int)', box, TQT_SLOT 'setZRotation(int)' );
+
+
+ # Now that we have all the widgets, put them into a nice layout
+
+ # Put the sliders on top of each other
+ my $vlayout = TQt::VBoxLayout( 20, "vlayout");
+ $vlayout->addWidget( xpos );
+ $vlayout->addWidget( ypos );
+ $vlayout->addWidget( zpos );
+
+ # Put the GL widget inside the frame
+ my $flayout = TQt::HBoxLayout( frame, 2, 2, "flayout");
+ $flayout->addWidget( box, 1 );
+
+ # Top level layout, puts the sliders to the left of the frame/GL widget
+ my $hlayout = TQt::HBoxLayout( this, 20, 20, "hlayout");
+ $hlayout->setMenuBar( menu );
+ $hlayout->addLayout( $vlayout );
+ $hlayout->addWidget( frame, 1 );
+}
+
+1;
+
+package main;
+
+use TQt;
+use GLObjectWindow;
+
+my $a = TQt::Application(\@ARGV);
+
+my $w = GLObjectWindow;
+$w->resize(350,350);
+$w->show;
+
+$a->setMainWidget( $w);
+
+exit $a->exec;
+