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.
A returns:+ #!/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" ;
B returns:Depth Before = 2 Depth After = 0
C returns:Depth Before = 2 Not a valid parameter to glpOpenWindow: `attributes' No visual! at /usr/lib/perl5/OpenGL.pm line 6049.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |