aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-03-23 12:02:59 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-03-23 12:02:59 -0700
commit6a3c3938cd802db8b034c27b743844735f1b6d28 (patch)
treecb5f38ab6e348984b042177d1a14a451075605b0 /tests
parenta7573355dbfafe35ec7620c51dc0d7929b024fb7 (diff)
minimal support for SDL text rendering
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runner.py6
-rw-r--r--tests/sdl_font.c46
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py
index c34334ea..66934895 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -6375,6 +6375,12 @@ f.close()
shutil.move(os.path.join(self.get_dir(), basename), basename + '.renamedsoitcannotbefound');
self.run_browser('page.html', '', '/report_result?' + str(width))
+ def test_sdl_font(self):
+ open(os.path.join(self.get_dir(), 'sdl_font.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_font.c')).read()))
+
+ Popen(['python', EMCC, os.path.join(self.get_dir(), 'sdl_font.c'), '-o', 'page.html']).communicate()
+ self.run_browser('page.html', '', '/report_result?80')
+
def test_worker(self):
# Test running in a web worker
output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_worker.cpp'), '-o', 'worker.js'], stdout=PIPE, stderr=PIPE).communicate()
diff --git a/tests/sdl_font.c b/tests/sdl_font.c
new file mode 100644
index 00000000..f4f26355
--- /dev/null
+++ b/tests/sdl_font.c
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_ttf.h>
+#include <emscripten.h>
+
+int main() {
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE);
+
+ printf("Init: %d\n", TTF_Init());
+
+ TTF_Font *font = TTF_OpenFont("myfont.ttf", 40);
+ printf("Font: %p\n", font);
+
+ SDL_Color color = { 0xff, 0x99, 0x00, 0x77 };
+
+ SDL_Surface *text = TTF_RenderText_Solid(font, "hello orange world", color);
+ SDL_LockSurface(text);
+ int sum = 0;
+ for (int i = 0; i < text->h; i++) {
+ sum += *((char*)text->pixels + i*text->w*4 + i*4 + 0);
+ }
+ printf("Sum: %d\n", sum);
+ SDL_UnlockSurface(text);
+
+ SDL_Color color2 = { 0xbb, 0, 0xff, 0 };
+ SDL_Surface *text2 = TTF_RenderText_Solid(font, "a second line, purple", color2);
+
+ // render
+ SDL_Rect dest = { 0, 50, 0, 0 };
+ SDL_BlitSurface (text, NULL, screen, NULL);
+ dest.y = 100;
+ SDL_BlitSurface (text2, NULL, screen, &dest);
+
+ SDL_Flip(screen);
+
+ printf("you should see two lines of text in different colors.\n");
+
+ SDL_Quit();
+
+ int result = sum;
+ REPORT_RESULT();
+
+ return 0;
+}
+