Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

RFC - 3D Graphics Programming In Perl -- Resource List

by mmmmtmmmm (Monk)
on Sep 05, 2007 at 13:19 UTC ( [id://637148]=perlmeditation: print w/replies, xml ) Need Help??

Hello --

An earlier post led me to discover that there was no good list of resources here on using Perl for 3D graphics rendering. So I set out to learn a bit about it, and wrote up a draft with what I found. This could definitely use some improvement, so please respond with things that you would like added to the list.

Here's what I've got so far -- more is on the way:


3D Graphics Programming In Perl

Perl is very well suited for generating and rendering complex 3D objects and environments. It's builtin string and array handling functions make it well suited for manipulating large arrays of pixels and vertices -- a common task for most 3D graphics applications. You can cast all worries aside that you will need a "faster" language like C/C++. Several benchmarks have found Perl to be as fast, and often faster than other languages such as C and Python at many common types of complex rendering tasks.

OpenGL

OpenGL is by far the most commonly used graphics API for both 2D & 3D graphics. It provides hundreds of functions for creating and displaying 3D objects and environments. OpenGL is written in C, and its documentation is written for C programmers. But even if you know very little or no C, the syntax for passing arguments to subroutines in C is similar enough to that of Perl, that you should be able to figure out which arguments you need to pass to each library function. It is a fairly trivial (albeit boring & tedious) task to convert OpenGL library calls written in C, to the proper Perl format. Most of the Perl OpenGL functions work exactly the same as their C counterparts -- same names, same arguments.

Below are some resources to get you up to speed OpenGL in general. These are all in C, but you will need to read them, even if you only plan to use the Perl modules. The documentation for the Perl OpenGL bindings lists the OpenGL functions they support, but does not describe what each function does or how to use them. For a full listing of what each function does, and what inputs it takes, you will have to look at the C API documentation.

This site has an excellent set of tutorials on OpenGL programming. They are all in C, however many of them contain links at the bottom for the equivalent Perl code:

Nehe's OpenGL Tutorials

Here's a nice introductory series from O'Reilly on OpenGL:

Creating Realtime 3D Graphics With OpenGL
Preparing to Build An OpenGL Application
OpenGL Rendering & Drawing

And here are two good tutorials on GLUT and GLSL:

GLUT Tutorial
OpenGL Shading Language Tutorial

Perl Bindings For OpenGL

Perl OpenGL (POGL) and SDL::OpenGL (Simple Direct Media Layer) are the two most developed Perl modules for rendering both 2D & 3D graphics, using the OpenGL libraries. The POGL module was found to perform significantly better than SDL::OpenGL in several benchmarking tests, when rendering OpenGL graphics. This is because, as they say on the POGL site:

SDL's primary focus is to provide a comprehensive collection of tools for imaging, audio and video; OpenGL is provided as a convenience, but not central to its core features. POGL focuses solely on OpenGL, and is able to tune its APIs for the best possible OpenGL performance in a Perl environment. Innovations such as POGL's OpenGL::Array objects provide significant advantage (in performance and ease of use) over SDL::OpenGL's packed string APIs. This focus also allows POGL to stay ahead of other Perl bindings in terms of support for OpenGL extensions, like VBOs, FBOs and Vertex/Fragment Programs.

The POGL documentation is basically just a list of OpenGL functions that are supported, but it contains no definitions for these functions. This is not surprising, since all of the POGL functions work exactly like their C counterparts -- why rewrite the already extensive OpenGL documentation, if all you will be doing is replacing "int width" with "$width", and "int draw_frame()" with "sub drawframe{}"?

Sorry folks, there is no way around it -- you are going to have to learn a bit of C and study the documentation for the OpenGL API in order to use the Perl OpenGL bindings. To look up a function listed in the POGL documentation, just type man gl_function_name in your shell.

This, by the way, might make it easier on you:

Converting OpenGL Code From C to Perl

OGRE

At the request of LTjake, I looked up OGRE 3D, and it seems very interesting -- although I don't really know enough about it to make a good judgement. OGRE 3D is an open source, rendering engine written in C++. There is also a new Perl module for OGRE 3D on CPAN. The OGRE 3D documentation is extensive and very well maintained. They also have an excellent wiki, which contains many high quality tutorials, ranging in difficulty from easy to advanced. Everything you need to get started should be in their Wiki :

Official documentation:

OGRE 3D Wiki

OGRE Manual

OGRE API Reference

And a link to the OGRE Perl Module:

Ogre

Using SDL w/ Perl

While Perl OpenGL outperforms SDL::OpenGL, it lacks some of the other capabilities that the SDL libraries possess. The two are often used together -- POGL to deal with the OpenGL rendering, and SDL for things that OpenGL doesn't handle like setting up a display window, audio, handling I/O events (mouse/keyboard/joystick/etc.), and other things. The official documentation for the SDL libraries is somewhat informative, but you will have to know a bit of C to be able to understand it:

SDL Introduction

The official documentation for the Perl SDL modules is somewhat helpful, and even contains a brief set of simple tutorials. These are worth looking over to learn a few basic concepts, before moving on to some of the more advanced guides:

Perl SDL Tutorials

This is a very in depth tutorial on SDL and Perl:

Developing Games With Perl & SDL

And if you still want to use SDL::OpenGL, instead of the (faster) POGL modules, check out this article:

Building a 3D Engine

Other Things That Will Help You

Learn To Program In C

Most of the documentation and tutorials for the SDL and OpenGL libraries is geared towards C/C++ programmers. Both of them are written in C, and therefore, it will be a great help if you have at least basic knowledge of C so that you can understand the wealth of graphics programming documentation that uses these languages. Check out The C Programming Language by Brian Kernighan & Dennis Ritchie, if you want to learn the basics of C programming. This is definitely the best book out there on the subject -- it's the "Programming Perl" of the C language. But if you aren't the type to buy books, then perhaps the following tutorial will be of assistance:

This is an excellent introductory->intermediate level C tutorial. I highly recommend it:
C Programming Tutorial

and this one provides a good reference to some useful Unix system functions

Programming in C: Unix System Calls & Subroutines - by A.D. Marshall

And here's another, more basic (and short) tutorial to get you quickly up to speed:
C Programming - by Steve Holmes

Learn Some Basic Math

A basic understanding of trigonometry, linear algebra, and vectors will definitely come in handy for more complex rendering tasks. Here are some useful mathematics resources:

Here is a decent set of tutorials if you need a refresher on math basics:

S.O.S. Math

Here is a very basic introduction to trigonometry:

Short Course In Trigonometry

This site is a very helpful linear algebra reference:

Vectors
Matrices
Linear Equations



Hopefully, after you've read the stuff above, you should be able to figure out where to go from here.

---mmmmtmmmm

Replies are listed 'Best First'.
Re: RFC - 3D Graphics Programming In Perl -- Resource List
by LTjake (Prior) on Sep 06, 2007 at 00:49 UTC
      Thanks for the suggestion.

      I checked out OGRE and it looks like a very neat project. I haven't had much of a chance to play around with it yet, but if it is as well designed as their documentation and website, then I'm in for a treat.

      I added some links to their website, and some of their documentation. Also added a link to the Ogre modules on CPAN.

      ----mmmmtmmmm
Re: RFC - 3D Graphics Programming In Perl -- Resource List
by ForgotPasswordAgain (Priest) on Sep 05, 2007 at 13:46 UTC
    Several benchmarks have found Perl to be as fast, and often faster than other languages such as C and Python at many common types of complex rendering tasks.

    Link please? I think we have to be clear what we mean by "Perl" (and "Python") here, at least if we consider POGL to be Perl.

Re: RFC - 3D Graphics Programming In Perl -- Resource List
by sfink (Deacon) on Sep 06, 2007 at 19:52 UTC
    I use OpenGL::Simple pretty heavily, since I found it much easier to get running than SDL::OpenGL, and POGL didn't exist when I started out. Unfortunately, it's pretty bare-bones -- as in, it only wraps a subset of the OpenGL API. (OpenGL has lots and lots of extensions, some of which are necessary for doing anything interesting these days. But they are unevenly supported by drivers and hardware.) I have had to add several dozen API entries myself, and fix up a few others.

    On the other hand, I fully intend to switch to POGL as soon as I find some time.

Re: RFC - 3D Graphics Programming In Perl -- Resource List
by girarde (Hermit) on Sep 05, 2007 at 21:34 UTC
    This is pretty cool, but would have been very cool with <readmore> tags.
      Good call...I added the <readmore> tags.

      ----mmmmtmmmm
Re: RFC - 3D Graphics Programming In Perl -- Resource List
by greengaroo (Hermit) on Jun 28, 2013 at 14:54 UTC

    Thank you for this post!

    A for will get you from A to Z; a while will get you everywhere.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://637148]
Approved by moritz
Front-paged by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-03-19 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found