NAME

GUI??? - Library for implementing GUIs with OpenGL

SYNOPSIS

  # 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);
}

DESCRIPTION

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.

Basic Overview

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.

OBJECT DESCRIPTIONS

The GUI??? is composed of the GUIWindow, GUIFrame, GUIButton, GUICanvas, and GUIText objects.

OBJECT NAME

GUIWindow - Create a window to hold 2D widgets. GUIWindow is a subclass of GUIFrame.

SYNOPSIS

$guiWindow = GUIWindow->new(?options?);

OPTIONS

Name: GLwindow Specifies the OpenGL window that the subwindow will be placed in

Also, accepts all the options of a GUIFrame.

METHODS

$guiWindow->adopt(widget); Add a widget to the window.

$guiWindow->draw; Draw the window and all its children

SPECIAL METHODS

These methods are not normally called directly. They are passed to glut.

$guiWindow->draw(@_); Passed to glutDisplayFunc.

$guiWindow->mouseButton(@_); Passed to glutMouseFunc.

$guiWindow->mouseMotion(@_); May be passed to glutMotionFunc.

$guiWindow->mousePassiveMotion(@_); May be passed to glutPassiveMotionFunc.

OBJECT NAME

GUIFrame - Create frame to hold 2D widgets

SYNOPSIS

$guiFrame = GUIFrame->new(?options?);

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.

METHODS

$guiFrame->adopt(widget); Add a widget to the frame.

$guiFrame->draw; Draw the frame and all its children

OBJECT NAME

GUIButton - Create push button widget

SYNOPSIS

$button = GUIButton->new(?options?);

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.

METHODS

$button->draw; Draw the button.

OBJECT NAME

GUIiButton - Create push button widget with images for up and down

SYNOPSIS

$button = GUIiButton->new(?options?);

OPTIONS

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: textColor Text color name for the text. Defaults to black.

Name: texture Reference to an array of OpenGL texture names to display on the button to represent the button state.

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.

METHODS

$button->draw; Draw the button.

OBJECT NAME

GUICanvas - Create canvas widget that allows drawing and selection with the mouse

SYNOPSIS

$canvas = GUICanvas->new(?options?);

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};

METHODS

$canvas->draw; Draw the canvas.

$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 OBJECTS

Circle - Circle (really a disk) on the canvas

Options

Name: color Specifies the color for the circle as a text string.

Name: radius Radius of the circle

Image - Image on the canvas

Options

Name: texture Specifies the texture to display.

Names: height and width Size of the image

Line - Line on the canvas

Options

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.

Poly - Filled polygon on the canvas

Options

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.

OBJECT NAME

GUILabel - Create label widget

SYNOPSIS

$label = GUILabel->new(?options?);

OPTIONS

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 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.

Name: textColor Text color name for the text. Defaults to black.

METHODS

$label->draw; Draw the label.

OBJECT NAME

GUIText - Create text display area

SYNOPSIS

$text = GUIText->new(?options?);

OPTIONS

Name: color Specifies the background color for the text display area 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 text display area.

Name: relief Set the appearance of the canvas. Choices are 'flat' and 'sunken'. 'sunken' is the default.

Name: text Initial text.

Name: textColor Color name for the text. Defaults to 'black'.

METHODS

$text->draw; Draw the text.

$text->insert('more text') Adds the text and scrolls up the old text

AUTHORS

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

Copyright 2008 John D. Overmars and Rob Duncan, All rights reserved.

LICENSE

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:

Around line 511:

You forgot a '=back' before '=head2'

Around line 557:

=back without =over