Started a simple font text class to do font rendering.
This commit is contained in:
parent
1830faf4c9
commit
b244c903a6
137 changed files with 16135 additions and 0 deletions
72
32-text-rendering/src/mesh.hpp
Normal file
72
32-text-rendering/src/mesh.hpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include "shader.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct Vertex {
|
||||
glm::vec3 position;
|
||||
glm::vec3 normal;
|
||||
glm::vec2 tex_coords;
|
||||
};
|
||||
|
||||
struct TextureCounts {
|
||||
unsigned int diffuseNr = 1;
|
||||
unsigned int specularNr = 1;
|
||||
unsigned int normalNr = 1;
|
||||
unsigned int heightNr = 1;
|
||||
};
|
||||
|
||||
struct Texture {
|
||||
unsigned int id;
|
||||
std::string type;
|
||||
std::string path;
|
||||
std::string target;
|
||||
int uniform_id=-1;
|
||||
|
||||
Texture(unsigned int id, const std::string& type, const std::string& path, TextureCounts& count) :
|
||||
id(id), type(type)
|
||||
{
|
||||
unsigned int number = 0;
|
||||
|
||||
if(type == "texture_diffuse") {
|
||||
number = count.diffuseNr++;
|
||||
} else if(type == "texture_specular") {
|
||||
number = count.specularNr++;
|
||||
} else if(type == "texture_normal") {
|
||||
number = count.normalNr++;
|
||||
} else if(type == "texture_height") {
|
||||
number = count.heightNr++;
|
||||
} else {
|
||||
dbc::sentinel($F("Invalid texture type={} for file={}", type, path));
|
||||
}
|
||||
|
||||
target = std::format("{}{}", type, number);
|
||||
}
|
||||
};
|
||||
|
||||
struct Mesh {
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
std::vector<Texture> textures;
|
||||
unsigned int VAO = 0;
|
||||
unsigned int VBO = 0;
|
||||
unsigned int EBO = 0;
|
||||
|
||||
Mesh(std::vector<Vertex>& vertices, std::vector<unsigned int>& indices, std::vector<Texture>& textures) :
|
||||
vertices(vertices),
|
||||
indices(indices),
|
||||
textures(textures)
|
||||
{
|
||||
setup_mesh();
|
||||
}
|
||||
|
||||
void draw(Shader &shader, bool with_textures);
|
||||
void setup_mesh();
|
||||
void apply_textures(const Shader& shader);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue