[racket] Strange error with OpenGL in Windows XP

From: Tomás Coiro (tomcoiro at hotmail.com)
Date: Mon Jul 30 23:13:10 EDT 2012

I have version 5.2.1 for windows 32-bit

I'm trying to make an OpenGL program for a roguelike, so, I'm trying to get a frame that can be updated and interacted with.

The problem is that after i practically copied gl-frame and gears to get a canvas class going and started trying simple drawing, i realized that when the canvas worked, the frame just freezed (or froze?).

What i mean is, everything works fine, the polygons are drawn, things are in the right color, things are placed where they should, but after that, when the program stops, the frame just stays there, i can't resize it, i can't move it, i can't close it and i can't interact to it by pressing keys (which i think work fine).

For some strange reason, gears does work fine.

In case it's important, i have a VIA S3G UniChrome Pro IGP graphics card, have windows XP and this is my code

#lang racket
(require sgl

(define WIDTH 800)
(define HEIGHT 800)

(define-syntax (add-key-maps stx)
  (syntax-case stx ()
    ((_ (key fn) ...)
     (syntax (begin
               (add-key-mapping key fn) ...)))))

(define gl-init
  (lambda ()
    (gl-clear-color 0.0 0.0 0.0 0.0)
    (gl-clear 'color-buffer-bit)
    (gl-color 1.0 1.0 1.0)
    (gl-ortho 0.0 1.0 0.0 1.0 -1.0 1.0)))

(define (set-gl-init fn)
  (set! gl-init fn))

(define gl-draw void)

(define (set-gl-draw fn)
  (set! gl-draw fn))

(define *key-mappings* '())

(define (add-key-mapping key fn)
  (set! *key-mappings* (cons (cons key fn) *key-mappings*)))

(define (clear-key-mappings)
  (set! *key-mappings* '()))

(define (gl-handlekey key)
  ((cdr (assoc key *key-mappings*))))

(define init? #f)

(define gl-canvas%
  (class* canvas% ()
    (inherit refresh with-gl-context swap-gl-buffers)
    (define/override (on-size w h)
       (lambda ()
         (gl-viewport 0 0 w h)
    (define/override (on-paint)
       (lambda ()
         (unless init?
           (set! init? #t))
    (define/override (on-char key)
      (gl-handlekey (send key get-key-code))
    (super-new (style '(gl no-autoclear)))))

(define frame (new frame% (label "No name game")))

(define canvas (new gl-canvas% (parent frame)
                               (min-width WIDTH)
                               (min-height HEIGHT)))

(send frame show #t)

(add-key-maps (#\m (lambda ()
                      (lambda () (gl-begin 'polygon)
                        (gl-vertex 0.25 0.75 0.0)
                        (gl-vertex 0.75 0.75 0.0)
                        (gl-vertex 0.75 0.25 0.0)
                        (gl-vertex 0.25 0.25 0.0)
                     (send canvas on-paint)))
              (#\n (lambda ()
                      (lambda () (gl-begin 'polygon)
                        (gl-vertex 0.4 0.6)
                        (gl-vertex 0.6 0.6)
                        (gl-vertex 0.6 0.4)
                        (gl-vertex 0.4 0.4)
                     (set! init? #f)
                     (send canvas on-paint))))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120731/0fcb5234/attachment.html>

Posted on the users mailing list.