97 lines
2.5 KiB
C
Raw Normal View History

2023-02-21 22:05:28 +01:00
#include <SDL2/SDL.h>
#include <SDL2/SDL_events.h>
2023-02-23 01:23:21 +01:00
#include <SDL2/SDL_video.h>
2023-02-12 09:34:44 +01:00
#include <stdlib.h>
2023-03-11 20:15:34 +01:00
#include <locale.h>
2023-02-12 09:34:44 +01:00
#include <stdio.h>
2023-02-19 23:40:58 +01:00
#include "ren.h"
2023-02-15 02:15:44 +01:00
#include "util.h"
2023-02-12 09:34:44 +01:00
2023-03-07 19:09:32 +01:00
//const char *str1 = "Ciao Mamma!\nprova: òçà°ù§|¬³¼$£ì\t";
2023-03-07 22:01:39 +01:00
const char *str1 = "ciao\tmamma";
2023-03-11 20:15:34 +01:00
const char *str2 = "The quick brown fox jumps over the lazy dog\n"
"чащах юга жил бы цитрус? Да, но фальшивый экземпляр!\n"
"Pijamalı hasta, yağız şoföre çabucak güvendi\n"
"Pchnąć w tę łódź jeża lub ośm skrzyń fig\n"
"イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン\n"
"Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa";
2023-02-25 22:50:31 +01:00
SDL_Window *win;
2023-03-19 16:42:41 +01:00
#define red 0xff0000ff
#define blue 0xffff0000
2023-02-25 22:50:31 +01:00
void draw(void)
{
2023-03-06 13:18:59 +01:00
static unsigned int frame = 0;
printf("frame: %d\n", frame++);
2023-02-25 22:50:31 +01:00
ren_clear();
2023-03-19 16:42:41 +01:00
//ren_render_box(10, 10, 400, 50, blue);
2023-03-11 20:15:34 +01:00
//if (ren_render_text(str1, 10, 10, 400, 50, 20))
// printf("text: %s\n", ren_strerror());
2023-03-07 19:09:32 +01:00
int w, h;
2023-03-11 20:15:34 +01:00
ren_get_text_box(str2, &w, &h, 20);
//printf("box for: %s -> (%d, %d)\n", str2, w, h);
2023-03-19 16:42:41 +01:00
ren_render_box(0, 0, w, h, blue);
2023-03-11 20:15:34 +01:00
ren_render_text(str2, 0, 0, w, h, 20);
// fixme: this causes a bug
const char *s = "ciao mamma";
ren_get_text_box(s, &w, &h, 12);
s = "stuff that was not in font size 12 -> чащаx";
2023-03-19 16:42:41 +01:00
ren_render_box(0, 200, w, h, red);
2023-03-11 20:15:34 +01:00
if (ren_render_text(s, 0, 200, 0xffff, 0xffff, 12))
printf("BUG\n");
2023-02-25 22:50:31 +01:00
SDL_GL_SwapWindow(win);
}
2023-02-12 09:34:44 +01:00
int main(void)
{
2023-03-11 20:15:34 +01:00
setlocale(LC_ALL, "en_US.UTF-8");
2023-02-23 23:39:34 +01:00
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");
2023-03-07 19:09:32 +01:00
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0");
2023-02-23 23:39:34 +01:00
2023-02-25 22:50:31 +01:00
win = SDL_CreateWindow(
2023-02-19 23:40:58 +01:00
"test render",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
500,
500,
2023-03-07 19:09:32 +01:00
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
2023-02-19 23:40:58 +01:00
if (ren_init(win)) {
printf("renderer init error: %s\n", ren_strerror());
return 1;
2023-02-12 09:34:44 +01:00
}
2023-02-21 22:05:28 +01:00
SDL_Event e;
while(1) {
SDL_WaitEvent(&e);
if (e.type == SDL_QUIT)
break;
2023-02-23 01:23:21 +01:00
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);
2023-02-25 22:50:31 +01:00
draw();
2023-02-23 23:39:34 +01:00
break;
2023-02-23 01:23:21 +01:00
case SDL_WINDOWEVENT_EXPOSED:
2023-02-25 22:50:31 +01:00
draw();
2023-02-23 01:23:21 +01:00
break;
default: break;
}
}
2023-02-21 22:05:28 +01:00
}
2023-02-15 02:15:44 +01:00
2023-02-19 23:40:58 +01:00
ren_free();
SDL_DestroyWindow(win);
2023-02-21 22:05:28 +01:00
SDL_Quit();
2023-02-12 09:34:44 +01:00
return 0;
}