From 27e35c65538fdaea026850735bbc6a2793b7e5f6 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 4 Jan 2024 17:31:06 +0100 Subject: [PATCH] Added text_2d.h and .cpp. --- sfw/render_objects/text_2d.cpp | 37 ++++++++++++++++++++++++++++++++++ sfw/render_objects/text_2d.h | 26 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 sfw/render_objects/text_2d.cpp create mode 100644 sfw/render_objects/text_2d.h diff --git a/sfw/render_objects/text_2d.cpp b/sfw/render_objects/text_2d.cpp new file mode 100644 index 0000000..e04a4f3 --- /dev/null +++ b/sfw/render_objects/text_2d.cpp @@ -0,0 +1,37 @@ +#include "render_objects/mesh_instance_2d.h" + +#include "render_objects/camera_2d.h" + +void MeshInstance2D::render() { + if (!mesh) { + return; + } + + Transform2D mat_orig = Camera2D::current_camera->get_model_view_matrix(); + + Camera2D::current_camera->set_model_view_matrix(mat_orig * transform); + + if (material) { + material->bind(); + } + + mesh->render(); + + for (int i = 0; i < children.size(); ++i) { + MeshInstance2D *c = children[i]; + + if (c) { + c->render(); + } + } + + Camera2D::current_camera->set_model_view_matrix(mat_orig); +} + +MeshInstance2D::MeshInstance2D() { + material = NULL; + mesh = NULL; +} +MeshInstance2D::~MeshInstance2D() { + children.clear(); +} diff --git a/sfw/render_objects/text_2d.h b/sfw/render_objects/text_2d.h new file mode 100644 index 0000000..49dcbfa --- /dev/null +++ b/sfw/render_objects/text_2d.h @@ -0,0 +1,26 @@ +#ifndef MESH_INSTACE_2D_H +#define MESH_INSTACE_2D_H + +#include "core/vector.h" + +#include "render_core/material.h" +#include "render_core/mesh.h" + +#include "core/transform.h" + +class MeshInstance2D { +public: + void render(); + + MeshInstance2D(); + ~MeshInstance2D(); + + Material *material; + Mesh *mesh; + + Transform2D transform; + + Vector children; +}; + +#endif // MESH_INSTACE_H