I need to scale up a png, what am I doing wrong?

36 views
Skip to first unread message

Matt Carter

unread,
Nov 12, 2014, 4:40:55 PM11/12/14
to lispb...@googlegroups.com
Hi all,

I have a small project where I'm playing with lispbuilder (https://github.com/ahungry/sdl-blub), however I cannot for the life of me get the zoom (or rotate) functions to scale, rotate or flip the surface of my loaded image.

A snippet is below:

(defparameter *img-player* (sdl:load-image "~/src/lisp/sdl-blub/assets/sprites/minimal-hero.png"))
(sdl:zoom-surface 2 2 :surface *img-player*)
(sdl:draw-surface-at *img-player* `#(,*x* ,*y*) :cell (aref animation *frame-index*))

Using this code simply renders the image at it's default size (which is a tiny 32x32 cell of a spritesheet).

If I omit the :surface key I receive an error about no default surface defined (yet somehow the draw-surface-at succeeds in copying my *img-player* surface there).

Thanks for any assistance,
-Matt

Matt Carter

unread,
Nov 13, 2014, 11:56:35 AM11/13/14
to lispb...@googlegroups.com
The solution was to call it as follows:


(defparameter *img-player* (sdl:load-image "~/src/lisp/sdl-blub/assets/sprites/minimal-hero.png"))
(setf *img-player* (sdl:convert-to-display-format :surface (lispbuilder-sdl-gfx:zoom-surface 2 2 :surface *img-player*)))
(sdl:draw-surface-at *img-player* `#(,*x* ,*y*) :cell (aref animation *frame-index*))

As a new user of SDL, it wasn't very clear given the documentation that the load-image zoomed surface required a #'convert-to-display-format before it could be drawn.

Great library though!

Elliott Slaughter

unread,
Nov 17, 2014, 5:56:06 PM11/17/14
to lispb...@googlegroups.com
So, it's true that load-image tries to modify the image as minimally as possible (this includes keeping the image in whatever format/bit-depth it was on disk), which might cause problems with blitting to other surfaces.

That said, I think the real issue is the setf call in the second code sample; in the first call, you zoom the image and then immediately throw the result away (it's a new surface, not an in-place modification of the old one). I suspect that if you got rid of the convert-to-display-format but kept the setf it would probably continue to work, though transparency might be off if the formats do actually differ.

Sorry for the slow response and hope that helps.

--
You received this message because you are subscribed to the Google Groups "Lispbuilder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lispbuilder...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Elliott Slaughter

"Don't worry about what anybody else is going to do. The best way to predict the future is to invent it." - Alan Kay
Reply all
Reply to author
Forward
0 new messages