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


In reply to Tk & OpenGL by skewray

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.