[plt-scheme] MrEd/OpenGL

From: Ryan Jarvis (rjarvis at WPI.EDU)
Date: Wed Sep 3 09:08:53 EDT 2003

Here is the initial structure of my code

(require (prefix gl- (lib "sgl.ss" "sgl")))

(define frame (instantiate frame% ("Three Dots") (width 300) (height
300)))

(define my-canvas%
  (class* canvas% ()

    (inherit with-gl-context swap-gl-buffers)

    (override on-event)

    (define on-event (lambda (event)
                       (with-gl-context
                        (lambda () (draw-points)))
                       (swap-gl-buffers)))

    (super-instantiate () )))

(define (draw-init dc)
   (gl-clear-color 1 1 1 0)
   (gl-color 0 0 0)
   (gl-point-size 4)
   (gl-matrix-mode 'projection)
   (gl-load-identity)
   (gl-ortho 0 640 0 480 0 1)
   (gl-clear 'color-buffer-bit))

(define (draw-points)
   (gl-begin 'points)
   (gl-vertex 100 50)
   (gl-vertex 100 130)
   (gl-vertex 150 130)
   (gl-end)
   (gl-flush))

(instantiate my-canvas% (frame))

(send frame show #t)

Now, I was trying to follow along in Ch.5 of the MrEd Manual, Drawing
Toolbox Overview and I added/modified the following lines

(define a-canvas
 (instantiate my-canvas% (frame)
                         (paint_callback (lambda (a-canvas dc)
                                                 (draw-init dc)))))

(define dc (send a-canvas get-gl-context))

I want it to call the initialization whenever the window is exposed,
resized etc.  Then ultimately I want to only call the initialization once
and then call as many (gl-begin)(gl-end) routines as I wish.  If I combine
(draw-init) and (draw-points) into one (draw-points) everything works fine
but it seems silly to re-initialize everytime an event is handled.

However, when I try to execute I get the error
instantiate: unused initialization arguments: (paint_callback etc. etc for
instantiated my-canvas%

Do I need to somehow inherit initialization arguments when I define my own
canvas?  I also tried describing the paint_callback in the
(super-instantiate ()) line for my-canvas, but I get the same error.  And
how come I can just type

(send a-canvas with-gl-context draw-init)

When I do that, I seem to get my (draw-points) working fine but I also get
other random garbage/pixels on the screen.

Thanks.



Posted on the users mailing list.