Important alert: (current site time 7/15/2013 9:25:16 PM EDT)
 

VB icon

OpenGL

Email
Submitted on: 5/30/2003 3:48:26 PM
By: Damian myerscough  
Level: Advanced
User Rating: Unrated
Compatibility: 5.0 (all versions), 4.0 (all versions), 3.0 (all versions), Pre 3.0
Views: 7900
 
     This code is to show you that you can do OpenGL in Perl this example was done by a friend of mine called: Jenkins

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: OpenGL
= Description:This code is to show you that you can do OpenGL in Perl this example was done by a friend of mine called: Jenkins
= By: Damian myerscough
=
= Returns:Graphics
=
= Assumes:Installing OpenGL
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=474&lngWId=6=for details.=**************************************

#! /usr/bin/perl -w
#
# This was coded By; Jenkins a friend of mine the reason
# I uploaded this was to get the perl section live again ;)
# Hope you enjoy this.
#
#
#
use OpenGL qw(:all); # Use the OpenGL module
use strict;# Use strict typechecking
use constant ESCAPE => 27;
my $window;
my $rtri = 0.0;
my $rquad = 0.0;
sub InitGL {
 my ($width, $height) = @_;
 glClearColor(0.0, 0.0, 0.0, 0.0);
 glClearDepth(1.0); 
 glDepthFunc(GL_LESS);
 glEnable(GL_DEPTH_TEST);
 glShadeModel(GL_SMOOTH); 
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity;
 gluPerspective(45.0, $width/$height, 0.1, 100.0);
 glMatrixMode(GL_MODELVIEW);
}
sub ReSizeGLScene {
 my ($width, $height) = @_;
 if ($height == 0) { $height = 1; }
 glViewport(0, 0, $width, $height);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity;
 gluPerspective(45.0, $width/$height, 0.1, 100.0);
 glMatrixMode(GL_MODELVIEW);
}
sub DrawGLScene {
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
 glLoadIdentity;
 # dont worry about this stuff below its just the dimentions of the objects and the nice gradient affects that it has
 glTranslatef(-1.5, 0.0, -6.0); 
 glRotatef($rtri, 0.0, 1.0, 0.0); 
 glBegin(GL_POLYGON);
 glColor3f(1.0, 0.0, 0.0);
 glVertex3f(0.0, 1.0, 0.0);
 glColor3f(0.0, 1.0, 0.0);
 glVertex3f(-1.0, -1.0, 1.0);
 glColor3f(0.0, 0.0, 1.0);
 glVertex3f(1.0, -1.0, 1.0);
 glColor3f(1.0, 0.0, 0.0);
 glVertex3f(0.0, 1.0, 0.0);
 glColor3f(0.0, 0.0, 1.0);
 glVertex3f(1.0, -1.0, 1.0);
 glColor3f(0.0, 1.0, 0.0);
 glVertex3f(1.0, -1.0, -1.0);
 glColor3f(1.0, 0.0, 0.0);
 glVertex3f(0.0, 1.0, 0.0);
 glColor3f(0.0, 1.0, 0.0);
 glVertex3f(1.0, -1.0, -1.0);
 glColor3f(0.0, 0.0, 1.0);
 glVertex3f(-1.0, -1.0, -1.0);
 glColor3f(1.0, 0.0, 0.0);
 glVertex3f(0.0, 1.0, 0.0);
 glColor3f(0.0, 0.0, 1.0);
 glVertex3f(-1.0, -1.0, -1.0);
 glColor3f(0.0, 1.0, 0.0);
 glVertex3f(-1.0, -1.0, 1.0);
 glEnd;
 glLoadIdentity;
 glTranslatef(1.5, 0.0, -6.0); 
 glRotatef($rquad, 1.0, 1.0, 1.0);
 glColor3f(0.5, 0.5, 1.0);
 glBegin(GL_QUADS);
 glColor3f(0.0, 1.0, 0.0);
 glVertex3f(1.0, 1.0, -1.0);
 glVertex3f(-1.0, 1.0, -1.0);
 glVertex3f(-1.0, 1.0, 1.0);
 glVertex3f(1.0, 1.0, 1.0);
 glColor3f(1.0, 0.5, 0.0);
 glVertex3f(1.0, -1.0, 1.0);
 glVertex3f(-1.0, -1.0, 1.0);
 glVertex3f(-1.0, -1.0, -1.0);
 glVertex3f( 1.0, -1.0, -1.0);
 glColor3f(1.0, 0.0, 0.0);
 glVertex3f(1.0, 1.0, 1.0);
 glVertex3f(-1.0, 1.0, 1.0);
 glVertex3f(-1.0, -1.0, 1.0);
 glVertex3f(1.0, -1.0, 1.0);
 glColor3f(1.0, 1.0, 0.0);
 glVertex3f(1.0, -1.0, -1.0);
 glVertex3f(-1.0, -1.0, -1.0);
 glVertex3f(-1.0, 1.0, -1.0);
 glVertex3f(1.0, 1.0, -1.0);
 glColor3f(0.0, 0.0, 1.0);
 glVertex3f(-1.0, 1.0, 1.0);
 glVertex3f(-1.0, 1.0, -1.0);
 glVertex3f(-1.0, -1.0, -1.0);
 glVertex3f(-1.0, -1.0, 1.0);
 glColor3f(1.0, 0.0, 1.0);
 glVertex3f(1.0, 1.0, -1.0);
 glVertex3f(1.0, 1.0, 1.0);
 glVertex3f(1.0, -1.0, 1.0); 
 glVertex3f(1.0, -1.0, -1.0); 
 glEnd;
 $rtri = $rtri + 15.0; 
 $rquad = $rquad - 15.0; 
 glutSwapBuffers;
}
sub keyPressed {
 my ($key, $x, $y) = @_;
 sleep(100);
 if ($key == ord('f')) {
 glutReshapeWindow(640, 480);
 }
 if ($key == ESCAPE) 
 { 
 glutDestroyWindow($window); 
 exit(0); 
 }
}
glutInit; 
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); 
glutInitWindowSize(640, 480); 
glutInitWindowPosition(0, 0); 
$window = glutCreateWindow("Perl's OpenGL"); 
glutDisplayFunc(\&DrawGLScene); 
glutFullScreen;
glutIdleFunc(\&DrawGLScene);
glutReshapeFunc(\&ReSizeGLScene);
glutKeyboardFunc(\&keyPressed);
InitGL(640, 480);
glutMainLoop; 
return 1;


Other 35 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.