jGL
Loading...
Searching...
No Matches
glShapeRenderer.h
Go to the documentation of this file.
1#ifndef GLSHAPERENDERER_H
2#define GLSHAPERENDERER_H
3
5#include <jGL/OpenGL/gl.h>
6#include <jGL/shapeRenderer.h>
7
8namespace jGL::GL
9{
15 {
16
17 public:
18
24 glShapeRenderer(size_t sizeHint = 8)
25 : ShapeRenderer(sizeHint)
26 {
27 xytheta = std::vector<float>(sizeHint*xythetaDim+padShapes*xythetaDim,0.0f);
28 scale = std::vector<float>(sizeHint*scaleDim+padShapes*scaleDim,0.0f);
29 colours = std::vector<float>(sizeHint*coloursDim+padShapes*coloursDim,0.0f);
30 initGL();
31 shader = std::make_shared<glShader>(shapeVertexShader, rectangleFragmentShader);
32 shader->use();
33 }
34
36 {
37 freeGL();
38 }
39
44 static const char * shapeVertexShader;
45
50 static const char * rectangleFragmentShader;
51
56 static const char * ellipseFragmentShader;
57
58 private:
59
60 void draw
61 (
62 std::shared_ptr<Shader> shader,
63 std::vector<std::pair<Info, Shape>> & shapes,
64 UpdateInfo info = UpdateInfo()
65 );
66
67 GLuint vao, a_position, a_xytheta, a_scale, a_colour;
68
69 float quad[6*4] =
70 {
71 // positions / texture coords
72 0.5f, 0.5f, 1.0f, 1.0f, // top right
73 0.5f, -0.5f, 1.0f, 0.0f, // bottom right
74 -0.5f, -0.5f, 0.0f, 0.0f, // bottom left
75 -0.5f, 0.5f, 0.0f, 1.0f, // top left
76 -0.5f, -0.5f, 0.0f, 0.0f, // bottom left
77 0.5f, 0.5f, 1.0f, 1.0f // top right
78 };
79
80 std::vector<float> xytheta;
81 size_t xythetaDim = 3;
82 size_t xythetaAttribtue = 1;
83
84 std::vector<float> scale;
85 size_t scaleDim = 2;
86 size_t scaleAttribtue = 2;
87
88 std::vector<float> colours;
89 size_t coloursDim = 4;
90 size_t coloursAttribtue = 3;
91
92 size_t padShapes = 8;
93
94 void initGL();
95 void freeGL();
96
97 };
98}
99
100#endif /* GLSHAPERENDERER_H */
OpenGL implementation of ShapeRenderer.
Definition glShapeRenderer.h:15
static const char * rectangleFragmentShader
A fragment shader to draw rectangles.
Definition glShapeRenderer.h:50
static const char * shapeVertexShader
A vertex shader for any default shapes.
Definition glShapeRenderer.h:44
~glShapeRenderer()
Definition glShapeRenderer.h:35
static const char * ellipseFragmentShader
A fragment shader to draw ellipses.
Definition glShapeRenderer.h:56
glShapeRenderer(size_t sizeHint=8)
Construct a new glShapeRenderer.
Definition glShapeRenderer.h:24
Renders shapes with optional rendering priority.
Definition shapeRenderer.h:31
std::shared_ptr< Shader > shader
Definition shapeRenderer.h:151
Definition gl.h:41
Control updated data for drawing.
Definition shapeRenderer.h:40