karsten....@4t2.co.uk
unread,Apr 12, 2013, 7:32:00 PM4/12/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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 ---------------------------------------