JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
FrameBuffer.hpp
Go to the documentation of this file.
1// Copyright 2012-2023 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "Color.hpp"
8#include "Finally.hpp"
9#include "Mat3.hpp"
10#include "Pixels.hpp"
11#include "Vec2.hpp"
12#include "Vertex.hpp"
13
14#include <memory>
15#include <vector>
16
17namespace jngl {
18
19class ShaderProgram;
20
36public:
38 FrameBuffer(Pixels width, Pixels height);
39
42
45
46 FrameBuffer(const FrameBuffer&) = delete;
47 FrameBuffer& operator=(const FrameBuffer&) = delete;
48 FrameBuffer(FrameBuffer&&) = default;
49 FrameBuffer& operator=(FrameBuffer&&) = default;
51
53 struct Context {
54 explicit Context(std::function<void()> resetCallback);
55 Context(const Context&) = delete;
56 Context& operator=(const Context&) = delete;
57 Context(Context&&) noexcept;
58 Context& operator=(Context&&) noexcept;
59 ~Context();
60
62 void clear();
63
65 void clear(Rgb color);
66
67 private:
68 std::function<void()> resetCallback;
69 };
70
74#if __cplusplus >= 201703L
75 [[nodiscard]]
76#endif
77 Context use() const;
78
80 void draw(Vec2 position, const ShaderProgram* = nullptr) const;
81 void draw(double x, double y) const;
82
83 void draw(Mat3 modelview, const ShaderProgram* = nullptr) const;
84
86 void drawMesh(const std::vector<Vertex>& vertexes, const ShaderProgram* = nullptr) const;
87
90 [[deprecated("use jngl::FrameBuffer::Context::clear(Color) instead")]]
91 static void clear();
92
94 Vec2 getSize() const;
95
101 uint32_t getTextureID() const;
102
103private:
104 struct Impl;
106};
107
108} // namespace jngl
Contains jngl::Color class.
Contains jngl::Finally class.
Contains jngl::Mat3 class.
Contains jngl::Pixels class.
Contains jngl::Vec2 class.
Image framebuffer object which can be rendered on.
void draw(Vec2 position, const ShaderProgram *=nullptr) const
Draws the framebuffer image to the screen.
static void clear()
Clear the framebuffer with the color set by jngl::setBackgroundColor.
FrameBuffer(Pixels width, Pixels height)
Creates a framebuffer object with width times height actual pixels.
void drawMesh(const std::vector< Vertex > &vertexes, const ShaderProgram *=nullptr) const
Draws a list of triangles with the framebuffer's texture on it.
Context use() const
Starts drawing on the FrameBuffer as long as Context is alive.
FrameBuffer(ScaleablePixels width, ScaleablePixels height)
Creates a framebuffer object with width times height scalable pixels.
uint32_t getTextureID() const
Returns the OpenGL texture ID of the associated image buffer.
Vec2 getSize() const
Returns the size in screen pixels.
FrameBuffer(std::array< Pixels, 2 > size)
Creates a framebuffer object with size[0] times size[1] pixels.
3x3 matrix
Definition Mat3.hpp:18
Scale-dependent pixels, corresponds to actual pixels on the screen.
Definition Pixels.hpp:14
Object representing a RGB color, new version of jngl::Color (which will be deprecated in the future)
Definition Rgb.hpp:15
Scale-independent pixels, also called "screen pixels".
Linked vertex and fragment shaders.
Two-dimensional vector.
Definition Vec2.hpp:36
JNGL's main namespace.
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.
Lifetime object when the FrameBuffer is in use.
void clear(Rgb color)
Clear the framebuffer with color.
void clear()
Clear the framebuffer with a transparent background.