Rudimentary font rasterisation at runtime with STB
This commit is contained in:
@@ -4,10 +4,13 @@
|
||||
#include "Dengine/Shader.h"
|
||||
#include "Dengine/Texture.h"
|
||||
|
||||
#define MAX_TEXTURE_SIZE 1024
|
||||
|
||||
enum TexList
|
||||
{
|
||||
texlist_hero,
|
||||
texlist_terrain,
|
||||
texlist_font,
|
||||
texlist_count,
|
||||
};
|
||||
|
||||
@@ -30,12 +33,19 @@ typedef struct TexAtlas
|
||||
|
||||
} TexAtlas;
|
||||
|
||||
typedef struct GlyphBitmap
|
||||
{
|
||||
v2i dimensions;
|
||||
u32 *pixels;
|
||||
} GlyphBitmap;
|
||||
|
||||
// TODO(doyle): Switch to hash based lookup
|
||||
typedef struct AssetManager
|
||||
{
|
||||
Texture textures[256];
|
||||
TexAtlas texAtlas[256];
|
||||
Shader shaders[256];
|
||||
Texture font;
|
||||
} AssetManager;
|
||||
|
||||
extern AssetManager assetManager;
|
||||
@@ -52,4 +62,5 @@ const i32 asset_loadShaderFiles(const char *const vertexPath,
|
||||
const char *const fragmentPath,
|
||||
const enum ShaderList type);
|
||||
|
||||
const i32 asset_loadTTFont(const char *filePath);
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define WT_DEBUG
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
#define absolute(x) ((x) > 0 ? (x) : -(x))
|
||||
|
||||
/* VECTORS */
|
||||
typedef union v2i
|
||||
{
|
||||
struct { i32 x, y; };
|
||||
struct { i32 w, h; };
|
||||
i32 e[2];
|
||||
} v2i;
|
||||
|
||||
typedef union v2
|
||||
{
|
||||
struct { f32 x, y; };
|
||||
@@ -30,6 +37,11 @@ typedef union v4
|
||||
f32 e[4];
|
||||
} v4;
|
||||
|
||||
INTERNAL inline v2i V2i(const i32 x, const i32 y)
|
||||
{
|
||||
v2i result = {x, y};
|
||||
return result;
|
||||
}
|
||||
INTERNAL inline v2 V2(const f32 x, const f32 y)
|
||||
{
|
||||
v2 result = {x, y};
|
||||
@@ -63,7 +75,7 @@ INTERNAL inline v4 V4(const f32 x, const f32 y, const f32 z, const f32 w)
|
||||
This is repeated for v3 and v4 for the basic math operations
|
||||
*/
|
||||
|
||||
#define DEFINE_VECTOR_MATH(num) \
|
||||
#define DEFINE_VECTOR_FLOAT_MATH(num) \
|
||||
INTERNAL inline v##num v##num##_add(const v##num a, const v##num b) \
|
||||
{ \
|
||||
v##num result; \
|
||||
@@ -109,9 +121,19 @@ INTERNAL inline b32 v##num##_equals(const v##num a, const v##num b) \
|
||||
return result; \
|
||||
} \
|
||||
|
||||
DEFINE_VECTOR_MATH(2);
|
||||
DEFINE_VECTOR_MATH(3);
|
||||
DEFINE_VECTOR_MATH(4);
|
||||
DEFINE_VECTOR_FLOAT_MATH(2);
|
||||
DEFINE_VECTOR_FLOAT_MATH(3);
|
||||
DEFINE_VECTOR_FLOAT_MATH(4);
|
||||
|
||||
#define DEFINE_VECTOR_INT_MATH(num) \
|
||||
INTERNAL inline v##num##i v##num##i_add(const v##num##i a, const v##num##i b) \
|
||||
{ \
|
||||
v##num##i result; \
|
||||
for (i32 i = 0; i < ##num; i++) { result.e[i] = a.e[i] + b.e[i]; } \
|
||||
return result; \
|
||||
} \
|
||||
|
||||
DEFINE_VECTOR_INT_MATH(2);
|
||||
|
||||
INTERNAL inline v3 v3_cross(const v3 a, const v3 b)
|
||||
{
|
||||
|
||||
@@ -10,12 +10,12 @@ typedef struct
|
||||
{
|
||||
void *buffer;
|
||||
i32 size;
|
||||
} PlatformFileReadResult;
|
||||
} PlatformFileRead;
|
||||
|
||||
i32 platform_readFileToBuffer(const char *const filePath,
|
||||
PlatformFileReadResult *file);
|
||||
PlatformFileRead *file);
|
||||
|
||||
inline void platform_closeFileReadResult(PlatformFileReadResult *file)
|
||||
inline void platform_closeFileRead(PlatformFileRead *file)
|
||||
{
|
||||
if (file->buffer)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include "Dengine/Common.h"
|
||||
#include "Dengine/OpenGL.h"
|
||||
|
||||
#define TARGET_TEXTURE_SIZE 1024
|
||||
#define TARGET_BYTES_PER_PIXEL 4
|
||||
|
||||
typedef struct Texture
|
||||
{
|
||||
// Holds the ID of the texture object, used for all texture operations to
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef WORLDTRAVELLER_GAME_H
|
||||
#define WORLDTRAVELLER_GAME_H
|
||||
|
||||
#include <Dengine/Common.h>
|
||||
#include <Dengine/Entity.h>
|
||||
#include <Dengine/Renderer.h>
|
||||
#include "Dengine/Common.h"
|
||||
#include "Dengine/Entity.h"
|
||||
#include "Dengine/Renderer.h"
|
||||
|
||||
#define NUM_KEYS 1024
|
||||
#define METERS_TO_PIXEL 100
|
||||
|
||||
Reference in New Issue
Block a user