Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I really don't like asking such a question but I need a simple example for perl opengl. Normally I am writing a protein folding program with perl and perl PDL. It has a user interface for commands but not a graphics interface for displaying the model program uses (it is not like the normal atomistic models, lets say it is more geometric). I tried to use PDL modules but I could not get PGPLOT or TriD to work. I am still trying on it. I can very easily do what I want in matlab in like 10 seconds but I wont be able to distribute it with my program. All I am left to is hardcore opengl module in perl with no what soever knowledge on opengl. All I ask is tell me how to draw cylinders and sphere using commands like gluSphere(), plot them. And also I want to deform the coordinates of sphere so that I can transform them into sphere. That would be how can I multply the y or x or z coordinates of vertices defining such a created object? Or have can I apply rotation matrices to the vertices of an objected created in such a way. I am still looking for tutorials on the web but I dont really have much time to lose on this and I dont want to do it in matlab. I have looked to few samples and tutorials in POGL page but they all seem to use vertices not predefined objects in glu. Thanks...

Replies are listed 'Best First'.
Re: Perl Opengl Question
by jethro (Monsignor) on Jul 12, 2008 at 15:10 UTC
    If PGPLOT or TriD have the capabilities you want, why don't you show us the code you can't get to work. If that is too large, strip the uninteresting parts from it or write a minimal test case.

    That way every monk may be able to help you instead of only those who dabbled in hardcore OpenGL

Re: Perl Opengl Question
by syphilis (Archbishop) on Jul 12, 2008 at 22:23 UTC
    I tried to use PDL modules but I could not get PGPLOT or TriD to work

    How about PDL's GD capabilities (PDL::IO::GD). Can it produce the graphics you want ?

    Cheers,
    Rob
      I looked at the module you mentioned it is only 2d. I also now looked at PGPLOT, I now see that it is also for only 2 dimensions. So all I am left to is either learn perl opengl, get PDL:TriD working somehow or do it with matlab and just distribute that part as a code to those who own a copy of matlab.
        Anyone with opengl knowledge to answer this question? I hope the answer is easy... If there is no one I assume I will have to seek opengl forums

        I personally believe that a (perlishly) OT solution may be given in terms of Scilab since the latter is "free enough" - if your concern is to only have to restrict to people holding a regular MATLAB license. In fact, I don't even know Scilab, but for the fact that it's similar in functionality to MATLAB, and its syntax is largely based on that of the latter, although the two are known not to be completely compatible. However "there is a converter included in Scilab for MATLAB=>Scilab Conversions." Thus that may be an option.

        --
        If you can't understand the incipit, then please check the IPB Campaign.
      I found a wrong statement in my message ''And also I want to deform the coordinates of sphere so that I can transform them into sphere'' would be ellipsoid at the very end. As for the replies, I have tried PDL but was not able to get it working for TriD or PGPLOT (findows plays a role here I assume). I havent heard of the other module you mentioned, but I will try it as soon as possible thanks
Re: Perl Opengl Question
by Anonymous Monk on Jul 15, 2008 at 14:40 UTC

    I think you're on the right track with POGL. It's the most actively maintained of the Perl-OpenGL bindings. Check out the examples directory that comes with the distribution.

    If you're starting from zero with OpenGL, I can tell you that it's just a simple state machine. You tell it where things are in the universe, and it draws them while you're telling it to. Whatever the current drawing color, lighting settings, model-view matrix, etc., it just does what you tell it to according to its current state.

    Using the glu* commands to draw shapes is very easy. Just remember to set up things first (color, light, etc.) before calling them.

    Couple quick tips:

    • Always draw in double-buffered mode. This means that you have 2 buffers: one that's being shown in the window, and the other that you're drawing on. When you're done drawing, you swap the buffers and what you just drew shows up on the screen.
    • The Perl binding to OpenGL is very similar to OpenGL's C API. This means you can read OpenGL docs and tutorials, and very easily convert the code samples to work in your Perl programs.

      Almost forgot: you probably want to use glut to do your windowing and to capture any user input you're interested in (keystrokes and mouse clicks). It's very simple to learn, cross-platform, standard, and has a free implemenation (freeglut).

        BTW - the latest rev of POGL (in SVN) adds FreeGLUT support (which catches close events).

        I'll be posting this to CPAN in the next week or so.

      Thanks for the POGL plug, Anon :^)

      You can find the following at POGL:

      If that doesn't help, send me an email at grafman-at-graphcomp.com