#include "base.h" no_warn_start #include no_warn_end #include #include #include "text.h" static void die(char const *fmt, ...) { char buf[256] = {0}; va_list args; va_start(args, fmt); vsnprintf(buf, sizeof buf - 1, fmt, args); va_end(args); // show a message box, and if that fails, print to stderr if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", buf, NULL) < 0) { fprintf(stderr, "%s\n", buf); } exit(EXIT_FAILURE); } int main(void) { 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); if (!window) die("%s", SDL_GetError()); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GLContext *glctx = SDL_GL_CreateContext(window); if (!glctx) { die("%s", SDL_GetError()); } SDL_GL_SetSwapInterval(1); // vsync Font *font = text_font_load("assets/font.ttf", 24); if (!font) { die("Couldn't load font: %s", text_get_err()); } bool quit = false; while (!quit) { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: quit = true; break; } } 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; }