|
@@ -11,6 +11,7 @@
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
#include <SDL.h>
|
|
|
+#include <SDL_ttf.h>
|
|
|
|
|
|
#include <log.h>
|
|
|
#include <display.h>
|
|
@@ -26,6 +27,8 @@ SDL_Texture *frameBufferTexture = NULL;
|
|
|
int32_t windowWidth = 1024;
|
|
|
int32_t windowHeight = 768;
|
|
|
|
|
|
+static TTF_Font *font = NULL;
|
|
|
+
|
|
|
/***********************************************************************************************************************
|
|
|
* Functions
|
|
|
**********************************************************************************************************************/
|
|
@@ -45,6 +48,13 @@ bool initialiseWindow(bool fullScreen)
|
|
|
|
|
|
Log(TLOG_DEBUG, NULL, "SDL properly initialised!");
|
|
|
|
|
|
+ ret = TTF_Init();
|
|
|
+ if (ret)
|
|
|
+ {
|
|
|
+ Log(TLOG_PANIC, NULL, "SDL_ttf Initialisation error!! error: %s", SDL_GetError());
|
|
|
+ goto exit;
|
|
|
+ }
|
|
|
+
|
|
|
if (fullScreen)
|
|
|
{
|
|
|
Log(TLOG_DEBUG, NULL, "Will go fullscreen! Fasten your seatbelts!");
|
|
@@ -74,6 +84,13 @@ bool initialiseWindow(bool fullScreen)
|
|
|
}
|
|
|
Log(TLOG_DEBUG, NULL, "SDL Renderer created!");
|
|
|
|
|
|
+ font = TTF_OpenFont("assets/pico8.ttf", 8);
|
|
|
+ if (font == NULL)
|
|
|
+ {
|
|
|
+ Log(TLOG_WARNING, NULL, "Cannot open the font for printing...: %s", SDL_GetError());
|
|
|
+ goto exit;
|
|
|
+ }
|
|
|
+
|
|
|
if (fullScreen)
|
|
|
{
|
|
|
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
|
@@ -87,6 +104,10 @@ exit:
|
|
|
|
|
|
void destroyWindow()
|
|
|
{
|
|
|
+ if (font != NULL)
|
|
|
+ {
|
|
|
+ TTF_CloseFont(font);
|
|
|
+ }
|
|
|
if (frameBuffer != NULL)
|
|
|
{
|
|
|
free(frameBuffer);
|
|
@@ -102,6 +123,36 @@ void renderFrameBuffer()
|
|
|
SDL_RenderCopy(renderer, frameBufferTexture, NULL, NULL);
|
|
|
}
|
|
|
|
|
|
+void drawText(int32_t x, int32_t y, colour_t colour, const char *format, ...)
|
|
|
+{
|
|
|
+ va_list va;
|
|
|
+ uint8_t r = ((colour >> 16) & 0xFF);
|
|
|
+ uint8_t g = ((colour >> 8) & 0xFF);
|
|
|
+ uint8_t b = ((colour ) & 0xFF);
|
|
|
+ SDL_Color c = { r, g, b , 255};
|
|
|
+ char buffer[512];
|
|
|
+
|
|
|
+ va_start(va, format);
|
|
|
+ vsnprintf(buffer, 512, format, va);
|
|
|
+ va_end(va);
|
|
|
+
|
|
|
+ SDL_Surface *surface = TTF_RenderText_Blended(font, buffer, c);
|
|
|
+ SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
|
|
+
|
|
|
+ int labelWidth, labelHeight;
|
|
|
+
|
|
|
+ SDL_QueryTexture(texture, NULL, NULL, &labelWidth, &labelHeight);
|
|
|
+
|
|
|
+ SDL_Rect destRect =
|
|
|
+ {
|
|
|
+ x, y, labelWidth, labelHeight
|
|
|
+ };
|
|
|
+ SDL_RenderCopyEx(renderer, texture, NULL, &destRect,0, NULL, SDL_FLIP_NONE);
|
|
|
+
|
|
|
+ SDL_FreeSurface(surface);
|
|
|
+ SDL_DestroyTexture(texture);
|
|
|
+}
|
|
|
+
|
|
|
void drawPixel(int32_t x, int32_t y, colour_t colour)
|
|
|
{
|
|
|
if ((x >= 0) && (x < windowWidth) && (y >= 0) && (y < windowHeight))
|