[gambit-list] glut callbacks
    Eduardo Cavazos 
    wayo.cavazos at gmail.com
       
    Sat Mar 21 21:50:10 EDT 2009
    
    
  
Eduardo Cavazos wrote:
> I was trying out the opengl library from the wiki.
> 
> Some of the functions in the glut library are used to specify callbacks. 
> For example, glutReshapeFunc.
> 
> In the glut libraries of Ypsilon, Larceny, and Chicken, I'm able to pass 
> a Scheme procedure to the 'glutReshapeFunc' procedure.
> 
> Is this doable with Gambit? From the sound of the manual, it seems like 
> this is not yet supported.
OK, the workaround strategy I mentioned is working great.
In my hacked version of the opengl library, this is the code for 
glutReshapeFunc:
----------------------------------------------------------------------
(define *glut-reshape-func* #f)
(c-define (basic-reshape-func width height)
           (int int)
           void
           "basicReshapeFunc"
           ""
           (*glut-reshape-func* width height))
(define (glutReshapeFunc proc)
   (set! *glut-reshape-func* proc)
   ((c-lambda () void " glutReshapeFunc ( basicReshapeFunc ) ; ")))
----------------------------------------------------------------------
glutDisplayFunc is another essential function. The code is similar:
----------------------------------------------------------------------
(define *glut-display-func* #f)
(c-define (basid-display-func)
           ()
           void
           "basicDisplayFunc"
           ""
           (*glut-display-func*))
(define (glutDisplayFunc proc)
   (set! *glut-display-func* proc)
   ((c-lambda () void " glutDisplayFunc ( basicDisplayFunc ) ; ")))
----------------------------------------------------------------------
Given those, Gambit (gsi or gsc) is able to run this test program:
----------------------------------------------------------------------
(load "/root/abstracting/support/gambit/gl/gl")
(load "/root/abstracting/support/gambit/glut/glut")
(basic-glut-init)
(define display-func
   (lambda ()
     (glClearColor 0.0 0.0 0.0 1.0)
     (glClear GL_COLOR_BUFFER_BIT)
     (glColor4d 1.0 1.0 1.0 1.0)
     (glBegin GL_LINES)
     (glVertex2d 10.0 10.0)
     (glVertex2d 90.0 90.0)
     (glEnd)
     (glFlush)))
(define reshape-func
   (lambda (w h)
     (glViewport 0 0 w h)
     (glMatrixMode GL_PROJECTION)
     (glLoadIdentity)
     (glOrtho 0.0 (+ w 0.0) 0.0 (+ h 0.0) -10.0 10.0)
     (glMatrixMode GL_MODELVIEW)))
(glutInitWindowPosition 100 100)
(glutInitWindowSize 500 500)
(glutCreateWindow "Hello GLUT")
(glutDisplayFunc display-func)
(glutReshapeFunc reshape-func)
(glutMainLoop)
----------------------------------------------------------------------
Ed
    
    
More information about the Gambit-list
mailing list