Render Target for J2D
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 2m10s

This commit is contained in:
2024-09-13 13:24:20 -04:00
parent 9e3e0c949f
commit 881d031f3c
8 changed files with 158 additions and 69 deletions

View File

@@ -18,6 +18,7 @@
#include <JGL/types/Enums.h>
#include <JGL/types/FontCache.h>
#include <JGL/types/Font.h>
#include <JGL/types/RenderTarget.h>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/LinearAlgebra/Vector2.hpp>
#include <J3ML/LinearAlgebra/Vector3.hpp>
@@ -41,7 +42,7 @@ namespace JGL {
/// @note This call may not strictly be necessary on some setups, but is provided to keep the API constant.
/// It is recommended to always open a JGL 2D context to render your content, then close when completed.
/// This keeps our code from, say, clobbering the OpenGL rendering context driving 3D content in between our calls.
void Begin();
void Begin(RenderTarget* render_target = nullptr, bool clear_buffers = false);
/// Closes a 2-D rendering context with the underlying graphics system (In this case& by default OpenGL).
/// @see Begin().
void End();
@@ -76,6 +77,8 @@ namespace JGL {
/// Draws a filled rectangle with rounded corners on the screen.
void FillRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius = 5, unsigned int subdivisions = 8);
void DrawRenderTargetAsSprite(const RenderTarget& render_target, const Vector2& position, float rad_rotation = 0, const Vector2& origin = Vector2(0 , 0),
const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White, Direction inversion = Direction::None);
/// Draws a sprite to the screen by passing a G̶L̶u̶i̶n̶t̶ JGL Texture that represents a handle to a loaded texture.
/// @param texture
/// @param position

View File

@@ -10,16 +10,26 @@ namespace JGL {
class JGL::RenderTarget {
private:
Color4 background_color = {0,0,0,0};
Color4 clear_color{0,0,0,0};
bool using_depth = false;
GLuint framebuffer_object = 0;
GLuint depth_buffer = 0;
Texture texture;
Texture* texture = nullptr;
public:
static GLuint GetActiveGLRenderTargetHandle();
static GLuint GetActiveGLFramebufferHandle();
static void SetActiveGLRenderTarget(const RenderTarget& render_target);
public:
[[nodiscard]] Texture GetGLTexture();
[[nodiscard]] GLuint GetGLTextureHandle();
[[nodiscard]] GLuint GetGLFramebufferObjectHandle();
[[nodiscard]] GLuint GetGLDepthBufferHandle();
[[nodiscard]] Vector2 GetDimensions() const;
[[nodiscard]] Texture* GetJGLTexture() const;
[[nodiscard]] GLuint GetGLTextureHandle() const;
[[nodiscard]] GLuint GetGLFramebufferObjectHandle() const;
[[nodiscard]] GLuint GetGLDepthBufferHandle() const;
[[nodiscard]] Color4 GetClearColor() const;
public:
/// Create a render target for a texture that already exists. For decals.
explicit RenderTarget(const Texture& texture, const Color4& clear_color = Colors::Black, bool use_depth = false);
/// Create a Render Target with a brand new texture. Want to render JGL elements onto a texture and display it as a sprite?
explicit RenderTarget(unsigned int size, const Color4& clear_color = Colors::Black, bool use_depth = false);
void Erase();
};

View File

@@ -40,8 +40,6 @@ namespace JGL {
/* Initialize a texture filled with trash data
this is primarily for the RenderTarget */
explicit Texture(const Vector2& size);
/* Initialize a texture that is a single color */
Texture(const Color4& color, const Vector2& size);
Texture() = default;
public:
[[nodiscard]] GLuint GetGLTextureHandle() const;