[plt-scheme] MrEd/OpenGL
> > And
> > how come I can't 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.
>
> I'm not enough of a GL expert to know about this one. Is the initial
> state of a GL context defined, or do you have to explicitly clear it?
> (Maybe your code already clears the context...)
>
> Matthew
Got it, thank you. I am not sure why but the reason
(send a-canvas with-gl-context draw-init)
didn't work was because I called it independently before
(send frame show #t)
When I called it after, there was no more random garbage. I am not sure
if that is something in SGL or MrED but I remember seeing an archive post
in this mailing list regarding not being able to get keyboard focus
unless you showed the object in the right position in the program.
Anyway, here is my working code for any interested parties
(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)))
(override on-paint)
(define on-paint (lambda ()
(send a-canvas with-gl-context draw-init)))
(super-instantiate () )))
(define (draw-init)
(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))
(define a-canvas (instantiate my-canvas% (frame) ))
(send frame show #t)