Hello.

Sorry, it took some time for me to answer.

> Hi Christoph
>
> Sounds like a good idea.
>
> http://gpwiki.org/index.php/SDL:Tutorials:Displaying_a_Bitmap_from_a_Custom_Resource_File_using_SDL_RWops
>
> This web page shows you what you need to do in C. So what you'd need
> to do is load the bmp or png as a binary file into an array of bytes.
>
> When you load your image you need to allocate an array of unsigned
> char, using cffi, and copy the lisp byte array into this one, as I
> don't think SDL will like the binary format of the lisp array.
>
> The you should be able to copy this roughly into lispbuilder-sdl calls...
>
> SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
> SDL_Surface *temp = SDL_LoadBMP_RW(rw, 1);
>
> Something like this
>
> (setf rw (sdl-cffi::sdl-rw-from-mem buffer size))
> (setf temp (sdl-cffi::SDL-Load-BMP-RW rw 1))
>
> Hope this helps,
>
> Justin

Thank you. Yes, it helped. The following code seems to under CLISP:

(defun file-to-byte-array (filepath)
  "Load a file into an Array of unsigned-byte 8"
  (with-open-file (str filepath :element-type '(unsigned-byte 8))
    (let* ((length (file-length str))
           (content (make-array (list length)
                                :element-type '(unsigned-byte 8)
                                :adjustable nil)))
      (read-sequence content str)
      content)))

(defun load-image-from-byte-sequence (byteseq)
  (make-instance 'sdl:surface
                 :surface
                 (sdl-cffi::sdl-load-bmp-rw
                  (sdl-cffi::with-foreign-string (str byteseq)
                    (sdl-cffi::sdl-rw-from-mem str (length byteseq)))
                  1)))

(sdl:with-init ()
    (sdl:window 400 400)
    (sdl:draw-surface (load-image-from-byte-sequence
(file-to-byte-array "/some/file.bmp")))
    (sdl:update-display)
    (sdl:with-events ()
      (:quit-event () t)
      (:video-expose-event (sdl:update-display))))

However, under SBCL, I get errors /sometimes/. ":SURFACE must be a
foreign pointer to an SDL_Surface, or :WIDTH and :HEIGHT must
specified." is the error-message. As far as I saw, the constructor of
sdl:surface calls sdl-base:is-valid-ptr. To determine the error, I
replaced its definition by the (equivalent) definition

(defun sdl-base::is-valid-ptr (pointer)
             (if (cffi:pointerp pointer)
                 (if (not (cffi:null-pointer-p pointer)) t (format t 
"Null-Pointer"))
                 (format t "No-Pointer")))

and recompiled the functions from sdl/surfaces.lisp. The output is
"Null-Pointer". So it seems that it is a Null-Pointer /sometimes/.
Sometimes SBCL just does nothing - it shows a black Window, with no
Graphic appearing. No error, nothing. Even when using convert-surface,
nothing happens. Even though replacing sdl:draw-surface by cl:write
sais, the object is a Surface. When setting the second Argument of
sdl-cffi::sdl-load-bmp-rw to 0, then also under CLISP I have no
problem, under SBCL I get a Memory Fault.

I dont know what I could be doing wrong. Any suggestions?

Christoph Senjak
_______________________________________________
application-builder mailing list
[email protected]
http://www.lispniks.com/mailman/listinfo/application-builder

Reply via email to