Corrected final font issues.
This commit is contained in:
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
Reference in New Issue
Block a user