Added UIElement and Text; Custom fonts are supported
This commit is contained in:
1 parent
c0f7634b5f
commit
65fd8e89bb
30 files changed
+346
-35
No files matched your search
@@ -52,7 +52,7 @@ namespace nf {
|
||||
LPCWSTR m_wclassName;
|
||||
HWND m_window;
|
||||
LONG m_defaultWindowStyle;
|
||||
int m_altWidth, m_altHeight;
|
||||
unsigned int m_altWidth, m_altHeight;
|
||||
|
||||
std::chrono::duration<double> m_fpsDuration;
|
||||
double m_deltaTime;
|
||||
@@ -75,7 +75,7 @@ namespace nf {
|
||||
|
||||
//Array of booleans that represent keyboard and mouse input minus the scrollwheel
|
||||
bool m_input[164];
|
||||
int m_mouseX, m_mouseY;
|
||||
unsigned int m_mouseX, m_mouseY;
|
||||
bool m_trackingMouse;
|
||||
bool m_mouseTrackFirst;
|
||||
int m_mouseDiffX, m_mouseDiffY;
|
||||
|
||||
@@ -27,6 +27,12 @@ namespace nf {
|
||||
~AShader() override;
|
||||
};
|
||||
|
||||
struct AFont : Asset {
|
||||
size_t size;
|
||||
|
||||
~AFont() override;
|
||||
};
|
||||
|
||||
class AssetPack {
|
||||
public:
|
||||
AssetPack();
|
||||
@@ -48,6 +54,8 @@ namespace nf {
|
||||
static AModel* cylinder;
|
||||
static AModel* torus;
|
||||
|
||||
static ATexture* logo;
|
||||
static AFont* defaultFont;
|
||||
|
||||
//static ATexture* logo;
|
||||
};
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace nf {
|
||||
struct Config {
|
||||
public:
|
||||
int width;
|
||||
int height;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
bool fullscreen;
|
||||
const char* title;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "Shader.h"
|
||||
#include "VertexArray.h"
|
||||
#include "IndexBuffer.h"
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "Utility.h"
|
||||
|
||||
namespace nf {
|
||||
class Shader;
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
Entity();
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "Utility.h"
|
||||
#include "IntroGamestate.h"
|
||||
#include "Assets.h"
|
||||
#include "Text.h"
|
||||
#include "Input.h"
|
||||
|
||||
namespace nf {
|
||||
class Drawable;
|
||||
@@ -48,7 +50,7 @@ namespace nf {
|
||||
Renderer(Application* app);
|
||||
|
||||
void render(Entity& in);
|
||||
//TODO: Create second render function for UIElements
|
||||
void render(UIElement& in);
|
||||
|
||||
void doFrame(Camera* camera);
|
||||
|
||||
@@ -59,9 +61,12 @@ namespace nf {
|
||||
HDC m_hdc;
|
||||
HGLRC m_hglrc;
|
||||
|
||||
AssetPack baseAP;
|
||||
|
||||
std::vector<Entity*> m_lGame;
|
||||
std::vector<Drawable*> m_lUI;
|
||||
Shader* m_defaultShader;
|
||||
std::vector<UIElement*> m_lUI;
|
||||
Shader* m_entityShader;
|
||||
Shader* m_textShader;
|
||||
};
|
||||
|
||||
class Application {
|
||||
@@ -107,7 +112,7 @@ namespace nf {
|
||||
LPCWSTR m_wclassName;
|
||||
HWND m_window;
|
||||
LONG m_defaultWindowStyle;
|
||||
int m_altWidth, m_altHeight;
|
||||
unsigned int m_altWidth, m_altHeight;
|
||||
|
||||
std::chrono::duration<double> m_fpsDuration;
|
||||
double m_deltaTime;
|
||||
@@ -130,7 +135,7 @@ namespace nf {
|
||||
|
||||
//Array of booleans that represent keyboard and mouse input minus the scrollwheel
|
||||
bool m_input[164];
|
||||
int m_mouseX, m_mouseY;
|
||||
unsigned int m_mouseX, m_mouseY;
|
||||
bool m_trackingMouse;
|
||||
bool m_mouseTrackFirst;
|
||||
int m_mouseDiffX, m_mouseDiffY;
|
||||
@@ -138,5 +143,4 @@ namespace nf {
|
||||
//Renderer object to use OpenGL to render the current state
|
||||
Renderer* m_renderer;
|
||||
};
|
||||
}
|
||||
#include "Input.h"
|
||||
}
|
||||
@@ -7,12 +7,14 @@
|
||||
|
||||
namespace nf {
|
||||
class Application;
|
||||
class UIElement;
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
Renderer(Application* app);
|
||||
|
||||
void render(Entity& in);
|
||||
void render(UIElement& in);
|
||||
//TODO: Create second render function for UIElements
|
||||
|
||||
void doFrame(Camera* camera);
|
||||
@@ -27,7 +29,8 @@ namespace nf {
|
||||
AssetPack baseAP;
|
||||
|
||||
std::vector<Entity*> m_lGame;
|
||||
std::vector<Drawable*> m_lUI;
|
||||
Shader* m_defaultShader;
|
||||
std::vector<UIElement*> m_lUI;
|
||||
Shader* m_entityShader;
|
||||
Shader* m_textShader;
|
||||
};
|
||||
}
|
||||
@@ -10,6 +10,7 @@ namespace nf {
|
||||
|
||||
void bind();
|
||||
void setUniform(const char* name, glm::mat4& data);
|
||||
void setUniform(const char* name, glm::vec3& data);
|
||||
|
||||
~Shader();
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
|
||||
#include "UIElement.h"
|
||||
#include "Assets.h"
|
||||
#include "Utility.h"
|
||||
|
||||
namespace nf {
|
||||
struct Character {
|
||||
unsigned int texID;
|
||||
Vec2 size;
|
||||
Vec2 bearing;
|
||||
unsigned int advance;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
const char* identity() override;
|
||||
void render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight) override;
|
||||
|
||||
~Text();
|
||||
private:
|
||||
std::string m_string;
|
||||
Vec2 m_position;
|
||||
Vec3 m_color;
|
||||
bool m_centered;
|
||||
std::map<char, Character> m_font;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "Drawable.h"
|
||||
|
||||
namespace nf {
|
||||
class Shader;
|
||||
|
||||
class UIElement : public Drawable {
|
||||
public:
|
||||
UIElement();
|
||||
|
||||
virtual const char* identity();
|
||||
virtual void render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight);
|
||||
|
||||
~UIElement();
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
@@ -38,7 +38,25 @@ __debugbreak();}
|
||||
#define Error(x) {MessageBox(FindWindow(L"NFClass", NULL), toWide(x), L"NF Engine Error", MB_OK | MB_ICONERROR);\
|
||||
std::exit(-1);}
|
||||
#endif
|
||||
|
||||
struct Vec2 {
|
||||
Vec2() : x(0.0), y(0.0) {}
|
||||
Vec2(double x1) : x(x1), y(x1) {}
|
||||
Vec2(double x1, double y1) : x(x1), y(y1) {}
|
||||
Vec2 operator*(const double scalar) {
|
||||
return Vec2(x * scalar, y * scalar);
|
||||
}
|
||||
Vec2& operator+=(const Vec2& rhs) {
|
||||
this->x += rhs.x;
|
||||
this->y += rhs.y;
|
||||
return *this;
|
||||
}
|
||||
Vec2& operator-=(const Vec2& rhs) {
|
||||
this->x -= rhs.x;
|
||||
this->y -= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
double x, y;
|
||||
};
|
||||
struct Vec3 {
|
||||
Vec3() : x(0.0), y(0.0), z(0.0) {}
|
||||
Vec3(double x1) : x(x1), y(x1), z(x1) {}
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace nf {
|
||||
void push(unsigned int count);
|
||||
void finishBufferLayout();
|
||||
void bind();
|
||||
void setBufferData(unsigned int buffer, const void* data, const size_t dataSize);
|
||||
|
||||
~VertexArray();
|
||||
private:
|
||||
|
||||
Reference in new issue
Block a user