diff --git a/include/dawn/display/gui/font.h b/include/dawn/display/gui/font.h index c19678d7..16e75129 100644 --- a/include/dawn/display/gui/font.h +++ b/include/dawn/display/gui/font.h @@ -15,11 +15,8 @@ /** How many characters (after the first char) to generate */ #define FONT_NUM_CHARS 96 -/** Passed to STBTT for scaling the font nicely */ -#define FONT_TEXTURE_SIZE 24 - /** Width of the loaded font texture */ -#define FONT_TEXTURE_WIDTH 512 +#define FONT_TEXTURE_WIDTH 1024 /** Height of the loaded font texture */ #define FONT_TEXTURE_HEIGHT FONT_TEXTURE_WIDTH @@ -27,6 +24,9 @@ /** Refer to STBTT docs for OpenGL Fill Mode v d3d Fill Modes */ #define FONT_FILL_MODE 1 +/** Passed to STBTT for scaling the font nicely, essentially the font size. */ +#define FONT_TEXTURE_SIZE 96 + // Chars #define FONT_NEWLINE '\n' #define FONT_SPACE ' ' @@ -35,7 +35,6 @@ #define FONT_LINE_HEIGHT FONT_TEXTURE_SIZE*0.75 #define FONT_INITIAL_LINE FONT_LINE_HEIGHT*0.75 #define FONT_SPACE_SIZE FONT_TEXTURE_SIZE*0.45 -#define FONT_SCALE_ADJUST 0.03 /** Representation of a font that can be used to render text */ typedef struct { diff --git a/include/dawn/poker/poker.h b/include/dawn/poker/poker.h index 0e67c22a..eb6cfda3 100644 --- a/include/dawn/poker/poker.h +++ b/include/dawn/poker/poker.h @@ -46,7 +46,14 @@ #define POKER_BLIND_BIG_DEFAULT 600 #define POKER_BLIND_SMALL_DEFAULT (POKER_BLIND_BIG_DEFAULT/2) +/** GUI Height fix (To keep gui scaling nicely we use a fixed height) */ +#define POKER_GUI_HEIGHT 2160 + typedef struct { + ////////////////////////////////////////////////////////////////////////////// + // Poker Logic Variables + ////////////////////////////////////////////////////////////////////////////// + /** Current Card Deck */ card_t deck[CARD_DECK_SIZE]; uint8_t deckSize; @@ -77,19 +84,29 @@ typedef struct { /** The current buy-in bet size. */ uint32_t roundBet; - /** Rendering Assets */ - framebuffer_t frameWorld; - framebuffer_t frameGui; + ////////////////////////////////////////////////////////////////////////////// + // Rendering Assets + ////////////////////////////////////////////////////////////////////////////// + /** Frames to hold the world and GUI render outputs */ + framebuffer_t frameWorld, frameGui; + /** Game's Font */ font_t font; + /** Game's Shader */ shader_t shader; - camera_t cameraWorld; - camera_t cameraGui; + /** Camera for the world and the GUI */ + camera_t cameraWorld, cameraGui; - /** Talk related */ - float lastWidth, lastHeight; + /** Refer to POKER_GUI_HEIGHT */ + float guiWidth; + + /** Last frame's GUI width, used to track font wrapping */ + float textLastWidth; + /** Primitive to hold talking text */ primitive_t talkPrimitive; + /** Current spoken text, tracked in-case of re-render */ char *talkText; + /** Information about the current rendered text */ fonttextinfo_t *talkTextInfo; texture_t dealerTexture; diff --git a/src/display/gui/font.c b/src/display/gui/font.c index b1597c34..9dbd6fed 100644 --- a/src/display/gui/font.c +++ b/src/display/gui/font.c @@ -110,9 +110,6 @@ fonttextinfo_t * fontTextClamp(font_t *font, char *text, float maxWidth) { if(c == FONT_SPACE) { x += FONT_SPACE_SIZE; - info->width = mathMax(info->width, quad->x1); - info->height = mathMax(info->height, quad->y1); - // Did this space cause a newline? if(x > maxWidth) { info->lines++; @@ -167,8 +164,12 @@ fonttextinfo_t * fontTextClamp(font_t *font, char *text, float maxWidth) { info->realLength++; } - info->width = mathMax(info->width, quad->x1); - info->height = mathMax(info->height, quad->y1); + for(j = 0; j < info->realLength; j++) { + quad = info->quads + j; + info->width = mathMax(info->width, quad->x1); + info->height = mathMax(info->height, quad->y1); + } + return info; } \ No newline at end of file diff --git a/src/poker/poker.c b/src/poker/poker.c index b175ae28..0855af96 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -47,7 +47,9 @@ void pokerUpdate(poker_t *poker, render_t *render) { } pokerFrameGui(poker, render); - pokerTalkRender(poker, render); + pokerTalkRender(poker); + + poker->textLastWidth = poker->guiWidth; } void pokerDispose(poker_t * poker) { diff --git a/src/poker/render/frame.c b/src/poker/render/frame.c index 0d07523b..0e05704e 100644 --- a/src/poker/render/frame.c +++ b/src/poker/render/frame.c @@ -10,11 +10,6 @@ void pokerFrameInit(poker_t *poker, render_t *render) { frameBufferInit(&poker->frameWorld, render->width, render->height); frameBufferInit(&poker->frameGui, render->width, render->height); - - // fonttextinfo_t *info; - // char *text = "Hello world how are you today? I'm doing fine myself."; - // info = fontTextClamp(&poker->font, text, 16, 500); - // fontTextInit(&poker->font, &bruh, info); } void pokerFrameWorld(poker_t *poker, render_t *render) { @@ -32,12 +27,13 @@ void pokerFrameWorld(poker_t *poker, render_t *render) { void pokerFrameGui(poker_t *poker, render_t *render) { // Update FB frameBufferResize(&poker->frameGui, render->width, render->height); + poker->guiWidth = ((float)POKER_GUI_HEIGHT/render->height) * render->width; // frameBufferUse(&poker->frameGui, true); // Correct aspect on the ortho camera cameraOrtho(&poker->cameraGui, - 0, render->width, - render->height, 0, + 0, poker->guiWidth, + POKER_GUI_HEIGHT, 0, 0.01, 100 ); cameraLookAt(&poker->cameraGui, 0, 0, 5, 0, 0, 0); diff --git a/src/poker/render/talk.c b/src/poker/render/talk.c index a32f7146..68c60d23 100644 --- a/src/poker/render/talk.c +++ b/src/poker/render/talk.c @@ -6,19 +6,11 @@ */ #include "talk.h" -#define SCALE 16 - -texture_t text; -primitive_t primitive; void pokerTalkInit(poker_t *poker) { poker->talkText = NULL; poker->talkTextInfo = NULL; - poker->lastWidth = 0, poker->lastHeight = 0; - - // Testing - assetTextureLoad(&text, "red.png"); - quadInit(&primitive, 0, 0, 0, 0, 0, 0, 0, 0, 0); + poker->textLastWidth = 0; } void pokerTalkDispose(poker_t *poker) { @@ -27,38 +19,33 @@ void pokerTalkDispose(poker_t *poker) { primitiveDispose(&poker->talkPrimitive); } -void pokerTalkTextRebuffer(poker_t *poker, render_t *render) { +void pokerTalkTextRebuffer(poker_t *poker) { // Check if we need to force a redraw or not. - if(poker->talkText == NULL || poker->lastWidth != render->width) { + if(poker->talkText == NULL || poker->textLastWidth != poker->guiWidth) { if(poker->talkTextInfo != NULL) { fontTextInfoDispose(poker->talkTextInfo); primitiveDispose(&poker->talkPrimitive); } } - poker->lastWidth = render->width; - poker->lastHeight = render->height; if(poker->talkText == NULL) return; // Rebuffer - poker->talkTextInfo = fontTextClamp(&poker->font,poker->talkText,render->width); + poker->talkTextInfo = fontTextClamp(&poker->font, poker->talkText, poker->guiWidth); fontTextInit(&poker->font, &poker->talkPrimitive, poker->talkTextInfo); } -void pokerTalkRender(poker_t *poker, render_t *render) { - pokerTalkTextRebuffer(poker, render); - +void pokerTalkRender(poker_t *poker) { + pokerTalkTextRebuffer(poker); if(poker->talkTextInfo == NULL) return; - shaderUsePosition(&poker->shader, 0,0,0, 0,0,0); + + // Render text + shaderUsePosition(&poker->shader, + 0,POKER_GUI_HEIGHT-poker->talkTextInfo->height,0, + 0,0,0 + ); shaderUseTexture(&poker->shader, &poker->font.texture); primitiveDraw(&poker->talkPrimitive, 0, -1); - - primitiveDispose(&primitive); - quadInit(&primitive, -0.05, 0, 0, 0.25, 0.25, poker->talkTextInfo->width, poker->talkTextInfo->height, 0.35, 0.35); - - shaderUsePosition(&poker->shader, 0,0,0, 0,0,0); - shaderUseTexture(&poker->shader, &text); - primitiveDraw(&primitive, 0, -1); } void pokerTalk(poker_t *poker, char *text) { diff --git a/src/poker/render/talk.h b/src/poker/render/talk.h index 2e212157..40f5bb08 100644 --- a/src/poker/render/talk.h +++ b/src/poker/render/talk.h @@ -11,15 +11,12 @@ #include "../../display/primitive.h" #include "../../display/shader.h" -#include "../../file/asset.h" -#include "../../display/primitives/quad.h" - void pokerTalkInit(poker_t *poker); void pokerTalkDispose(poker_t *poker); -void pokerTalkTextRebuffer(poker_t *poker, render_t *render); +void pokerTalkTextRebuffer(poker_t *poker); -void pokerTalkRender(poker_t *poker, render_t *render); +void pokerTalkRender(poker_t *poker); void pokerTalk(poker_t *poker, char *text); \ No newline at end of file