jGL
Loading...
Searching...
No Matches
glParticles.h
Go to the documentation of this file.
1#ifndef GLPARTICLES
2#define GLPARTICLES
3
4#include <jGL/OpenGL/gl.h>
5#include <jGL/particles.h>
7#include <jGL/texture.h>
8
9namespace jGL::GL
10{
11 class glParticles : public Particles
12 {
13
14 public:
15
16 glParticles(size_t sizeHint);
17
18 glParticles(std::vector<TexturedParticle> p);
19
20 void draw(glm::mat4 proj);
21
22 void setTexture(std::shared_ptr<Texture> tex) { texture = tex; }
23
25
27 {
28 glDeleteVertexArrays(1, &vao);
29 glDeleteBuffers(1, &a_position);
30 glDeleteBuffers(1, &a_colour);
31 glDeleteBuffers(1, &a_texCoord);
32 }
33
34 private:
35
36 GLuint vao, a_position, a_colour, a_texCoord;
37
38 std::vector<float> position;
39 std::vector<float> colour;
40 std::vector<float> texCoord;
41
42 std::shared_ptr<Texture> texture = nullptr;
43
44 void initGL();
45 void flatten(Particles::UpdateInfo info);
46
47 glShader shader;
48
49 const char * vertexShader =
50 "#version " GLSL_VERSION "\n"
51 "precision lowp float; precision lowp int;\n"
52 "layout(location=0) in vec4 a_position;\n"
53 "layout(location=1) in vec4 a_colour;\n"
54 "layout(location=2) in vec4 a_texCoord;\n"
55 "uniform mat4 proj;\n"
56 "uniform float scale;\n"
57 "out float theta;\n"
58 "out vec4 o_colour;\n"
59 "void main(void){"
60 "o_colour = a_colour;\n"
61 "theta = a_position.z;\n"
62 "gl_Position = proj*vec4(a_position.xy,0.0,1.0);\n"
63 "gl_PointSize = a_position.w*scale;\n"
64 "}";
65
66 const char * fragmentShader =
67 "#version " GLSL_VERSION "\n"
68 "precision lowp float; precision lowp int;\n"
69 "uniform sampler2D sampler;\n"
70 "uniform int textureless;\n"
71 "in vec4 o_colour;\n"
72 "in float theta;\n"
73 "layout(location=0) out vec4 colour;\n"
74 "void main(void){\n"
75 "vec2 coord = 2.0 * gl_PointCoord - 1.0;"
76 "float ct = cos(theta); float st = sin(theta);\n"
77 "mat2 rot = mat2(ct, -st, st, ct);\n"
78 "vec2 pos = rot * coord;\n"
79 "colour = o_colour * texture(sampler, (pos+1.0)*0.5);\n"
80 "}";
81 };
82}
83
84#endif /* GLPARTICLES */
Definition glParticles.h:12
void setTexture(std::shared_ptr< Texture > tex)
Definition glParticles.h:22
void draw(glm::mat4 proj)
Definition glParticles.cpp:212
~glParticles()
Definition glParticles.h:26
void update(Particles::UpdateInfo info)
Definition glParticles.cpp:141
Definition particles.h:14
Definition gl.h:41
An OpenGL implementation of Shader.
Definition glShader.h:15
Definition particles.h:19