Some refactoring and better usage of text
This commit is contained in:
parent
10138d5fd8
commit
2aed98d688
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Gedeng {
|
namespace Gedeng {
|
||||||
|
|
||||||
TextLabel::TextLabel() : shader(Shader("Shader/text.vs", "Shader/text.fs")) {
|
TextLabel::TextLabel(const String &text) : text(text), shader(Shader("Shader/text.vs", "Shader/text.fs")) {
|
||||||
FT_Library ft;
|
FT_Library ft;
|
||||||
if (FT_Init_FreeType(&ft)) {
|
if (FT_Init_FreeType(&ft)) {
|
||||||
GG_CORE_ERROR("Couldn't create font library!");
|
GG_CORE_ERROR("Couldn't create font library!");
|
||||||
@ -25,7 +25,7 @@ TextLabel::TextLabel() : shader(Shader("Shader/text.vs", "Shader/text.fs")) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set size
|
// Set size
|
||||||
FT_Set_Pixel_Sizes(face, 0, 48);
|
FT_Set_Pixel_Sizes(face, 0, 12);
|
||||||
|
|
||||||
// Load first 128 ASCII Characters
|
// Load first 128 ASCII Characters
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // disable byte-alignment restriction
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // disable byte-alignment restriction
|
||||||
@ -75,14 +75,18 @@ TextLabel::TextLabel() : shader(Shader("Shader/text.vs", "Shader/text.fs")) {
|
|||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextLabel::render_text(String text, float x, float y, float scale, Vector3 color) {
|
void TextLabel::set_text(const String &text) {
|
||||||
|
this->text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextLabel::render_text(float x, float y, float scale, Vector3 color) {
|
||||||
// activate corresponding render state
|
// activate corresponding render state
|
||||||
shader.use();
|
shader.use();
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(shader.ID, "textColor"), color.x, color.y, color.z);
|
glUniform3f(glGetUniformLocation(shader.ID, "textColor"), color.x, color.y, color.z);
|
||||||
|
|
||||||
// FIXME: We need the screen size here... (or UI module size?)
|
// FIXME: We need the screen size here... (or UI module size?)
|
||||||
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(500), 0.0f, static_cast<float>(500));
|
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(900), 0.0f, static_cast<float>(600));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.ID, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
glUniformMatrix4fv(glGetUniformLocation(shader.ID, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
@ -13,9 +13,11 @@ namespace Gedeng {
|
|||||||
|
|
||||||
class TextLabel {
|
class TextLabel {
|
||||||
public:
|
public:
|
||||||
TextLabel();
|
TextLabel(const String &text = String(""));
|
||||||
|
|
||||||
void render_text(String text, float x, float y, float scale, Vector3 color);
|
void set_text(const String &text);
|
||||||
|
|
||||||
|
void render_text(float x, float y, float scale, Vector3 color);
|
||||||
|
|
||||||
bool is_valid();
|
bool is_valid();
|
||||||
|
|
||||||
@ -29,6 +31,8 @@ class TextLabel {
|
|||||||
|
|
||||||
std::map<char, Character> characters;
|
std::map<char, Character> characters;
|
||||||
unsigned int vao, vbo;
|
unsigned int vao, vbo;
|
||||||
|
|
||||||
|
String text;
|
||||||
bool valid;
|
bool valid;
|
||||||
|
|
||||||
Shader shader;
|
Shader shader;
|
||||||
|
@ -42,6 +42,18 @@ class ParallaxApp : public Gedeng::Application {
|
|||||||
if (Gedeng::Input::is_key_down(GLFW_KEY_X)) {
|
if (Gedeng::Input::is_key_down(GLFW_KEY_X)) {
|
||||||
bump_depth -= delta * 0.1;
|
bump_depth -= delta * 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gedeng::String text;
|
||||||
|
text += std::to_string(number_of_steps).c_str();
|
||||||
|
text += " steps, ";
|
||||||
|
|
||||||
|
text += std::to_string(number_of_refinement_steps).c_str();
|
||||||
|
text += " refinement steps, ";
|
||||||
|
|
||||||
|
text += std::to_string(bump_depth).c_str();
|
||||||
|
text += " bump depth";
|
||||||
|
|
||||||
|
debug_text.set_text(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dynamic_update(double delta) override {
|
void dynamic_update(double delta) override {
|
||||||
@ -71,8 +83,7 @@ class ParallaxApp : public Gedeng::Application {
|
|||||||
quad_mesh.rotate(delta * 25.0f, glm::normalize(glm::vec3(0.0, 0.0, 1.0)));
|
quad_mesh.rotate(delta * 25.0f, glm::normalize(glm::vec3(0.0, 0.0, 1.0)));
|
||||||
quad_mesh.render(render_shader);
|
quad_mesh.render(render_shader);
|
||||||
|
|
||||||
debug_text.render_text(Gedeng::String("This is sample text"), 25.0f, 25.0f, 1.0f,
|
debug_text.render_text(25.0f, 25.0f, 1.0f, Gedeng::Vector3(1.0, 1.0, 0.0));
|
||||||
Gedeng::Vector3(1.0, 1.0, 0.0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user