Hello monks,

Occasionally I am playing with 3D graphics. I had some fun doing it in a Tk::Canvas, but ... as the complexity of the 3D objects increases, that's getting painfully slow. So I've been looking for alternatives, starting with OpenGL.

I could not fail noticing that the Perl OpenGL project is a bit stale, with a newsfeed ending in 2007. On the plus side, I succeeded in translating the examples from The Official Guide to Learning OpenGL, Version 1.1 from C to Perl rather easily. Fortunately, this guide is about the same age as the Perl module.

Things get a bit murky when I want to integrate OpenGL drawing into my Tk application. The examples directory in the OpenGL distribution contains a tk_demo.pl script, and hooray, this script works out of the box.

But: This script integrates the OpenGL window with a subroutine glpOpenWindow. This subroutine is part of the Perl module OpenGL, but not exactly documented, and also not part of any OpenGL standard. The C examples in the Guide (and many other examples I found online) use GLUT functions like glutCreateWindow: this function is well documented in OpenGL, and also offered by the OpenGL module. Unfortunately glutCreateWindow creates a top-level window, whereas I would like to use it within my Tk widget. Windows created with glpOpenWindow can use a Tk widget as "parent", but I have no idea how to do the equivalent of GLUT functions like glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); for this window. The call doesn't fail, it just doesn't do anything. Some GLUT functions, e.g. glutFullScreen, bail out with a freeglut message ERROR: Function <glutFullScreen> called with no current window defined.

So that's the question: Has someone a pointer or example how to use the GLUT window subroutines within a Tk widget? Or, as an alternative, how to get a depth buffer activated with a glpOpenWindow window?

BTW: Prima offers Prima::GLWidget which is a direct widget for OpenGL drawing. This works nicely, and I could re-write my Tk applicaton for Prima. Only, I'm not familiar with Prima, and would prefer to avoid the effort.


In reply to Graphics: OpenGL in Perl/Tk ... with GLUT by haj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.