 |
BARE2D
|
|
Go to the documentation of this file.
6 std::string& vertShader,
7 unsigned int perspectiveWidth,
8 unsigned int perspectiveHeight)
10 , m_fragShader(fragShader)
11 , m_vertShader(vertShader)
13 m_camera = std::make_shared<Camera2D>();
14 m_camera->init(perspectiveWidth, perspectiveHeight);
24 link({
"vertexPosition",
"vertexColour",
"vertexUV"});
30 (
void*)offsetof(
Vertex, colour));
50 GLint textureUniform = 0;
52 glm::mat4 projectionMatrix =
m_camera->getCameraMatrix();
65 if(!
m_camera->isRectInViewspace(destRect))
71 m_glyphs.push_back(
new Glyph(destRect, uvRect, texture, depth, colour, angle, COR));
78 std::vector<Vertex> vertices;
81 vertices.resize(
m_glyphs.size() * 6);
94 vertices[vertex++] =
m_glyphs[0]->topLeft;
95 vertices[vertex++] =
m_glyphs[0]->bottomLeft;
96 vertices[vertex++] =
m_glyphs[0]->bottomRight;
97 vertices[vertex++] =
m_glyphs[0]->bottomRight;
98 vertices[vertex++] =
m_glyphs[0]->topRight;
99 vertices[vertex++] =
m_glyphs[0]->topLeft;
105 for(
unsigned int glyph = 1; glyph <
m_glyphs.size(); glyph++)
119 vertices[vertex++] =
m_glyphs[glyph]->topLeft;
120 vertices[vertex++] =
m_glyphs[glyph]->bottomLeft;
121 vertices[vertex++] =
m_glyphs[glyph]->bottomRight;
122 vertices[vertex++] =
m_glyphs[glyph]->bottomRight;
123 vertices[vertex++] =
m_glyphs[glyph]->topRight;
124 vertices[vertex++] =
m_glyphs[glyph]->topLeft;
139 glBufferData(GL_ARRAY_BUFFER, vertices.size() *
sizeof(
Vertex),
nullptr, GL_DYNAMIC_DRAW);
142 glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size() *
sizeof(
Vertex), vertices.data());
void setUniformMatrix(const std::string uniform, bool transpose, T *data, unsigned int num=1)
Similar to setUniform.
Just holds vertex data for convenience.
The renderer class holds some shader program, manages some VBO, some render batch(es),...
A simple renderer. Has the GLSL VAOs vertexPosition (vec3), vertexColour (vec4), and vertexUV (vec2)....
std::vector< Glyph * > m_glyphs
virtual void link(std::initializer_list< std::string > attributes)
std::shared_ptr< Camera2D > m_camera
void compileShaders(const char *vertexShaderPath, const char *fragmentShaderPath)
Compiles the shaders. Does not link them.
virtual void setCamera(std::shared_ptr< Camera2D > camera)
Sets the camera to a given pointer. This means that the renderer takes ownership.
BasicRenderer(std::string &fragShader, std::string &vertShader, unsigned int perspectiveWidth=2, unsigned int perspectiveHeight=2)
void unbindVBO()
Unbinds this VAO's VBO.
virtual void createRenderBatches() override
Constructs all of the render batches from data given by, say, draw() calls.
The glyph represents a renderbatch's primitive data, which is created from each draw call in the basi...
void setUniform(const std::string uniform, T *data, unsigned int num=1)
A generalized wrapper to find and set a uniform for this shader.
virtual void preRender() override
Does stuff inside of the render function, within the shader's use.
std::shared_ptr< Camera2D > getCamera()
void bindVBO()
Binds the VAO's VBO.
std::vector< RenderBatch > m_batches
void addVertexAttribute(GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *data)
Wrapper for glVertexAttribPointer - Adds an attribute to the VBO - each vertex data slot will gain so...
An RGBA 8-bit colour value.
virtual void init() override
Initializes all necessary bits of the renderer.
virtual void draw(glm::vec4 destRect, glm::vec4 uvRect, GLuint texture, float depth, Colour colour=Colour(255, 255, 255, 255), float angle=0.0f, glm::vec2 COR=glm::vec2(0.5f))
virtual void init()
Initializes all necessary bits of the renderer.