in reply to XS prototype (or not) problem?

glColor3f( @$ref ); fails!

Can't reproduce the problem:
C:\_32\comp\OpenGL>perl -MOpenGL -e "@x=1.0,0.0,0.0);$ref=\@x,OpenGL:: +glColor3f(@$ref)" C:\_32\comp\OpenGL>
Which version of OpenGL ? (I have the upcoming 0.57 built from svn source - so it may be that an old problem has been fixed.)

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: XS prototype (or not) problem? (Solved)
by BrowserUk (Patriarch) on Jul 24, 2008 at 08:30 UTC

    I don't get an error if I do that either, but (I think) that's because nothing has been initialised yet. Try this:

    #! perl -slw use strict; use OpenGL qw[ :all ]; print "Version: ", $OpenGL::VERSION; glutInit(); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA + ); glutInitWindowSize( 1024, 768 ); my $main = glutCreateWindow( 'OGL1' ); glutDisplayFunc( \&render ); glutMainLoop(); sub render { glClearColor( 1, 1, 1, 1 ); glClear(GL_COLOR_BUFFER_BIT); drawPolygon( #### One too many arguments!!! (I'd added an alpha value) [ 1.0, 0.0, 0.0, 0.0 ], # red [ 0.25, 0.25, 0.25 ], [ 0.75, 0.25, 0.25 ], [ 0.75, 0.75, 0.25 ], [ 0.25, 0.75, 0.25 ], ); glutSwapBuffers(); } sub drawPolygon { glBegin(GL_POLYGON); ## glColor3f( @{ shift() }[ 0, 1, 2 ] ); ## Works glColor3f( @{ shift() } ); ## Fails glVertex3f( @$_ ) for @_; glEnd(); }

    Switch the comment card in drawPloygon to see it work.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      sub drawPolygon { glBegin(GL_POLYGON); ## glColor3f( @{ shift() }[ 0, 1, 2 ] ); ## Works glColor3f( @{ shift() } ); ## Fails glVertex3f( @$_ ) for @_; glEnd(); }
      In the call that works glColor3f() receives 3 arguments. In the call that fails glColor3f() receives 4 arguments - which rightly warrants a "Usage" error. The following rendition of sub drawPolygon works fine for me:
      sub drawPolygon { glBegin(GL_POLYGON); my $arg = shift; pop(@$arg); ## glColor3f( @{ shift() }[ 0, 1, 2 ] ); ## Works glColor3f( @{ $arg } ); glVertex3f( @$_ ) for @_; glEnd(); }
      Update: Duh, you'd already worked it out for yourself. I missed the "Solved" and didn't pay attention to the comments.

      Cheers,
      Rob