aboutsummaryrefslogtreecommitdiff
path: root/src/library_sdl.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-03-21 16:40:07 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-03-21 16:43:40 -0700
commit65dd19503b073531b57e78831e1a65c4186b13b1 (patch)
tree3eab8b13f0f2b4ccfa0690a1b666ce2f6e6ff7ed /src/library_sdl.js
parentfa6a563674b6335103c014d421284053cd274c4f (diff)
initial version of TTF_RenderText_Solid
Diffstat (limited to 'src/library_sdl.js')
-rw-r--r--src/library_sdl.js33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 3ce281f0..07a6be63 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -134,7 +134,8 @@ mergeInto(LibraryManager.library, {
])
},
- makeSurface: function(width, height, flags) {
+ makeSurface: function(width, height, flags, customCanvas) {
+ flags = flags || 0;
var surf = _malloc(14*Runtime.QUANTUM_SIZE); // SDL_Surface has 14 fields of quantum size
var buffer = _malloc(width*height*4);
var pixelFormat = _malloc(18*Runtime.QUANTUM_SIZE);
@@ -160,12 +161,19 @@ mergeInto(LibraryManager.library, {
// Decide if we want to use WebGL or not
var useWebGL = (flags & 0x04000000) != 0; // SDL_OPENGL
-
+ var canvas;
+ if (customCanvas) {
+ canvas = new document.createElement('canvas');
+ canvas.width = width;
+ canvas.height = height;
+ } else {
+ canvas = Module['canvas'];
+ }
SDL.surfaces[surf] = {
width: width,
height: height,
- canvas: Module['canvas'],
- ctx: SDL.createContext(useWebGL),
+ canvas: canvas,
+ ctx: SDL.createContext(canvas, useWebGL),
surf: surf,
buffer: buffer,
pixelFormat: pixelFormat,
@@ -175,7 +183,7 @@ mergeInto(LibraryManager.library, {
return surf;
},
- createContext: function(useWebGL) {
+ createContext: function(canvas, useWebGL) {
#if !USE_TYPED_ARRAYS
if (useWebGL) {
Module.print('(USE_TYPED_ARRAYS needs to be enabled for WebGL)');
@@ -183,12 +191,12 @@ mergeInto(LibraryManager.library, {
}
#endif
try {
- var ctx = Module.canvas.getContext(useWebGL ? 'experimental-webgl' : '2d');
+ var ctx = canvas.getContext(useWebGL ? 'experimental-webgl' : '2d');
if (!ctx) throw 'Could not create canvas :(';
if (useWebGL) {
// Set the background of the WebGL canvas to black, because SDL gives us a
// window which has a black background by default.
- Module.canvas.style.backgroundColor = "black";
+ canvas.style.backgroundColor = "black";
}
return Module.ctx = ctx;
} catch (e) {
@@ -634,11 +642,20 @@ mergeInto(LibraryManager.library, {
filename = FS.standardizePath(Pointer_stringify(filename));
var id = SDL.fonts.length;
SDL.fonts.push({
- name: filename
+ name: filename // but we don't actually do anything with it..
});
return id;
},
+ TTF_RenderText_Solid: function(font, text, color) {
+ // XXX the font and color are ignored
+ text = Pointer_stringify(text);
+ var surf = SDL.makeSurface(20*text.length, 15, 0, true); // bogus numbers..
+ var surfData = SDL.surfaces[surf];
+ surfData.ctx.fillText(text, 0, 0);
+ },
+ TTF_RenderText_Blended: 'TTF_RenderText_Solid', // XXX ignore blending vs. solid
+
// Misc
SDL_InitSubSystem: function(flags) { return 0 },