[racket] racket/gui: Problem displaying bitmap data

From: David Vanderson (david.vanderson at gmail.com)
Date: Tue Jun 24 22:29:39 EDT 2014

Alexander,

Not all bitmaps support all operations.  I've modified your program to 
show the bitmap in the frame.  Hopefully this helps, but I'm not sure 
what you are trying to do.  Let me know if you're still having trouble!

Dave


(module ex6 racket/base

   (require srfi/1)
   (require srfi/4)
   (require srfi/9)
   (require racket/class)
   (require racket/gui/base)

   (define-record-type game-screen
     (make-game-screen width height data)
     game-screen?
     (width game-screen-width)
     (height game-screen-height)
     (data game-screen-data))

   (define (initialize-screen)
     (let* ((d (make-u8vector (* 4 320 200) 0)))
       (do ((i 0 (+ i 4))) ((>= i (* 4 320 200)) #f)
         (for-each (lambda (e)
                     (u8vector-set! d (+ i (car e)) (cadr e)))
                   (zip (list 0 1 2 3) (list 200 0 0 255))))
       (make-game-screen 320 200 d)))

   (define *the-screen* (initialize-screen))

   (define bitmap (make-bitmap
                   (game-screen-width *the-screen*)
                   (game-screen-height *the-screen*)))

   (send bitmap set-argb-pixels 0 0
         (game-screen-width *the-screen*)
         (game-screen-height *the-screen*)
         (game-screen-data *the-screen*)
         #f #f)

   (define (draw-screen canvas dc)
     (send dc draw-bitmap bitmap 0 0))

   (define (main)
     (let* ((the-toplevel-frame (new frame% (label "Raycaster 3D!") 
(width 500) (height 500)))
            (the-canvas (new canvas% (parent the-toplevel-frame) 
(paint-callback draw-screen))))
       (send the-toplevel-frame show #t)))

   (main))



On 06/24/2014 08:28 PM, Alexander Shendi wrote:
> Hello all,
>
> I'm attaching (and including inline) a simple test-case that can be run via:
>   racket -t ex6.rkt
>
> Thanks in advance for your help.
>
> Best Regards,
>
> Alexander
>
> ----------------------------------------------------------------------------------------------
>   
>   (module ex6 racket/base
>    
>    (require srfi/1)
>    (require srfi/4)
>    (require srfi/9)
>    (require racket/class)
>    (require racket/gui/base)
>    
>    (define-record-type game-screen
>      (make-game-screen width height data)
>      game-screen?
>      (width game-screen-width)
>      (height game-screen-height)
>      (data game-screen-data))
>    
>    (define (initialize-screen)
>      (let* ((d (make-u8vector (* 4 320 200) 0)))
>        (do ((i 0 (+ i 4))) ((>= i (* 4 320 200)) #f)
>          (for-each (lambda (e)
>                      (u8vector-set! d (+ i (car e)) (cadr e)))
>                    (zip (list 0 1 2 3) (list 200 0 0 255))))
>        (make-game-screen 320 200 d)))
>
>    (define *the-screen* (initialize-screen))
>      
>    (define (main)
>      (let* ((the-toplevel-frame (new frame% (label "Raycaster 3D!")))
>             (the-canvas (new canvas% (parent the-toplevel-frame)))
>             (the-canvas-bitmap (send the-canvas make-bitmap
>                                      (game-screen-width *the-screen*)
>                                      (game-screen-height *the-screen*)))
>             (the-canvas-bitmap-dc (new bitmap-dc% (bitmap the-canvas-bitmap))))
>        (send the-canvas-bitmap-dc set-argb-pixels 0 0
>                                  (game-screen-width *the-screen*)
>                                  (game-screen-height *the-screen*)
>                                  (game-screen-data *the-screen*)
>                                  #f #f)
>        (send the-toplevel-frame show #t)))
>      
>    (main))
>
> ----------------------------------------------------------------------------------------------
>
> Gesendet: Dienstag, 24. Juni 2014 um 20:25 Uhr
> Von: "Alexander Shendi" <alexander.shendi at web.de>
> An: users at racket-lang.org
> Betreff: [racket] racket/gui: Problem displaying bitmap data
> Dear list,
>   
> I am trying to display bitmap data that I have written into a SRFI-4 u8vector (that  I believe maps to a Racket
> bytevector). The bitmap data is in RGBA format. Now I am trying to display the bitmap data in a window.
> Please see the relevant part of my program below:
>
> (define (main)
> (let* ((the-toplevel-frame (new frame% (label "Raycaster 3D!")))
> (the-canvas (new canvas% (parent the-toplevel-frame)))
> (the-canvas-bitmap (send the-canvas make-bitmap
> (game-screen-width *the-screen*)
> (game-screen-height *the-screen*)))
> (the-canvas-bitmap-dc (new bitmap-dc% (bitmap the-canvas-bitmap))))
> (for-each (lambda (e) (apply vline e)) (raycast-all *game-map*)) ;; Application logic :)
> (send the-canvas-bitmap-dc set-argb-pixels 0 0
> (game-screen-width *the-screen*)
> (game-screen-height *the-screen*)
> (game-screen-data *the-screen*)
> #f #f)
> (send the-toplevel-frame show #t)))
>
> However this results in the error message:
>
> $ racket -t game6.rkt
>
> [Debug output of program snipped] ...
>
> set-argb-pixels in bitmap%: not available in a canvas-compatible bitmap: (object:x11-bitmap% ...)
> context...:
> /usr/local/share/racket/pkgs/draw-lib/racket/draw/private/bitmap.rkt:776:4: core404
> /home/alexshendi/sources/racket/game/game6.rkt:366:2: main
> /home/alexshendi/sources/racket/game/game6.rkt: [running body]
>
>
> Operating System: Linux x86_64 (Ubuntu 14.04)
> Racket Version: 6.0.1 (Release)
>
> Can anyone help me do it the correct way? Many thanks in advance.
>
> Best Regards,
>
> Alexander
> ~
> ~
> ~
> ~
> ~
> ~
> ~
> ~
> ~
> ~
> ~
> ~
>
>
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
>
> ____________________
>    Racket Users list:
>    http://lists.racket-lang.org/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140624/d0c71b5d/attachment-0001.html>

Posted on the users mailing list.