You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ugui/text_rendering/main.c

68 lines
1.2 KiB

#include <SDL2/SDL.h>
#include <SDL2/SDL_events.h>
2 years ago
#include <SDL2/SDL_video.h>
2 years ago
#include <stdlib.h>
#include <stdio.h>
2 years ago
#include "ren.h"
2 years ago
#include "util.h"
2 years ago
2 years ago
const char *str = "Ciao Mamma!\nprova: òçà°ù§|¬³¼$£ì\t";
SDL_Window *win;
void draw(void)
{
ren_clear();
ren_render_text(str, 0, 0, 100, 50, 12);
2 years ago
ren_render_box(100, 300, 50, 50, 0xffff0000);
SDL_GL_SwapWindow(win);
}
2 years ago
int main(void)
{
2 years ago
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
2 years ago
win = SDL_CreateWindow(
2 years ago
"test render",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
500,
500,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (ren_init(win)) {
printf("renderer init error: %s\n", ren_strerror());
return 1;
2 years ago
}
2 years ago
SDL_Event e;
while(1) {
SDL_WaitEvent(&e);
if (e.type == SDL_QUIT)
break;
2 years ago
if (e.type == SDL_WINDOWEVENT) {
switch (e.window.event) {
case SDL_WINDOWEVENT_RESIZED:
case SDL_WINDOWEVENT_SIZE_CHANGED:
ren_update_viewport(e.window.data1, e.window.data2);
2 years ago
draw();
2 years ago
break;
2 years ago
case SDL_WINDOWEVENT_EXPOSED:
2 years ago
draw();
2 years ago
break;
default: break;
}
}
}
2 years ago
2 years ago
ren_free();
SDL_DestroyWindow(win);
SDL_Quit();
2 years ago
return 0;
}