aboutsummaryrefslogtreecommitdiff
path: root/tests/sdl_font.c
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/sdl_font.c
parenta7573355dbfafe35ec7620c51dc0d7929b024fb7 (diff)
minimal support for SDL text rendering
Diffstat (limited to 'tests/sdl_font.c')
-rw-r--r--tests/sdl_font.c46
1 files changed, 46 insertions, 0 deletions
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;
+}
+