 |
BARE2D
|
|
Go to the documentation of this file.
8 std::string& vertShader,
9 unsigned int perspectiveWidth,
10 unsigned int perspectiveHeight) :
12 m_fragShader(fragShader), m_vertShader(vertShader) {
13 m_camera = std::make_shared<Camera2D>();
14 m_camera->init(perspectiveWidth, perspectiveHeight);
23 link({
"vertexPosition",
"vertexColour",
"vertexUV"});
32 (
void*)offsetof(
Vertex, colour));
41 unsigned char* data =
new unsigned char[4];
47 glTexImage2D(GL_TEXTURE_2D,
61 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
63 float backColour[] = {0.0f, 0.0f, 0.0f, 0.0f};
64 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, backColour);
66 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
67 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
84 glm::mat4 projectionMatrix =
m_camera->getCameraMatrix();
94 if(!
m_camera->isRectInViewspace(destRect))
99 glm::vec4 uv(0.0f, 0.0f, 1.0f, 1.0f);
108 std::vector<Vertex> vertices;
111 vertices.resize(
m_glyphs.size() * 6);
123 vertices[vertex++] =
m_glyphs[0]->topLeft;
124 vertices[vertex++] =
m_glyphs[0]->bottomLeft;
125 vertices[vertex++] =
m_glyphs[0]->bottomRight;
126 vertices[vertex++] =
m_glyphs[0]->bottomRight;
127 vertices[vertex++] =
m_glyphs[0]->topRight;
128 vertices[vertex++] =
m_glyphs[0]->topLeft;
134 for(
unsigned int glyph = 1; glyph <
m_glyphs.size(); glyph++) {
139 vertices[vertex++] =
m_glyphs[glyph]->topLeft;
140 vertices[vertex++] =
m_glyphs[glyph]->bottomLeft;
141 vertices[vertex++] =
m_glyphs[glyph]->bottomRight;
142 vertices[vertex++] =
m_glyphs[glyph]->bottomRight;
143 vertices[vertex++] =
m_glyphs[glyph]->topRight;
144 vertices[vertex++] =
m_glyphs[glyph]->topLeft;
159 glBufferData(GL_ARRAY_BUFFER, vertices.size() *
sizeof(
Vertex),
nullptr, GL_DYNAMIC_DRAW);
162 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),...
virtual void init() override
Initializes all necessary bits of the renderer.
void bindTexture(GLenum target, GLenum texture)
Binds a texture to target in the currently active texture slot.
A renderer made to simply run a shader with some passed glyphs. VAOs vertexPosition (vec3),...
std::vector< Glyph * > m_glyphs
virtual ~TexturelessRenderer()
std::shared_ptr< Camera2D > getCamera()
virtual void link(std::initializer_list< std::string > attributes)
virtual void createRenderBatches() override
Constructs all of the render batches from data given by, say, draw() calls.
virtual void setCamera(std::shared_ptr< Camera2D > camera)
Sets the camera to a given pointer. This means that the renderer takes ownership.
void compileShaders(const char *vertexShaderPath, const char *fragmentShaderPath)
Compiles the shaders. Does not link them.
virtual void draw(glm::vec4 destRect, float depth, Colour colour=Colour(255, 255, 255, 255), float angle=0.0f, glm::vec2 COR=glm::vec2(0.5f))
void unbindVBO()
Unbinds this VAO's VBO.
std::shared_ptr< Camera2D > m_camera
The glyph represents a renderbatch's primitive data, which is created from each draw call in the basi...
virtual void preRender() override
Does stuff inside of the render function, within the shader's use.
void bindVBO()
Binds the VAO's VBO.
TexturelessRenderer(std::string &fragShader, std::string &vertShader, unsigned int perspectiveWidth=2, unsigned int perspectiveHeight=2)
static GLContext * getContext()
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()
Initializes all necessary bits of the renderer.