Text is finally working, once again it was the depth buffer settings in framebuffer.cpp that caused the rendering of text and images to be in z order rather than all on the same plane.

master
Zed A. Shaw 1 week ago
parent 681007e383
commit e2a72e3da1
  1. 9
      lua/builder_test.lua
  2. 7
      meson.build
  3. 5
      shaders/image.vert.glsl
  4. 4
      shaders/text.frag.glsl
  5. 4
      src/engine.cpp
  6. 8
      src/framebuffer.cpp
  7. 2
      src/image.cpp
  8. 5
      src/options.cpp
  9. 2
      src/screen.cpp
  10. 2
      src/screen.hpp
  11. 15
      src/text.cpp
  12. 1
      src/text.hpp
  13. 10
      wraps/magic_enum.wrap

@ -8,7 +8,14 @@ config{
}
slide{
h1 "Here's Mine",
image{
src="assets/test.jpg"
},
h1 "Image Before Test",
}
slide{
h1 "Image After Test",
image{
src="assets/test.jpg"
},

@ -25,7 +25,12 @@ glfw3 = subproject('glfw').get_variable('glfw_dep')
glm = subproject('glm').get_variable('glm_dep')
freetype2 = subproject('freetype2').get_variable('freetype_dep')
dependencies = [fmt, fuc2, sol2, glfw3, glm, freetype2]
# have to disable tests because this dude's using catch2 from the 1890s
magic_enum_proj = subproject('magic_enum', default_options: {
'test': false})
magic_enum = magic_enum_proj.get_variable('magic_enum_dep')
dependencies = [fmt, fuc2, sol2, glfw3, glm, freetype2, magic_enum]
sources = [
'src/glad/glad.cpp',

@ -1,11 +1,12 @@
#version 330 core
layout (location = 0) in vec3 aPos;
// in the original this was vec3 but in image.cpp:88 it's a 2 element float so WTF?
layout (location = 0) in vec2 aPos;
layout (location = 1) in vec2 aTexCoord;
out vec2 TexCoord;
void main()
{
gl_Position = vec4(aPos, 1.0);
gl_Position = vec4(aPos, 0.0, 1.0);
TexCoord = aTexCoord;
}

@ -2,11 +2,11 @@
in vec2 TexCoords;
out vec4 color;
uniform sampler2D text;
uniform sampler2D glyph;
uniform vec3 textColor;
void main()
{
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(glyph, TexCoords).r);
color = vec4(textColor, 1.0) * sampled;
}

@ -7,6 +7,7 @@
#include <glm/gtc/type_ptr.hpp>
#include "image.hpp"
#include <glad/glad.h>
#include <magic_enum/magic_enum.hpp>
void framebuffer_size_callback(GLFWwindow *, int width, int height) {
glViewport(0, 0, width, height);
@ -66,7 +67,6 @@ GLFWwindow* create_window() {
}
void setup() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
glEnable(GL_MULTISAMPLE);
@ -110,7 +110,7 @@ void Engine::render() {
if(node.type == NodeType::TEXT || node.type == NodeType::H1 || node.type == NodeType::UL) {
text->render(node.content, 25.0f, WINDOW_HEIGHT - y, 1.0f, glm::vec3(1.0f, 1.0f, 1.0f));
} else if(node.type == NodeType::IMAGE && node.image != nullptr) {
} else if(node.type == NodeType::IMAGE) {
dbc::check(node.image != nullptr, "Node's image not configured.");
node.image->render();
} else {

@ -29,22 +29,18 @@ void FrameBuffer::init() {
void FrameBuffer::begin() {
glBindFramebuffer(GL_FRAMEBUFFER, target_fb);
glEnable(GL_DEPTH_TEST);
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
}
void FrameBuffer::commit() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDisable(GL_DEPTH_TEST);
glClearColor(0.0f, 0.0f, 1.0, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
void FrameBuffer::draw(Screen& screen) {
screen.shader.use();
glBindVertexArray(screen.target_VAO);
glActiveTexture(GL_TEXTURE0 + screen.texture_id);
glActiveTexture(GL_TEXTURE0 + screen.texture_unit);
glBindTexture(GL_TEXTURE_2D, texture_color_buffer);
glDrawArrays(GL_TRIANGLES, 0, 6);
}

@ -61,7 +61,7 @@ void Image::render() {
// use the correct texture unit
glActiveTexture(GL_TEXTURE0 + texture_unit);
glBindTexture(GL_TEXTURE_2D, texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
// then I don't need to set this every time I render
glBindVertexArray(image_vao);

@ -42,8 +42,9 @@ Options parse_options(int argc, char* argv[]) {
}
if(!result.deck_given) {
print_usage();
result.error = true;
result.deck_file = "builder_test.lua";
// print_usage();
// result.error = true;
}
return result;

@ -4,7 +4,7 @@
void Screen::init() {
shader.use();
shader.setInt("screenTexture", texture_id);
shader.setInt("screenTexture", texture_unit);
glGenVertexArrays(1, &target_VAO);
glGenBuffers(1, &target_VBO);

@ -5,7 +5,7 @@ struct Screen {
Shader shader{{"shaders/screen.vert.glsl", "shaders/screen.frag.glsl", ""}};
unsigned int target_VAO = 0;
unsigned int target_VBO = 0;
unsigned int texture_id = 10;
unsigned int texture_unit = 10;
float vertices[24] = {
// vertex attributes for a quad that fills the entire screen in Normalized Device Coordinates.

@ -10,11 +10,10 @@
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>(WINDOW_WIDTH), 0.0f, static_cast<float>(WINDOW_HEIGHT));
text_shader.setMat4("projection", projection);
// BUG: might be better as a getter/setter so it only needs to run once
glUniform3f(glGetUniformLocation(text_shader.ID, "textColor"), color.x, color.y, color.z);
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0 + texture_unit);
glBindVertexArray(text_vao);
for(auto c : text) {
@ -34,7 +33,7 @@ void Text::render(const std::string& text, float x, float y, float scale, glm::v
{ xpos + w, ypos + h, 1.0f, 0.0f }
};
// rander glyph texture over quad
// render glyph texture over quad
glBindTexture(GL_TEXTURE_2D, ch.texture_id);
// update content of VBO memory
@ -48,12 +47,16 @@ void Text::render(const std::string& text, float x, float y, float scale, glm::v
x += (ch.advance >> 6) * scale;
}
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindVertexArray(0);
}
Text::Text() {
// can you create this before load_font?
text_shader.use();
text_shader.setTextureUnit("glyph", texture_unit);
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(WINDOW_WIDTH), 0.0f, static_cast<float>(WINDOW_HEIGHT));
text_shader.setMat4("projection", projection);
glGenVertexArrays(1, &text_vao);
glGenBuffers(1, &text_vbo);

@ -18,6 +18,7 @@ struct Text {
unsigned int text_vao = UINT_MAX;
unsigned int text_vbo = UINT_MAX;
std::unordered_map<unsigned char, Character> characters{};
unsigned int texture_unit = 5;
void render(const std::string& text, float x, float y, float scale, glm::vec3 color);
void load_font();

@ -0,0 +1,10 @@
[wrap-file]
directory = magic_enum-0.9.7
source_url = https://github.com/Neargye/magic_enum/archive/refs/tags/v0.9.7.tar.gz
source_filename = magic_enum-v0.9.7.tar.gz
source_hash = b403d3dad4ef542fdc3024fa37d3a6cedb4ad33c72e31b6d9bab89dcaf69edf7
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/magic_enum_0.9.7-1/magic_enum-v0.9.7.tar.gz
wrapdb_version = 0.9.7-1
[provide]
magic_enum = magic_enum_dep
Loading…
Cancel
Save