[PATCH] SDL rotozoomSurface

83 views
Skip to first unread message

karsten....@4t2.co.uk

unread,
Apr 12, 2013, 7:32:00 PM4/12/13
to emscripte...@googlegroups.com
Hey All,

There is probably a reason for this, but the SDL library provided by Emscripten doesn't support the SDL_gfx rotozoomSurface function. It did however contain the definition in the system includes leading to a runtime error that the javascript function was not found.
Copying the SDL_rotozoom.c from the upstream SDL_gfx src and using that did not work (resulted in 100% transparent image) so I had to implement it using the HTML5 canvas instead.

Due to WebGL still not being as widely supported as software rendering via the HTML5 canvas, I still needed a way to rotate images without it. For this reason I implemented the small function and have included the patch below.

Best regards,

Karsten

---------------- 8< --------------------

--- library_sdl.js.orig 2013-04-13 00:11:52.000000000 +0100
+++ library_sdl.js      2013-04-13 00:20:20.000000000 +0100
@@ -1022,6 +1022,19 @@
     return _SDL_UpperBlit(src, srcrect, dst, dstrect);
   },

+  rotozoomSurface: function(src, rotation, scale, smooth) {
+    var srcData = SDL.surfaces[src];
+    var w = srcData.width*scale;
+    var h = srcData.height*scale;
+    var ret = SDL.makeSurface(w, h, srcData.flags, false, 'zoomSurface');
+    var dstData = SDL.surfaces[ret];
+    dstData.ctx.translate(w / 2, h / 2);
+    dstData.ctx.rotate(-rotation * (3.14159265 / 180));
+    dstData.ctx.translate(-(w / 2), -(h / 2));
+    dstData.ctx.drawImage(srcData.canvas, 0, 0, w, h);
+    return ret;
+  },
+
   zoomSurface: function(src, x, y, smooth) {
     var srcData = SDL.surfaces[src];
     var w = srcData.width*x;
----------------------------- >8 ---------------------------------------

Alon Zakai

unread,
Apr 15, 2013, 8:20:06 PM4/15/13
to emscripte...@googlegroups.com
There is a rotozoomSurface on emscripten incoming, perhaps not yet on master (was recently added I think). Does it work ok? It looks a little different than yours.

- azakai




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

karsten....@4t2.co.uk

unread,
Apr 16, 2013, 7:26:29 AM4/16/13
to emscripte...@googlegroups.com
Hi azakai,

Ah, didn't check the incoming branch. I believe that implementation is better since it increases the size of the surface to the diagonal width so that the image is guaranteed to fit on.

All good, both implementations will work for my purposes.

Cheers,

Karsten

Mike Stein

unread,
Nov 13, 2022, 8:31:48 PM11/13/22
to emscripten-discuss
Karsten,

Does Emscripten now include SDL_gfx functionality? I am a novice programmer and would like to try porting:

Antirez's old graphical Lua load81 project on github to the browser. It's only dependence is on SDL libraries and it looks like Emscripten includes these (or as ports) but not necessarily SDL_gfx.

I appreciate any information you can provide. 

Thanks!

Mike

Reply all
Reply to author
Forward
0 new messages