GUI??? - Library for implementing GUIs with OpenGL
# Simple Example #!/usr/bin/perl -w use strict; use GUIFrame; use GUIButton; our $rtri =0; ## triangle rotation OpenGL::glutInit; OpenGL::glutInitDisplayMode(OpenGL::GLUT_RGB | OpenGL::GLUT_DEPTH | OpenGL::GLUT_DOUBLE); OpenGL::glutInitWindowSize(800,400); OpenGL::glutInitWindowPosition(200,100); my $win1 = OpenGL::glutCreateWindow("OpenGL GUIButton Test"); glViewport(0,0,400,400); my $pwin = glutCreateSubWindow($win1, 0,0, 400,400); &setup3D; ## build the 2D panel my $GUIRoot = GUIWindow->new(GLwindow=> $win1, x => 400, y => 0, width => 400, height => 400, ); $GUIRoot->adopt(GUIButton->new(x=>10,y=>10, width=>52,height=>32,text=>'Exit', clickCallback=>sub{exit(0)}, )); glutDisplayFunc( sub{ $GUIRoot->GUIDraw(@_) }); glutMouseFunc( sub{ $GUIRoot->mouseButton(@_) }); glutMotionFunc( sub{ $GUIRoot->mouseMotion(@_) }); glutPassiveMotionFunc(sub{ $GUIRoot->mousePassiveMotion(@_) }); glutMainLoop; sub step { glutSetWindow($pwin); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); # Reset The View glTranslatef(0.0, 0.0, -6.0); # Move into the screen 6.0 units. glRotatef($rtri, 0.0, 1.0, 0.0); glBegin(GL_POLYGON); glColor3f(1.0, 0.0, 0.0); # Red glVertex3f(0.0, 1.0, 0.0); # Top glColor3f(0.0, 1.0, 0.0); # Green glVertex3f(1.0, -1.0, 0.0); # Bottom Right glColor3f(0.0, 0.0, 1.0); # Blue glVertex3f(-1.0, -1.0, 0.0); # Bottom Left glEnd(); # We are done with the triangle $rtri+=1; glutSwapBuffers(); }
sub setup3D { glClearColor(0.0, 0.0, 0.0, 0.0); # Set up 3D calls glClearDepth(1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, 1.0, 0.1, 100.0); glMatrixMode(GL_MODELVIEW); glutDisplayFunc(\&step); glutIdleFunc(\&step); }
GUI???? is a tool for creating user interfaces with OpenGL widgets. It allows 2D controls to be associated with 3D images without requiring sharing execution with a tool like Tk. It provides widgets for labels, buttons, text display and canvas drawing areas. The canvas supports drawing lines, circles, polygons and images.
To implement an application with a 3D window and a 2D window, the base window is created with glutCreateWindow and divided creating two subwindows with glutCreateSubWindow. The 2D subwindow is passed as wid (window ID) to the constructor of a GUIFrame. The desired GUI widgets are created using the adopt method of GUIFrame. Similarly, objects to be drawn on a GUI canvas are created with the create method of the GUICanvas.
All of the objects have accessor routines for each option allowing them to be changed dynamically.
The GUI??? is composed of the GUIWindow, GUIFrame, GUIButton, GUICanvas, and GUIText objects.
GUIWindow - Create a window to hold 2D widgets. GUIWindow is a subclass of GUIFrame.
$guiWindow = GUIWindow->new(?options?);
Name: GLwindow Specifies the OpenGL window that the subwindow will be placed in
Also, accepts all the options of a GUIFrame.
$guiWindow->adopt(widget); Add a widget to the window.
$guiWindow->adopt(widget);
$guiWindow->draw; Draw the window and all its children
$guiWindow->draw;
These methods are not normally called directly. They are passed to glut.
$guiWindow->draw(@_); Passed to glutDisplayFunc.
$guiWindow->draw(@_);
$guiWindow->mouseButton(@_); Passed to glutMouseFunc.
$guiWindow->mouseButton(@_);
$guiWindow->mouseMotion(@_); May be passed to glutMotionFunc.
$guiWindow->mouseMotion(@_);
$guiWindow->mousePassiveMotion(@_); May be passed to glutPassiveMotionFunc.
$guiWindow->mousePassiveMotion(@_);
GUIFrame - Create frame to hold 2D widgets
$guiFrame = GUIFrame->new(?options?);
Name: color Specifies the background color for the frame as a text string.
Names: x and y Coordinates of the upper left corner of the frame.
Names: height and width Size of the frame
Name: texture Optional OpenGL texture name to display the frame as a texture rather than in a single color.
$guiFrame->adopt(widget); Add a widget to the frame.
$guiFrame->adopt(widget);
$guiFrame->draw; Draw the frame and all its children
$guiFrame->draw;
GUIButton - Create push button widget
$button = GUIButton->new(?options?);
Name: color Specifies the background color for the button as a text string.
Name: font One of the available glut bitmapped fonts. As a value, not a string.
Names: x and y Coordinates of the upper left corner of the button.
Names: height and width Size of the button
Name: text Optional text.
Name: relief Set the appearance of the button. Choices are 'flat' and 'raised'. 'raised' is the default.
Name: textColor Text color name for the text. Defaults to black.
Name: texture Optional OpenGL texture name to display on the button.
Name: clickCallback Code reference for the routine to call when the button is clicked (pressed and released).
Name: pressCallback Code reference for the routine to call when the button is pressed but not yet released.
$button->draw; Draw the button.
$button->draw;
GUIiButton - Create push button widget with images for up and down
$button = GUIiButton->new(?options?);
Names: height and width Size of the button.
Name: texture Reference to an array of OpenGL texture names to display on the button to represent the button state.
GUICanvas - Create canvas widget that allows drawing and selection with the mouse
$canvas = GUICanvas->new(?options?);
Name: color Specifies the background color for the canvas as a text string.
Names: x and y Coordinates of the upper left corner of the canvas.
Names: height and width Size of the canvas
Name: relief Set the appearance of the canvas. Choices are 'flat' and 'sunken'. 'sunken' is the default.
Name: clickCallback Code reference for the routine to call when the canvas is clicked (pressed and released). The routine called must perform these calculations to determine the relative x,y on the canvas. my ($x,$y) = ($self->{mouse}{x},$self->{mouse}{y}); $x -= $self->{x}; $y -= $self->{y};
my ($x,$y) = ($self->{mouse}{x},$self->{mouse}{y}); $x -= $self->{x}; $y -= $self->{y};
$canvas->draw; Draw the canvas.
$canvas->draw;
$canvas->create('type',?options?); Create a object on the canvas. type can be 'Circle', 'Line', 'Image', or 'Poly'. The most of the options will depend on type. All types require x and y.
$canvas->create('type',?options?);
type
Name: color Specifies the color for the circle as a text string.
Name: radius Radius of the circle
Name: texture Specifies the texture to display.
Names: height and width Size of the image
Name: color Specifies the color for the line as a text string.
Name: width Width of the line in pixels.
Names: x2 and y2 Coordinates of the 2nd end of the line.
Name: color Specifies the color for the polygon as a text string.
Name: As many pairs of coordinates as are required to describe the polygon. They are not preceeded by an option name.
GUILabel - Create label widget
$label = GUILabel->new(?options?);
Names: x and y Coordinates of the upper left corner of the label.
Names: height and width Size of the area to center the text in. Defaults to 0x0 and label will not display.
Name: text Label text.
$label->draw; Draw the label.
$label->draw;
GUIText - Create text display area
$text = GUIText->new(?options?);
Name: color Specifies the background color for the text display area as a text string.
Names: x and y Coordinates of the upper left corner of the text display area.
Name: text Initial text.
Name: textColor Color name for the text. Defaults to 'black'.
$text->draw; Draw the text.
$text->draw;
$text->insert('more text') Adds the text and scrolls up the old text
$text->insert('more text')
John D. Overmars <overmars@jdovermarsa.com>, and Rob Duncan <duncan@jdovermarsa.com>
The idea for GUI??? was inspired by a C capability by Rob Bateman.
Copyright 2008 John D. Overmars and Rob Duncan, All rights reserved.
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head2'
=back without =over
To install OpenGL::QEng, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenGL::QEng
CPAN shell
perl -MCPAN -e shell install OpenGL::QEng
For more information on module installation, please visit the detailed CPAN module installation guide.