DBGCFLAGS=-g
DBGLDFLAGS=
CFLAGS=-Wall -Wextra -Werror -pedantic $(DBGCFLAGS) -std=c89
-LIBS=-lSDL3 -lSDL3_ttf
+LIBS=-lSDL3
LDFLAGS=$(DBGLDFLAGS) $(LIBS)
INSTALL_DIR=/usr/local
#include "i_input.c"
#include "u_time.c"
#include "t_update.c"
+#include "u_debug.c"
#endif
va_list args;
va_start(args, fmt);
- u_vfprintf(stream, fmt, args);
+ res = u_vfprintf(stream, fmt, args);
va_end(args);
return res;
*/
void p_delay(u64 time);
-/**
- * Drwas debug text to the screen
- */
-void p_draw_debug_text(u32 x, u32 y, const char *fmt, ...);
/**
SDL_UpdateWindowSurface(p_main_window);
}
-
-void p_draw_debug_text(u32 x, u32 y, const char *fmt, ...) {
- char buffer[2048];
- va_list args;
- TTF_Text *t;
-
- va_start(args, fmt);
- vsprintf(buffer, fmt, args);
- va_end(args);
-
- /* if there is no font just print the info...
- * this might spam a lot but at least we can still read the data
- */
- if (p_r_sdl_debug_font == LRTS_NULL) {
- u_log(U_LOG_DEBUG, "%s\n", buffer);
- return;
- }
-
- t = TTF_CreateText(p_r_sdl_text_engine, p_r_sdl_debug_font, buffer, strlen(buffer));
- TTF_DrawSurfaceText(t, x, y, r_target);
-}
#include "../p_platform.h"
#include <SDL3/SDL.h>
-#include <SDL3_ttf/SDL_ttf.h>
#include "p_window.h"
#include "../u_defs.h"
#include "../u_log.h"
#include "p_window.c"
-TTF_TextEngine *p_r_sdl_text_engine;
-TTF_Font *p_r_sdl_debug_font;
-
#define DEFAULT_COLOR 0x222222FF
int p_render_init(void) {
exit(-1);
}
- if (!TTF_Init()) {
- u_log(U_LOG_ERR, "Failed to init ttf: %s\n", SDL_GetError());
- exit(-1);
- }
-
- p_r_sdl_text_engine = TTF_CreateSurfaceTextEngine();
- if (p_r_sdl_text_engine == LRTS_NULL) {
- u_log(U_LOG_ERR, "Failed to init ttf text engine: %s\n", SDL_GetError());
- exit(-1);
- }
-
- /* TODO: find a way to get a default font on any platform... */
- p_r_sdl_debug_font = TTF_OpenFont("", 14);
- if (p_r_sdl_debug_font == LRTS_NULL) {
- u_log(U_LOG_WARN, "Failed to open debug font\n", SDL_GetError());
- }
-
SDL_SetSurfaceColorKey(SDL_GetWindowSurface(p_main_window), LRTS_TRUE, R_COLOR_TRANSPARENT);
u_log(U_LOG_DEBUG, "Init successful\n");
int p_renderer_finish(void) {
SDL_DestroySurface(r_target);
SDL_DestroyWindow(p_main_window);
- TTF_CloseFont(p_r_sdl_debug_font);
- TTF_DestroySurfaceTextEngine(p_r_sdl_text_engine);
SDL_Quit();
u_log(U_LOG_DEBUG, "Exiting...\n");
return 0;
#ifndef P_R_SDL_H__
#define P_R_SDL_H__
-#include <SDL3_ttf/SDL_ttf.h>
-
-extern TTF_Font *p_r_sdl_debug_font;
-extern TTF_TextEngine *p_r_sdl_text_engine;
#endif
#include "p_draw.h"
#include "t_tile.h"
#include "r_assets.h"
+#include "u_debug.h"
struct r_framebuffer r_framebuffer;
}
void r_render_debug(void) {
- struct lrts_state *state = lrts_state();
+ /* struct lrts_state *state = lrts_state(); */
- p_draw_debug_text(0, 0, "FPS: %d", state->fps);
+ u_debug_draw_text(0, 0, "01");
+ /*u_debug_draw_text(0, 0, "FPS: %d", state->fps); */
}
void r_render_frame(void) {
u_timer_start(&u_fps_timer);
p_draw_begin();
- t_map_draw(&t_map);
+ /* t_map_draw(&t_map); */
if (state->debug) {
r_render_debug();
}
--- /dev/null
+#include "u_debug.h"
+
+#include "r_render.h"
+
+#define U_DEBUG_FONT_W 8
+#define U_DEBUG_FONT_H 8
+
+const u8 debug_font_num[10 * U_DEBUG_FONT_H] = {
+ /* 0 */
+ 0xFE,
+ 0x82,
+ 0x82,
+ 0x82,
+ 0x82,
+ 0x82,
+ 0x82,
+ 0xFF,
+
+ /* 1 */
+ 0x80,
+ 0x80,
+ 0x80,
+ 0x80,
+ 0x80,
+ 0x80,
+ 0x80,
+ 0x80,
+
+ /* 2 */
+
+};
+
+r_color u_debug_colors[2] = {0x00000000, 0xFFFFFFFF};
+
+#define u_debug_draw_pixel(x, y, i, c, bit) r_draw_pixel(&r_framebuffer, (x)+7-bit, (y) + i, u_debug_colors[c[i] >> bit & 0x01]);
+
+void u_debug_draw_char(u32 x, u32 y, const u8 *c) {
+ u32 i;
+ for (i = 0; i < U_DEBUG_FONT_H; i++) {
+ u_debug_draw_pixel(x, y, i, c, 0);
+ u_debug_draw_pixel(x, y, i, c, 1);
+ u_debug_draw_pixel(x, y, i, c, 2);
+ u_debug_draw_pixel(x, y, i, c, 3);
+ u_debug_draw_pixel(x, y, i, c, 4);
+ u_debug_draw_pixel(x, y, i, c, 5);
+ u_debug_draw_pixel(x, y, i, c, 6);
+ u_debug_draw_pixel(x, y, i, c, 7);
+ }
+}
+
+void u_debug_draw_text(u32 x, u32 y, const char *fmt, ...) {
+ u32 i = 0;
+ u32 len = 0;
+ char c = 0;
+ char buffer[2048];
+ va_list args;
+
+ va_start(args, fmt);
+ len = u_vsprintf(buffer, fmt, args);
+ va_end(args);
+
+ LRTS_UNUSED(x);
+ LRTS_UNUSED(y);
+
+ for (i = 0; i < len; i++) {
+ c = buffer[i];
+ if (c >= '0' && c <= '9') {
+ u_debug_draw_char(x+U_DEBUG_FONT_W*2*i, y,
+ debug_font_num + (u32)(c - '0') * U_DEBUG_FONT_H);
+ }
+ }
+
+}
+
--- /dev/null
+#ifndef U_DEBUG_H__
+#define U_DEBUG_H__
+
+#define U_DEBUG_FONT_BYTES 8
+
+/**
+ * Daws debug text to the screen
+ */
+void u_debug_draw_text(u32 x, u32 y, const char *fmt, ...);
+
+#endif