Text rendering to screen, assetmanager merged to gamestate
This commit is contained in:
@@ -29,38 +29,35 @@ enum TerrainCoords
|
||||
typedef struct TexAtlas
|
||||
{
|
||||
// TODO(doyle): String hash based lookup
|
||||
v4 texRect[16];
|
||||
|
||||
v4 texRect[128];
|
||||
} 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;
|
||||
|
||||
v2i codepointRange;
|
||||
} AssetManager;
|
||||
|
||||
extern AssetManager assetManager;
|
||||
GLOBAL_VAR AssetManager assetManager;
|
||||
|
||||
/* Texture */
|
||||
Texture *asset_getTexture(const enum TexList type);
|
||||
TexAtlas *asset_getTextureAtlas(const enum TexList type);
|
||||
const i32 asset_loadTextureImage(const char *const path,
|
||||
Texture *asset_getTexture(AssetManager *assetManager, const enum TexList type);
|
||||
TexAtlas *asset_getTextureAtlas(AssetManager *assetManager,
|
||||
const enum TexList type);
|
||||
const i32 asset_loadTextureImage(AssetManager *assetManager,
|
||||
const char *const path,
|
||||
const enum TexList type);
|
||||
|
||||
/* Shaders */
|
||||
Shader *asset_getShader(const enum ShaderList type);
|
||||
const i32 asset_loadShaderFiles(const char *const vertexPath,
|
||||
Shader *asset_getShader(AssetManager *assetManager, const enum ShaderList type);
|
||||
const i32 asset_loadShaderFiles(AssetManager *assetManager,
|
||||
const char *const vertexPath,
|
||||
const char *const fragmentPath,
|
||||
const enum ShaderList type);
|
||||
|
||||
const i32 asset_loadTTFont(const char *filePath);
|
||||
const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath);
|
||||
#endif
|
||||
|
||||
@@ -39,17 +39,6 @@ typedef struct Entity
|
||||
i32 currAnimIndex;
|
||||
} Entity;
|
||||
|
||||
INTERNAL inline v4 getRect(v2 origin, v2 size)
|
||||
{
|
||||
v2 upperLeftBound = v2_add(origin, V2(0.0f, size.y));
|
||||
v2 lowerRightBound = v2_add(origin, V2(size.x, 0.0f));
|
||||
|
||||
v4 result = V4(upperLeftBound.x, upperLeftBound.y, lowerRightBound.x,
|
||||
lowerRightBound.y);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
INTERNAL inline v4 getEntityScreenRect(Entity entity)
|
||||
{
|
||||
v4 result = getRect(entity.pos, entity.size);
|
||||
|
||||
@@ -258,4 +258,25 @@ INTERNAL inline v4 mat4_mul_v4(const mat4 a, const v4 b)
|
||||
return result;
|
||||
}
|
||||
|
||||
INTERNAL inline v4 getRect(v2 origin, v2 size)
|
||||
{
|
||||
v2 upperLeftBound = v2_add(origin, V2(0.0f, size.y));
|
||||
v2 lowerRightBound = v2_add(origin, V2(size.x, 0.0f));
|
||||
|
||||
v4 result = V4(upperLeftBound.x, upperLeftBound.y, lowerRightBound.x,
|
||||
lowerRightBound.y);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
INTERNAL inline v2 getRectSize(v4 rect)
|
||||
{
|
||||
f32 width = absolute(rect.x - rect.z);
|
||||
f32 height = absolute(rect.y - rect.w);
|
||||
|
||||
v2 result = V2(width, height);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,23 @@ void renderer_entity(Renderer *renderer, Entity *entity, f32 rotate,
|
||||
void renderer_object(Renderer *renderer, v2 pos, v2 size, f32 rotate, v3 color,
|
||||
Texture *tex);
|
||||
|
||||
INTERNAL inline void renderer_flipTexCoord(v4 *texCoords, b32 flipX, b32 flipY)
|
||||
{
|
||||
if (flipX)
|
||||
{
|
||||
v4 tmp = *texCoords;
|
||||
texCoords->x = tmp.z;
|
||||
texCoords->z = tmp.x;
|
||||
}
|
||||
|
||||
if (flipY)
|
||||
{
|
||||
v4 tmp = *texCoords;
|
||||
texCoords->y = tmp.w;
|
||||
texCoords->w = tmp.y;
|
||||
}
|
||||
}
|
||||
|
||||
INTERNAL inline RenderQuad renderer_createQuad(v4 quadRectNdc, v4 texRectNdc)
|
||||
{
|
||||
// NOTE(doyle): Draws a series of triangles (three-sided polygons) using
|
||||
|
||||
@@ -42,6 +42,8 @@ typedef struct GameState
|
||||
// TODO(doyle): Make size of list dynamic
|
||||
Entity entityList[256];
|
||||
i32 freeEntityIndex;
|
||||
|
||||
AssetManager assetManager;
|
||||
} GameState;
|
||||
|
||||
void worldTraveller_gameInit(GameState *state);
|
||||
|
||||
Reference in New Issue
Block a user