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

I am foolishly trying to use OpenGL inside a Tk application. I am discovering that there is a tremendous lack of documentation on the Perl/OpenGL interfaces. Most POD pages are nothing more than lists of routine names. Pointers to documentation are most welcome.

I want to create an OpenGL window with a depth buffer, so that objects get hidden. The only way I know of to create an OpenGL window is to use OpenGL::glpOpenWindow(), which is deprecated. However, the documentation gives no hint as to what replaces it. My understanding is that the glut library wants to use its own event loop, which doesn't play well with Tk.

I wrote the following test program to see what various options do. The first option works, but the depth buffer goes from 2 bits to 0 bits, and objects don't hide each other. The second option fails, even though the Perl source at cpan.org implies that it should work fine. The third option crashes X Windows.

+ #!/usr/bin/perl -w + use warnings ; use strict ; use lib ('blib') ; use Tk ; # OpenGL: need r:all for glGetIntegerv_p, need :old for glpOpen Window use OpenGL qw(:all :old) ; my $arg = shift ; my $MW = new MainWindow ; # craps out if $border = 0 my $border = 1 ; my ( $w, $h ) = ( 100, 100 ) ; my $glwin ; my @attributes = [ GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 1 ] ; my $id = $MW->WindowId ; my $depth = glGetIntegerv_p( GL_DEPTH_BITS ) ; print "Depth Before = $depth\n" ; $glwin = glpOpenWindow ( x => $border, y => $border, width => $w, height => $h, parent => $$id ) if $arg eq 'A' ; $glwin = glpOpenWindow ( x => $border, y => $border, width => $w, height => $h, parent => $$id, attributes => \@attributes ) if $arg eq 'B' ; $glwin = glpcOpenWindow ( $border, $border, $w, $h, $$id, 0, \@attributes ) if $arg eq 'C' ; $depth = glGetIntegerv_p( GL_DEPTH_BITS ) ; print "Depth After = $depth\n" ;
A returns:
Depth Before = 2 Depth After = 0
B returns:
Depth Before = 2 Not a valid parameter to glpOpenWindow: `attributes' No visual! at /usr/lib/perl5/OpenGL.pm line 6049.
C returns:
Depth Before = 2 X Error of failed request: BadValue (integer parameter out of range f +or operation) Major opcode of failed request: 1 (X_CreateWindow) Value in failed request: 0x2b1af80 Serial number of failed request: 26 Current serial number in output stream: 28

Any suggestions of what to do? Is there a glpOpenWindow() replacement?

Brian

Replies are listed 'Best First'.
Re: Tk & OpenGL
by syphilis (Archbishop) on Oct 07, 2009 at 07:33 UTC
    Is there a glpOpenWindow() replacement?

    There's a demo script in the OpenGL top level source folder ('test.pl') that gets run as part of 'make test', and provides a rotating cube. Does it run ok for you ?

    That script has no mention of glpOpenWindow, or of :old .... afaik, you get your window by calling glutInit() and glutCreateWindow("Window Title").
    In fact, the following is all I need to create a window (albeit an empty one):
    C:\>perl -MOpenGL=":all" -e "glutInit();glutCreateWindow('Test');sleep + 2;"
    Does that 'test.pl' script help you out at all ?

    Cheers,
    Rob
Re: Tk & OpenGL
by biohisham (Priest) on Oct 07, 2009 at 10:54 UTC
    This book can be useful, I am yet to start it but it is so informative that it can alleviate the lack of documentation for Perl/OpenGl, The Official Guide to Learning Open Gl.

    Check this OpenGl Exmaple, this example effectively uses the glut library and as well it does the depth buffers.


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
      OpenGL works fine by itself using glut. It doesn't work with Tk. That is the issue at hand. The only glue available appears to be an undocumented and depreciated subroutine. Sigh.
Re: Tk & OpenGL
by igoryonya (Pilgrim) on Dec 10, 2009 at 05:03 UTC
    I am not too familiar yet with OpenGL. I am still on chapter 3 of OpenGL SuperBible, but would it work for you if you fork the OpenGL, or the Tk interface?
    It would look like Visual Basic or Gimp, etc. separate window interface, but it's a possible solution.

    What do you think?