Now rendering fonts separately from the scene render.
This commit is contained in:
parent
b244c903a6
commit
3231f747a9
5 changed files with 21 additions and 10 deletions
|
|
@ -119,8 +119,18 @@ void update(GLFWwindow* window, Scene& scene) {
|
|||
scene.update();
|
||||
}
|
||||
|
||||
void render(GLFWwindow* window, Scene& scene) {
|
||||
void render(GLFWwindow* window, Scene& scene, Text& text) {
|
||||
scene.render(window);
|
||||
float scale = 0.5f;
|
||||
|
||||
float X_height = text.characters['X'].size.y * scale + 0.5f;
|
||||
float y = 0.0f;
|
||||
|
||||
for(int i = 0; i < 100; i++) {
|
||||
y += X_height;
|
||||
text.render(std::format("y={}", y), 25.0f, y, scale, glm::vec3(1.0, 0.0f, 0.0f));
|
||||
}
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
|
|
@ -134,12 +144,13 @@ int main() {
|
|||
|
||||
auto window = create_window();
|
||||
auto scene = setup();
|
||||
Text text;
|
||||
|
||||
glfwSetWindowUserPointer(window, &scene);
|
||||
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
update(window, scene);
|
||||
render(window, scene);
|
||||
render(window, scene, text);
|
||||
}
|
||||
|
||||
quit(window, scene);
|
||||
|
|
|
|||
|
|
@ -57,9 +57,7 @@ void Scene::render(GLFWwindow* window) {
|
|||
draw_thing(with_shader, thing);
|
||||
}
|
||||
|
||||
text.render_text("This is A Test", 25.0f, 25.0f, 1.0f, glm::vec3(0.5, 0.8f, 0.2f));
|
||||
|
||||
// render_skybox(projection);
|
||||
render_skybox(projection);
|
||||
|
||||
framebuffer.commit();
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ struct Scene {
|
|||
unsigned int skyboxVBO = UINT_MAX;
|
||||
unsigned int skybox_texture_id = UINT_MAX;
|
||||
bool reflect_on = false;
|
||||
Text text;
|
||||
|
||||
Scene(components::Scene& config):
|
||||
shader{config.shader},
|
||||
|
|
@ -91,7 +90,6 @@ struct Scene {
|
|||
|
||||
framebuffer.init();
|
||||
screen.init();
|
||||
text.load_font();
|
||||
init_skybox();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
void Text::render_text(const std::string& text, float x, float y, float scale, glm::vec3 color) {
|
||||
void Text::render(const std::string& text, float x, float y, float scale, glm::vec3 color) {
|
||||
text_shader.use();
|
||||
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(SCR_WIDTH), 0.0f, static_cast<float>(SCR_HEIGHT));
|
||||
text_shader.setMat4("projection", projection);
|
||||
|
|
|
|||
|
|
@ -12,12 +12,16 @@ struct Character {
|
|||
};
|
||||
|
||||
struct Text {
|
||||
std::string font{"assets/fonts/text.ttf"};
|
||||
Shader text_shader{{"shaders/32-text.vert.glsl", "shaders/32-text.frag.glsl", ""}};
|
||||
unsigned int text_vao = UINT_MAX;
|
||||
unsigned int text_vbo = UINT_MAX;
|
||||
std::string font{"assets/fonts/text.ttf"};
|
||||
std::unordered_map<unsigned char, Character> characters;
|
||||
|
||||
void render_text(const std::string& text, float x, float y, float scale, glm::vec3 color);
|
||||
Text() {
|
||||
load_font();
|
||||
}
|
||||
|
||||
void render(const std::string& text, float x, float y, float scale, glm::vec3 color);
|
||||
void load_font();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue