Added UITexture and font caching

This commit is contained in:
grayson committed 2021-09-02 02:21:27 -05:00
1 parent 2af54c4d9e
commit dff0d86558
26 files changed
+252 -60

No files matched your search

+5 -1
View File
@@ -3,15 +3,17 @@
namespace nf {
class Model;
class Texture;
struct Font;
struct Asset {
char* data;
bool alreadyLoaded = false;
virtual ~Asset();
};
struct AModel : Asset {
bool alreadyLoaded;
Model* loadedModel;
~AModel() override;
@@ -19,6 +21,7 @@ namespace nf {
struct ATexture : Asset {
size_t size;
Texture* loadedTexture;
~ATexture() override;
};
@@ -29,6 +32,7 @@ namespace nf {
struct AFont : Asset {
size_t size;
Font* loadedFont;
~AFont() override;
};
+3 -1
View File
@@ -1,14 +1,16 @@
#pragma once
#include "Drawable.h"
#include "Assets.h"
namespace nf {
class Drawable;
class Texture;
class Model : public Drawable {
public:
Model();
void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinates, size_t textureCoordinatesBufferSize, const char* textureData, size_t textureSize);
void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinates, size_t textureCoordinatesBufferSize, ATexture* texture);
void bind() override;
~Model();
+1
View File
@@ -10,6 +10,7 @@
#include "IntroGamestate.h"
#include "Assets.h"
#include "Text.h"
#include "UITexture.h"
#include "Input.h"
namespace nf {
+1
View File
@@ -32,5 +32,6 @@ namespace nf {
std::vector<UIElement*> m_lUI;
Shader* m_entityShader;
Shader* m_textShader;
Shader* m_uiTextureShader;
};
}
+6 -5
View File
@@ -13,22 +13,23 @@ namespace nf {
unsigned int advance;
};
struct Font {
std::map<char, Character> m_characters;
};
class Text : public UIElement {
public:
Text();
void create(const std::string& string, const Vec2& position, const Vec3& color = {1.0, 1.0, 1.0}, unsigned int size = 160, Asset* font = BaseAssets::defaultFont);
void centered(bool centered);
void setText(const std::string& string);
const char* identity() override;
void render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight) override;
~Text();
private:
std::string m_string;
Vec2 m_position;
Font* m_font;
Vec3 m_color;
bool m_centered;
std::map<char, Character> m_font;
};
}
+4
View File
@@ -1,4 +1,5 @@
#pragma once
#include "Utility.h"
namespace nf {
class Texture {
@@ -7,9 +8,12 @@ namespace nf {
void create(const char* textureData, size_t textureSize);
void bind();
Vec2 getDimensions();
~Texture();
private:
unsigned int m_id;
int m_x;
int m_y;
};
}
+9 -2
View File
@@ -1,6 +1,8 @@
#pragma once
#include "Drawable.h"
#include "Utility.h"
namespace nf {
class Shader;
@@ -9,10 +11,15 @@ namespace nf {
UIElement();
virtual const char* identity();
void setPosition(float x, float y);
void setPosition(const Vec2& position);
void centered(bool x, bool y = false);
virtual void render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight);
~UIElement();
private:
protected:
Vec2 m_position;
bool m_centeredX;
bool m_centeredY;
};
}
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include "UIElement.h"
#include "Utility.h"
namespace nf {
class Texture;
struct Asset;
class UITexture : public UIElement {
public:
UITexture();
void create(Asset* texture, const Vec2& position, double scale = 1.0);
const char* identity() override;
void render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight) override;
~UITexture();
private:
Texture* m_texture;
float m_scale;
};
}