summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-11-23 18:29:58 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-11-23 18:29:58 -0500
commit55d0ece0a9072ca409bdf6ff2f3b6d0b268e2952 (patch)
tree5df0cbfacf3d9442ddb34fdf5fb3b59f4e74d82e /main.c
parent5e458dff3bcc832b0b28d83bd3ef482174d1dc09 (diff)
unicode text rendering working
Diffstat (limited to 'main.c')
-rw-r--r--main.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/main.c b/main.c
index 2353d08..f2aa450 100644
--- a/main.c
+++ b/main.c
@@ -3,6 +3,7 @@ no_warn_start
#include <SDL2/SDL.h>
no_warn_end
#include <GL/gl.h>
+#include <locale.h>
#include "text.h"
static void die(char const *fmt, ...) {
@@ -23,7 +24,8 @@ static void die(char const *fmt, ...) {
int main(void) {
- if (SDL_Init(SDL_INIT_VIDEO) < 0)
+ setlocale(LC_ALL, ""); // allow unicode
+ if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0)
die("%s", SDL_GetError());
SDL_Window *window = SDL_CreateWindow("ted", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL);
@@ -39,7 +41,7 @@ int main(void) {
SDL_GL_SetSwapInterval(1); // vsync
- Font *font = text_font_load("assets/font.ttf", 12);
+ Font *font = text_font_load("assets/font.ttf", 24);
if (!font) {
die("Couldn't load font: %s", text_get_err());
}
@@ -55,11 +57,33 @@ int main(void) {
}
}
- glClearColor(0,0,0,1);
+ int window_width = 0, window_height = 0;
+ SDL_GetWindowSize(window, &window_width, &window_height);
+
+ // set up GL
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glViewport(0, 0, window_width, window_height);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glOrtho(0, window_width, 0, window_height, -1, +1);
+ glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
+ glColor3f(1,1,1);
+ text_render(font, u8"hőello☐øλㄔ☺☹", 50, 50);
+ if (text_has_err()) {
+ printf("Text error: %s\n", text_get_err());
+ break;
+ }
+
SDL_GL_SwapWindow(window);
}
+ SDL_GL_DeleteContext(glctx);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+ text_font_free(font);
+
return 0;
}