Added True Type fonts
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,6 +9,7 @@
|
||||
// Display / Rendering
|
||||
#include "display/debug/grid.h"
|
||||
|
||||
#include "display/gui/bitmapfont.h"
|
||||
#include "display/gui/font.h"
|
||||
|
||||
#include "display/camera.h"
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
|
||||
/** Which is the first character within the font tilemap */
|
||||
#define BITMAP_FONT_CHAR_START 33
|
||||
|
||||
/** Center a font along the X axis */
|
||||
#define BITMAP_FONT_CENTER_X 9876543
|
||||
|
||||
/** Center a font along the Y axis */
|
||||
#define BITMAP_FONT_CENTER_Y -BITMAP_FONT_CENTER_X
|
||||
|
||||
/** Align right edge of font to origin */
|
||||
#define BITMAP_FONT_RIGHT_X (BITMAP_FONT_CENTER_X-1)
|
||||
|
||||
typedef struct {
|
||||
float width, height;
|
||||
int32_t lines;
|
||||
} bitmapfontmeasure_t;
|
||||
@@ -7,19 +7,42 @@
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../texture.h"
|
||||
|
||||
/** Which is the first character within the font tilemap */
|
||||
#define FONT_CHAR_START 33
|
||||
/** Which character (ASCII) to start the font from */
|
||||
#define FONT_FIRST_CHAR 32
|
||||
|
||||
/** Center a font along the X axis */
|
||||
#define FONT_CENTER_X 9876543
|
||||
/** Center a font along the Y axis */
|
||||
#define FONT_CENTER_Y -FONT_CENTER_X
|
||||
/** How many characters (after the first char) to generate */
|
||||
#define FONT_NUM_CHARS 96
|
||||
|
||||
/** Align right edge of font to origin */
|
||||
#define FONT_RIGHT_X (FONT_CENTER_X-1)
|
||||
/** Width of the loaded font texture */
|
||||
#define FONT_TEXTURE_WIDTH 512
|
||||
|
||||
/** Height of the loaded font texture */
|
||||
#define FONT_TEXTURE_HEIGHT FONT_TEXTURE_WIDTH
|
||||
|
||||
/** Refer to STBTT docs for OpenGL Fill Mode v d3d Fill Modes */
|
||||
#define FONT_FILL_MODE 1
|
||||
|
||||
#define FONT_NEWLINE '\n'
|
||||
#define FONT_SPACE ' '
|
||||
#define FONT_LINE_HEIGHT 0.75
|
||||
#define FONT_INITIAL_LINE FONT_LINE_HEIGHT*0.75
|
||||
#define FONT_SPACE_SIZE 0.35
|
||||
|
||||
typedef struct {
|
||||
float size;
|
||||
texture_t texture;
|
||||
stbtt_bakedchar characterData[FONT_NUM_CHARS];
|
||||
} font_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t length;
|
||||
int32_t realChars;
|
||||
float lineHeight, spaceSize;
|
||||
} fonttextinfo_t;
|
||||
|
||||
typedef struct {
|
||||
float width, height;
|
||||
int32_t lines;
|
||||
stbtt_aligned_quad *quads;
|
||||
} fontmeasure_t;
|
||||
+2
-2
@@ -8,6 +8,8 @@
|
||||
// Static Libs
|
||||
#include <cglm/cglm.h>
|
||||
#include <glad/glad.h>
|
||||
#include <stb_image.h>
|
||||
#include <stb_truetype.h>
|
||||
|
||||
// Standard Libs
|
||||
#include <stdio.h>
|
||||
@@ -20,6 +22,4 @@
|
||||
// Windows Fixes
|
||||
# define strtok_r strtok_s
|
||||
# define sleep(n) _sleep(n)
|
||||
#else
|
||||
|
||||
#endif
|
||||
+11
-10
@@ -17,16 +17,17 @@
|
||||
#include "../display/tileset.h"
|
||||
|
||||
/** Rounds that the game can be in */
|
||||
#define POKER_ROUND_DEAL 0x00
|
||||
#define POKER_ROUND_BLINDS 0x01
|
||||
#define POKER_ROUND_BET0 0x02
|
||||
#define POKER_ROUND_FLOP 0X03
|
||||
#define POKER_ROUND_BET1 0x04
|
||||
#define POKER_ROUND_TURN 0x05
|
||||
#define POKER_ROUND_BET2 0x06
|
||||
#define POKER_ROUND_RIVER 0x07
|
||||
#define POKER_ROUND_BET3 0x08
|
||||
#define POKER_ROUND_WINNER 0x09
|
||||
#define POKER_ROUND_MATCH 0x00
|
||||
#define POKER_ROUND_DEAL 0x01
|
||||
#define POKER_ROUND_BLINDS 0x02
|
||||
#define POKER_ROUND_BET0 0x03
|
||||
#define POKER_ROUND_FLOP 0X04
|
||||
#define POKER_ROUND_BET1 0x05
|
||||
#define POKER_ROUND_TURN 0x06
|
||||
#define POKER_ROUND_BET2 0x07
|
||||
#define POKER_ROUND_RIVER 0x08
|
||||
#define POKER_ROUND_BET3 0x09
|
||||
#define POKER_ROUND_WINNER 0x10
|
||||
|
||||
/** How many cards the dealer can hold in their hand */
|
||||
#define POKER_DEALER_HAND 5
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
#include "camera.h"
|
||||
|
||||
void cameraLookAt(camera_t *camera,
|
||||
float x, float y, float z, float targetX, float targetY, float targetZ
|
||||
float x, float y, float z,
|
||||
float targetX, float targetY, float targetZ
|
||||
) {
|
||||
glm_mat4_identity(camera->view);
|
||||
glm_lookat(
|
||||
(vec3){ x, y, z },
|
||||
(vec3){ targetX, targetY, targetZ },
|
||||
(vec3){ 0, 1, 0 },
|
||||
(vec3){ 0,1,0 },
|
||||
camera->view
|
||||
);
|
||||
}
|
||||
@@ -27,7 +28,7 @@ void cameraLook(camera_t *camera,
|
||||
glm_look(
|
||||
(vec3){ x, y, z },
|
||||
(vec3){ pitch, yaw, roll },
|
||||
(vec3){ 0, 1, 0 },
|
||||
(vec3){ 0,1,0 },
|
||||
camera->view
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
* @param targetZ The Target Z position in world space of the camera.
|
||||
*/
|
||||
void cameraLookAt(camera_t *camera,
|
||||
float x, float y, float z, float targetX, float targetY, float targetZ
|
||||
float x, float y, float z,
|
||||
float targetX, float targetY, float targetZ
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "bitmapfont.h"
|
||||
|
||||
tilesetdiv_t * bitmapFontGetCharacterDivision(tileset_t *tileset, char character) {
|
||||
int32_t i = ((int32_t)character) - BITMAP_FONT_CHAR_START;
|
||||
return tileset->divisions + i;
|
||||
}
|
||||
|
||||
bitmapfontmeasure_t bitmapFontMeasure(char *string, float charWidth, float charHeight) {
|
||||
int32_t i;
|
||||
float x, y;
|
||||
char c;
|
||||
bitmapfontmeasure_t measure = {
|
||||
.height = 0, .lines = 1, .width = 0
|
||||
};
|
||||
|
||||
i = 0;
|
||||
y = 0;
|
||||
x = 0;
|
||||
|
||||
while(true) {
|
||||
c = string[i];
|
||||
if(c == '\0') break;
|
||||
i++;
|
||||
|
||||
if(c == '\n') {
|
||||
measure.width = mathMax(x, measure.width);
|
||||
x = 0;
|
||||
y += charHeight;
|
||||
measure.lines++;
|
||||
continue;
|
||||
} else if(c == ' ') {
|
||||
x += charWidth;
|
||||
continue;
|
||||
}
|
||||
|
||||
x += charWidth;
|
||||
}
|
||||
|
||||
measure.width = mathMax(x, measure.width);
|
||||
measure.height = y + charHeight;
|
||||
|
||||
return measure;
|
||||
}
|
||||
|
||||
bitmapfontmeasure_t bitmapFontSpriteBatchBuffer(
|
||||
spritebatch_t *batch, tileset_t *tileset,
|
||||
char *string, float x, float y, float z, float charWidth, float charHeight
|
||||
) {
|
||||
int32_t i;
|
||||
char c;
|
||||
tilesetdiv_t *div;
|
||||
float cx, cy;
|
||||
bitmapfontmeasure_t measure;
|
||||
|
||||
// Detect char dimensions
|
||||
if(charWidth == -1) charWidth = tileset->divX * (charHeight / tileset->divY);
|
||||
if(charHeight == -1) charHeight = tileset->divY * (charWidth / tileset->divX);
|
||||
|
||||
// Position the text.
|
||||
if(x == BITMAP_FONT_CENTER_X ||
|
||||
y == BITMAP_FONT_CENTER_Y ||
|
||||
x == BITMAP_FONT_RIGHT_X
|
||||
) {
|
||||
measure = bitmapFontMeasure(string, charWidth, charHeight);
|
||||
if(x == BITMAP_FONT_CENTER_X) {
|
||||
x = -(measure.width/2);
|
||||
} else if(x == BITMAP_FONT_RIGHT_X) {
|
||||
x = -measure.width;
|
||||
}
|
||||
if(y == BITMAP_FONT_CENTER_Y) y = -(measure.height/2);
|
||||
}
|
||||
|
||||
// Begin buffering the sprite batch
|
||||
measure.width = 0;
|
||||
measure.height = 0;
|
||||
measure.lines = 1;
|
||||
i = 0;
|
||||
cx = x, cy = y;
|
||||
|
||||
while(true) {
|
||||
c = string[i];
|
||||
if(c == '\0') break;
|
||||
i++;
|
||||
|
||||
// Special chars
|
||||
if(c == '\n') {
|
||||
measure.width = mathMax(cx-x, measure.width);
|
||||
cx = x;
|
||||
cy += charHeight;
|
||||
measure.lines++;
|
||||
continue;
|
||||
} else if(c == ' ') {
|
||||
cx += charWidth;
|
||||
continue;
|
||||
}
|
||||
|
||||
div = bitmapFontGetCharacterDivision(tileset, c);
|
||||
spriteBatchQuad(batch, -1,
|
||||
cx, cy, z, charWidth, charHeight,
|
||||
div->x0, div->y1, div->x1, div->y0
|
||||
);
|
||||
cx += charWidth;
|
||||
}
|
||||
|
||||
measure.width = mathMax(cx-x, measure.width);
|
||||
measure.height = cy-y + charHeight;
|
||||
|
||||
return measure;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../spritebatch.h"
|
||||
|
||||
/**
|
||||
* Get the division for a given character.
|
||||
*
|
||||
* @param tileset Tileset to get the division from.
|
||||
* @param character Character to get the division for.
|
||||
* @return The division from the tileset for the character.
|
||||
*/
|
||||
tilesetdiv_t * bitmapFontGetCharacterDivision(tileset_t *tileset, char character);
|
||||
|
||||
/**
|
||||
* Measures a string's fully rendered size.
|
||||
*
|
||||
* @param string The string to measure
|
||||
* @param charWidth The width of each character.
|
||||
* @param charHeight The height of each character.
|
||||
* @return The measured string.
|
||||
*/
|
||||
bitmapfontmeasure_t bitmapFontMeasure(char *string, float charWidth, float charHeight);
|
||||
|
||||
/**
|
||||
* Renders a set of font characters to the sprite. Coordinates are anchored to
|
||||
* the top left (0,0) origin.
|
||||
*
|
||||
* @param batch Sprite Batch to render to.
|
||||
* @param tileset Tileset for the font.
|
||||
* @param string String to render.
|
||||
* @param x Position in X space.
|
||||
* @param y Position in Y space.
|
||||
* @param z Position in Z space.
|
||||
* @param charWidth Width of each character. Set to -1 to use the height ratio.
|
||||
* @param charHeight Height of each character. Set to -1 to be the width ratio.
|
||||
* @returns The string measurement.
|
||||
*/
|
||||
bitmapfontmeasure_t bitmapFontSpriteBatchBuffer(spritebatch_t *batch, tileset_t *tileset,
|
||||
char *string, float x, float y, float z, float charWidth, float charHeight
|
||||
);
|
||||
+110
-82
@@ -7,109 +7,137 @@
|
||||
|
||||
#include "font.h"
|
||||
|
||||
tilesetdiv_t * fontGetCharacterDivision(tileset_t *tileset, char character) {
|
||||
int32_t i = ((int32_t)character) - FONT_CHAR_START;
|
||||
return tileset->divisions + i;
|
||||
// Due to some compiler bullshit, this is here.
|
||||
#ifndef STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include <stb_truetype.h>
|
||||
#endif
|
||||
|
||||
void fontInit(font_t *font, char *data, float size) {
|
||||
int32_t i, s;
|
||||
s = FONT_TEXTURE_WIDTH * FONT_TEXTURE_HEIGHT;
|
||||
|
||||
uint8_t *bitmapData = malloc(sizeof(uint8_t) * s);
|
||||
pixel_t *pixels = malloc(sizeof(pixel_t) * s);
|
||||
|
||||
font->size = size;
|
||||
|
||||
// STBTT Loads fonts as single channel values only.
|
||||
stbtt_BakeFontBitmap(
|
||||
data, 0, size, bitmapData,
|
||||
FONT_TEXTURE_WIDTH, FONT_TEXTURE_HEIGHT,
|
||||
FONT_FIRST_CHAR, FONT_NUM_CHARS,
|
||||
font->characterData
|
||||
);
|
||||
|
||||
for(i = 0; i < FONT_TEXTURE_WIDTH * FONT_TEXTURE_HEIGHT; i++) {
|
||||
pixels[i].r = 0xFF;
|
||||
pixels[i].g = 0xFF;
|
||||
pixels[i].b = 0xFF;
|
||||
pixels[i].a = bitmapData[i];
|
||||
}
|
||||
textureInit(&font->texture, FONT_TEXTURE_WIDTH, FONT_TEXTURE_HEIGHT, pixels);
|
||||
|
||||
free(bitmapData);
|
||||
free(pixels);
|
||||
}
|
||||
|
||||
fontmeasure_t fontMeasure(char *string, float charWidth, float charHeight) {
|
||||
int32_t i;
|
||||
fonttextinfo_t fontGetTextInfo(font_t *font, char *text) {
|
||||
float x, y;
|
||||
char c;
|
||||
fontmeasure_t measure = {
|
||||
.height = 0, .lines = 1, .width = 0
|
||||
int32_t i;
|
||||
fonttextinfo_t info = {
|
||||
.length = 0,
|
||||
.realChars = 0,
|
||||
.lineHeight = FONT_LINE_HEIGHT * font->size,
|
||||
.spaceSize = font->size * FONT_SPACE_SIZE
|
||||
};
|
||||
|
||||
// Count how many "real characters" are in the string.
|
||||
i = 0;
|
||||
y = 0;
|
||||
x = 0;
|
||||
while(c = text[i++]) {
|
||||
info.length++;
|
||||
if(c == FONT_SPACE) continue;
|
||||
if(c == FONT_NEWLINE) continue;
|
||||
info.realChars++;
|
||||
}
|
||||
|
||||
while(true) {
|
||||
c = string[i];
|
||||
if(c == '\0') break;
|
||||
i++;
|
||||
|
||||
if(c == '\n') {
|
||||
measure.width = mathMax(x, measure.width);
|
||||
x = 0;
|
||||
y += charHeight;
|
||||
measure.lines++;
|
||||
continue;
|
||||
} else if(c == ' ') {
|
||||
x += charWidth;
|
||||
return info;
|
||||
}
|
||||
|
||||
fontmeasure_t * fontTextMeasure(font_t *font,char *text,fonttextinfo_t *info) {
|
||||
int32_t i, j;
|
||||
char c;
|
||||
float x, y;
|
||||
stbtt_aligned_quad *quad;
|
||||
fontmeasure_t *measure;
|
||||
|
||||
measure = malloc(sizeof(fontmeasure_t));
|
||||
measure->quads = malloc(sizeof(stbtt_aligned_quad) * info->realChars);
|
||||
|
||||
x = 0;
|
||||
y = FONT_INITIAL_LINE * font->size;
|
||||
|
||||
i = 0, j = 0;
|
||||
while(c = text[i++]) {
|
||||
if(c == FONT_SPACE) {
|
||||
x += info->spaceSize;
|
||||
continue;
|
||||
}
|
||||
|
||||
x += charWidth;
|
||||
if(c == FONT_NEWLINE) {
|
||||
y += info->lineHeight;
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Calculate the quad of the character, store into the array.
|
||||
quad = measure->quads + j;
|
||||
stbtt_GetBakedQuad(font->characterData,
|
||||
FONT_TEXTURE_WIDTH, FONT_TEXTURE_HEIGHT, ((int32_t)c)-FONT_FIRST_CHAR,
|
||||
&x, &y, quad, FONT_FILL_MODE
|
||||
);
|
||||
j++;
|
||||
}
|
||||
|
||||
measure.width = mathMax(x, measure.width);
|
||||
measure.height = y + charHeight;
|
||||
|
||||
return measure;
|
||||
}
|
||||
|
||||
fontmeasure_t fontSpriteBatchBuffer(spritebatch_t *batch, tileset_t *tileset,
|
||||
char *string, float x, float y, float z, float charWidth, float charHeight
|
||||
void fontTextMeasureDispose(fontmeasure_t *measure) {
|
||||
free(measure->quads);
|
||||
free(measure);
|
||||
}
|
||||
|
||||
void fontTextBufferFromMeasure(font_t *font, primitive_t *primitive, char *text,
|
||||
fontmeasure_t *measure
|
||||
) {
|
||||
int32_t i;
|
||||
stbtt_aligned_quad *quad;
|
||||
int32_t i, j;
|
||||
char c;
|
||||
tilesetdiv_t *div;
|
||||
float cx, cy;
|
||||
fontmeasure_t measure;
|
||||
|
||||
// Detect char dimensions
|
||||
if(charWidth == -1) charWidth = tileset->divX * (charHeight / tileset->divY);
|
||||
if(charHeight == -1) charHeight = tileset->divY * (charWidth / tileset->divX);
|
||||
|
||||
// Position the text.
|
||||
if(x == FONT_CENTER_X ||
|
||||
y == FONT_CENTER_Y ||
|
||||
x == FONT_RIGHT_X
|
||||
) {
|
||||
measure = fontMeasure(string, charWidth, charHeight);
|
||||
if(x == FONT_CENTER_X) {
|
||||
x = -(measure.width/2);
|
||||
} else if(x == FONT_RIGHT_X) {
|
||||
x = -measure.width;
|
||||
}
|
||||
if(y == FONT_CENTER_Y) y = -(measure.height/2);
|
||||
}
|
||||
|
||||
// Begin buffering the sprite batch
|
||||
measure.width = 0;
|
||||
measure.height = 0;
|
||||
measure.lines = 1;
|
||||
i = 0;
|
||||
cx = x, cy = y;
|
||||
|
||||
while(true) {
|
||||
c = string[i];
|
||||
if(c == '\0') break;
|
||||
i++;
|
||||
|
||||
// Special chars
|
||||
if(c == '\n') {
|
||||
measure.width = mathMax(cx-x, measure.width);
|
||||
cx = x;
|
||||
cy += charHeight;
|
||||
measure.lines++;
|
||||
continue;
|
||||
} else if(c == ' ') {
|
||||
cx += charWidth;
|
||||
continue;
|
||||
}
|
||||
|
||||
div = fontGetCharacterDivision(tileset, c);
|
||||
spriteBatchQuad(batch, -1,
|
||||
cx, cy, z, charWidth, charHeight,
|
||||
div->x0, div->y1, div->x1, div->y0
|
||||
i = 0, j = 0;
|
||||
while(c = text[i++]) {
|
||||
if(c == FONT_SPACE) continue;
|
||||
if(c == FONT_NEWLINE) continue;
|
||||
quad = measure->quads + j;
|
||||
quadBuffer(primitive, 0,
|
||||
quad->x0, quad->y0, quad->s0, quad->t0,
|
||||
quad->x1, quad->y1, quad->s1, quad->t1,
|
||||
j*QUAD_VERTICE_COUNT, j*QUAD_INDICE_COUNT
|
||||
);
|
||||
cx += charWidth;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
measure.width = mathMax(cx-x, measure.width);
|
||||
measure.height = cy-y + charHeight;
|
||||
void fontTextInitFromMeasure(font_t *font, primitive_t *primitive, char *text,
|
||||
fonttextinfo_t *info, fontmeasure_t *measure
|
||||
) {
|
||||
primitiveInit(primitive,
|
||||
QUAD_VERTICE_COUNT*info->realChars, QUAD_INDICE_COUNT*info->realChars
|
||||
);
|
||||
fontTextBufferFromMeasure(font, primitive, text, measure);
|
||||
}
|
||||
|
||||
return measure;
|
||||
void fontDispose(font_t *font) {
|
||||
textureDispose(&font->texture);
|
||||
}
|
||||
+58
-28
@@ -6,42 +6,72 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
#include "../spritebatch.h"
|
||||
#include "../texture.h"
|
||||
#include "../primitive.h"
|
||||
#include "../primitives/quad.h"
|
||||
|
||||
/**
|
||||
* Get the division for a given character.
|
||||
*
|
||||
* @param tileset Tileset to get the division from.
|
||||
* @param character Character to get the division for.
|
||||
* @return The division from the tileset for the character.
|
||||
* Initializes Font from raw TTF data.
|
||||
* @param font Font to initialize
|
||||
* @param data Data to intialize for.
|
||||
* @param size Font size to load the font in.
|
||||
*/
|
||||
tilesetdiv_t * fontGetCharacterDivision(tileset_t *tileset, char character);
|
||||
void fontInit(font_t *font, char *data, float size);
|
||||
|
||||
/**
|
||||
* Measures a string's fully rendered size.
|
||||
*
|
||||
* @param string The string to measure
|
||||
* @param charWidth The width of each character.
|
||||
* @param charHeight The height of each character.
|
||||
* @return The measured string.
|
||||
* Generates information about how the given font will render the given text.
|
||||
* @param font Font to get the information for.
|
||||
* @param text Text that will be used to render
|
||||
* @return Some information about how the font will render the text.
|
||||
*/
|
||||
fontmeasure_t fontMeasure(char *string, float charWidth, float charHeight);
|
||||
fonttextinfo_t fontGetTextInfo(font_t *font, char *text);
|
||||
|
||||
/**
|
||||
* Renders a set of font characters to the sprite. Coordinates are anchored to
|
||||
* the top left (0,0) origin.
|
||||
* Measures (and calculates the quads for) a text prior to rendering it.
|
||||
*
|
||||
* @param batch Sprite Batch to render to.
|
||||
* @param tileset Tileset for the font.
|
||||
* @param string String to render.
|
||||
* @param x Position in X space.
|
||||
* @param y Position in Y space.
|
||||
* @param z Position in Z space.
|
||||
* @param charWidth Width of each character. Set to -1 to use the height ratio.
|
||||
* @param charHeight Height of each character. Set to -1 to be the width ratio.
|
||||
* @returns The string measurement.
|
||||
* @param font Font to use for rendering and measuring
|
||||
* @param text Text to measure/render.
|
||||
* @param info Info about the text being rendered / measured.
|
||||
* @returns Font measurement calculation.
|
||||
*/
|
||||
fontmeasure_t fontSpriteBatchBuffer(spritebatch_t *batch, tileset_t *tileset,
|
||||
char *string, float x, float y, float z, float charWidth, float charHeight
|
||||
);
|
||||
fontmeasure_t * fontTextMeasure(font_t *font, char *text, fonttextinfo_t *info);
|
||||
|
||||
/**
|
||||
* Disposes a previously calculated font text measurement.
|
||||
* @param measure Measurement to dispose.
|
||||
*/
|
||||
void fontTextMeasureDispose(fontmeasure_t *measure);
|
||||
|
||||
/**
|
||||
* Buffers the vertices of a font text onto a primitive. Requires some info
|
||||
* about how the font is meant to render from the text info section.
|
||||
*
|
||||
* @param font Font to render.
|
||||
* @param primitive Primitive to render into.
|
||||
* @param text Text to render.
|
||||
* @param measure The precalculated measurement.
|
||||
*/
|
||||
void fontTextBufferFromMeasure(font_t *font, primitive_t *primitive, char *text,
|
||||
fontmeasure_t *measure
|
||||
);
|
||||
|
||||
/**
|
||||
* Initializes an uninitialized primitive for rendering.
|
||||
*
|
||||
* @param font Font to render.
|
||||
* @param primitive Primitive to render into.
|
||||
* @param text Text to render.
|
||||
* @param info Text Info to use while rendering.
|
||||
* @param measure The pre calcuted font measurement.
|
||||
*/
|
||||
void fontTextInitFromMeasure(font_t *font, primitive_t *primitive, char *text,
|
||||
fonttextinfo_t *info, fontmeasure_t *measure
|
||||
);
|
||||
|
||||
/**
|
||||
* Clean up a previously loaded font
|
||||
* @param font Loaded font.
|
||||
*/
|
||||
void fontDispose(font_t *Font);
|
||||
@@ -7,6 +7,12 @@
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
// Due to some compiler bullshit, this is here.
|
||||
#ifndef STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
#endif
|
||||
|
||||
void textureInit(texture_t *texture, int32_t width, int32_t height,
|
||||
pixel_t *pixels
|
||||
) {
|
||||
|
||||
+6
-4
@@ -7,10 +7,6 @@
|
||||
|
||||
#include "asset.h"
|
||||
|
||||
// Due to some bullshit, this is here.
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
|
||||
char * assetStringLoad(char *assetName) {
|
||||
// Open a buffer.
|
||||
FILE *fptr = assetBufferOpen(assetName);
|
||||
@@ -121,4 +117,10 @@ void assetTextureLoad(texture_t *texture, char *fileName) {
|
||||
// Turn into a texture.
|
||||
textureInit(texture, width, height, data);
|
||||
stbi_image_free(data);
|
||||
}
|
||||
|
||||
void assetFontLoad(font_t *font, char *assetName, float size) {
|
||||
char *data = assetStringLoad(assetName);
|
||||
fontInit(font, data, size);
|
||||
free(data);
|
||||
}
|
||||
+10
-1
@@ -9,6 +9,7 @@
|
||||
#include <dawn/dawn.h>
|
||||
#include "../display/shader.h"
|
||||
#include "../display/texture.h"
|
||||
#include "../display/gui/font.h"
|
||||
|
||||
/**
|
||||
* Method to load an asset into memory as a raw string.
|
||||
@@ -67,4 +68,12 @@ void assetShaderLoad(shader_t *shader, char *fileVertex, char *fileFragment);
|
||||
* @param texture Texture to load the file into.
|
||||
* @param fileName The file path of the PNG image.
|
||||
*/
|
||||
void assetTextureLoad(texture_t *texture, char *fileName);
|
||||
void assetTextureLoad(texture_t *texture, char *fileName);
|
||||
|
||||
/**
|
||||
* Load a font from a TTF file.
|
||||
* @param font Font to load into.
|
||||
* @param assetName Asset name for the TTF font.
|
||||
* @param size Size of the font.
|
||||
*/
|
||||
void assetFontLoad(font_t *font, char *assetName, float size);
|
||||
+43
-1
@@ -7,6 +7,12 @@
|
||||
|
||||
#include "game.h"
|
||||
|
||||
font_t font;
|
||||
primitive_t quad;
|
||||
|
||||
texture_t mom;
|
||||
primitive_t cube;
|
||||
|
||||
bool gameInit(game_t *game) {
|
||||
// Init the game
|
||||
game->name = GAME_NAME;
|
||||
@@ -17,6 +23,17 @@ bool gameInit(game_t *game) {
|
||||
// Hand off to the poker logic.
|
||||
pokerInit(&game->poker);
|
||||
|
||||
assetFontLoad(&font, "fonts/opensans/OpenSans-Bold.ttf", 64.0);
|
||||
|
||||
char *text = "Ayy\nNice meme";
|
||||
fonttextinfo_t info = fontGetTextInfo(&font, text);
|
||||
fontmeasure_t *measure = fontTextMeasure(&font, text, &info);
|
||||
fontTextInitFromMeasure(&font, &quad, text, &info, measure);
|
||||
fontTextMeasureDispose(measure);
|
||||
|
||||
quadInit(&cube, 0, 0,0,0,0, 923,576,1,1);
|
||||
assetTextureLoad(&mom, "cards_normal.png");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,7 +42,32 @@ bool gameUpdate(game_t *game, float platformDelta) {
|
||||
engineUpdateStart(&game->engine, game, platformDelta);
|
||||
|
||||
// Hand off to the poker logic
|
||||
pokerUpdate(&game->poker, &game->engine.render);
|
||||
shaderUse(&game->poker.shader);
|
||||
|
||||
// cameraPerspective(&game->poker.camera, 45,
|
||||
// game->engine.render.width/game->engine.render.height,
|
||||
// 0.01, 1000
|
||||
// );
|
||||
// cameraLookAt(&game->poker.camera, 300,300,300, 0,0,0);
|
||||
|
||||
cameraOrtho(&game->poker.camera,
|
||||
0, game->engine.render.width,
|
||||
game->engine.render.height, 0,
|
||||
0.1, 1000
|
||||
);
|
||||
cameraLookAt(&game->poker.camera, 0,0,5, 0,0,-5);
|
||||
|
||||
shaderUseCamera(&game->poker.shader, &game->poker.camera);
|
||||
|
||||
shaderUseTexture(&game->poker.shader, &font.texture);
|
||||
shaderUsePosition(&game->poker.shader, 0,0,0, 0,0,0);
|
||||
primitiveDraw(&quad, 0, -1);
|
||||
|
||||
// shaderUseTexture(&game->poker.shader, &mom);
|
||||
// shaderUsePosition(&game->poker.shader, 0,0,0, 0,0,0);
|
||||
// primitiveDraw(&cube, 0, -1);
|
||||
|
||||
// pokerUpdate(&game->poker, &game->engine.render);
|
||||
|
||||
// Hand back to the engine.
|
||||
return engineUpdateEnd(&game->engine, game);
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
#include "../engine/engine.h"
|
||||
#include "../poker/poker.h"
|
||||
|
||||
#include "../display/camera.h"
|
||||
#include "../display/shader.h"
|
||||
#include "../display/gui/font.h"
|
||||
#include "../display/primitives/quad.h"
|
||||
#include "../display/primitives/cube.h"
|
||||
|
||||
/**
|
||||
* Initialize the game context.
|
||||
*
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "glwfwplatform.h"
|
||||
|
||||
game_t GAME_STATE;
|
||||
game_t *GAME_STATE;
|
||||
|
||||
GLFWwindow *window = NULL;
|
||||
|
||||
@@ -37,7 +37,8 @@ int32_t main() {
|
||||
glfwSetErrorCallback(&glfwOnError);
|
||||
|
||||
// Prepare the game
|
||||
game_t *game = &GAME_STATE;
|
||||
game_t *game = malloc(sizeof(game_t));
|
||||
GAME_STATE = game;
|
||||
input_t *input = &game->engine.input;
|
||||
|
||||
// Init the game
|
||||
@@ -69,7 +70,7 @@ int32_t main() {
|
||||
);
|
||||
|
||||
// Update the window title.
|
||||
glfwSetWindowTitle(window, GAME_STATE.name);
|
||||
glfwSetWindowTitle(window, GAME_STATE->name);
|
||||
|
||||
double time = 0;
|
||||
|
||||
@@ -91,6 +92,7 @@ int32_t main() {
|
||||
// Game has finished running, cleanup.
|
||||
gameDispose(game);
|
||||
}
|
||||
free(game);
|
||||
|
||||
// Terminate the GLFW context.
|
||||
glfwSetWindowSizeCallback(window, NULL);
|
||||
@@ -100,13 +102,13 @@ int32_t main() {
|
||||
}
|
||||
|
||||
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height) {
|
||||
renderSetResolution(&GAME_STATE.engine.render, width, height);
|
||||
renderSetResolution(&GAME_STATE->engine.render, width, height);
|
||||
}
|
||||
|
||||
void glfwOnKey(GLFWwindow *window,
|
||||
int32_t key, int32_t scancode, int32_t action, int32_t mods
|
||||
) {
|
||||
input_t *input = &GAME_STATE.engine.input;
|
||||
input_t *input = &GAME_STATE->engine.input;
|
||||
if(action == GLFW_PRESS) {
|
||||
input->buffer[key] = 1;
|
||||
} else if(action == GLFW_RELEASE) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#define WINDOW_HEIGHT_DEFAULT 270
|
||||
|
||||
/** The current running game state. */
|
||||
extern game_t GAME_STATE;
|
||||
extern game_t *GAME_STATE;
|
||||
|
||||
/** The GLFW Window Context Pointer */
|
||||
extern GLFWwindow *window;
|
||||
|
||||
+10
-18
@@ -8,8 +8,6 @@
|
||||
#include "poker.h"
|
||||
|
||||
void pokerInit(poker_t *poker) {
|
||||
uint8_t x;
|
||||
|
||||
// Load the main shader
|
||||
assetShaderLoad(&poker->shader,
|
||||
"shaders/textured.vert", "shaders/textured.frag"
|
||||
@@ -20,28 +18,22 @@ void pokerInit(poker_t *poker) {
|
||||
pokerCardInit(poker);
|
||||
pokerPlayerInit(poker);
|
||||
|
||||
// Reset the main game state. This does not init the round.
|
||||
poker->blindBig = POKER_BLIND_BIG_DEFAULT;
|
||||
poker->blindSmall = POKER_BLIND_SMALL_DEFAULT;
|
||||
poker->roundDealer = 0x00;
|
||||
|
||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
||||
poker->players[x].state = 0x00;
|
||||
poker->players[x].chips = POKER_PLAYER_CHIPS_DEFAULT;
|
||||
}
|
||||
|
||||
// Hand over to the deal for the first time.
|
||||
pokerDealInit(poker);
|
||||
pokerMatchInit(poker);
|
||||
}
|
||||
|
||||
void pokerUpdate(poker_t *poker, render_t *render) {
|
||||
// Game Logic
|
||||
|
||||
// TEMP
|
||||
switch(poker->round) {
|
||||
case POKER_ROUND_MATCH:
|
||||
pokerMatchUpdate(poker);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Rendering
|
||||
cameraPerspective(&poker->camera, 20,render->width/render->height,0.001,1000);
|
||||
pokerLookAtPlayer(&poker->camera, pokerPlayerGetSeatForPlayer(0x00));
|
||||
|
||||
// Render Logic
|
||||
shaderUse(&poker->shader);
|
||||
shaderUseCamera(&poker->shader, &poker->camera);
|
||||
|
||||
|
||||
+1
-2
@@ -7,14 +7,13 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "round/deal.h"
|
||||
#include "round/match.h"
|
||||
#include "render/world.h"
|
||||
#include "render/card.h"
|
||||
#include "render/player.h"
|
||||
#include "render/look.h"
|
||||
#include "../file/asset.h"
|
||||
#include "../display/shader.h"
|
||||
|
||||
#include "../display/camera.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "blinds.h"
|
||||
|
||||
void pokerBlindsInit(poker_t *poker) {
|
||||
poker->round = POKER_ROUND_BLINDS;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Initializes the blinds round.
|
||||
* @param poker The poker game conetxt.
|
||||
*/
|
||||
void pokerBlindsInit(poker_t *poker);
|
||||
@@ -32,6 +32,7 @@ void pokerDealInit(poker_t *poker) {
|
||||
}
|
||||
|
||||
// Hard look at the dealer
|
||||
pokerLookAtPlayer(&poker->camera, POKER_SEAT_DEALER);
|
||||
|
||||
// Shuffle the deck
|
||||
for(x = 0; x < CARD_DECK_SIZE - 1; x++) {
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "blinds.h"
|
||||
#include "../render/look.h"
|
||||
|
||||
/**
|
||||
* Resets a poker game for the new round.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include "match.h"
|
||||
|
||||
void pokerMatchInit(poker_t *poker) {
|
||||
uint8_t x;
|
||||
// Reset the main game state. This does not init the round.
|
||||
poker->blindBig = POKER_BLIND_BIG_DEFAULT;
|
||||
poker->blindSmall = POKER_BLIND_SMALL_DEFAULT;
|
||||
poker->roundDealer = 0x00;
|
||||
|
||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
||||
poker->players[x].state = 0x00;
|
||||
poker->players[x].chips = POKER_PLAYER_CHIPS_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
void pokerMatchUpdate(poker_t *poker) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "deal.h"
|
||||
|
||||
/**
|
||||
* Init the poker match round.
|
||||
* @param poker The poker game context.
|
||||
*/
|
||||
void pokerMatchInit(poker_t *poker);
|
||||
|
||||
/**
|
||||
* Update the poker match round.
|
||||
* @param poker The poker match to update for.
|
||||
*/
|
||||
void pokerMatchUpdate(poker_t *poker);
|
||||
Reference in New Issue
Block a user