28 Cell(glm::vec3 a, glm::vec3 b, glm::vec3 c)
32 shader = std::make_unique<jGL::GL::glShader>(vertexShader, fragmentShader);
34 shader->setUniform<glm::vec4>(
"colour", {0.0,1.0,0.0,0.5});
35 glGenVertexArrays(1, &vao);
36 glGenBuffers(1, &a_vertices);
37 glGenBuffers(1, &a_coords);
39 glBindVertexArray(vao);
68 glDeleteBuffers(1, &a_vertices);
69 glDeleteBuffers(1, &a_coords);
70 glDeleteVertexArrays(1, &vao);
81 shader->setUniform<glm::mat4>(
"proj", pv);
93 this->a = a; this->b = b; this->c = c;
95 glBindVertexArray(vao);
104 glBindVertexArray(0);
114 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
115 glEnable(GL_DEPTH_TEST);
116 glEnable(GL_CULL_FACE);
120 glBindVertexArray(vao);
121 glDrawArrays(GL_TRIANGLES, 0, 12*3);
122 glBindVertexArray(0);
129 std::unique_ptr<jGL::GL::glShader> shader;
131 std::array<float, 12*3*3> cube;
133 const std::array<float, 12*3*2> textureCoords =
135 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
136 0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
138 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
139 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
141 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
142 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
144 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
145 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
147 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
148 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
150 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
151 1.0, 0.0, 0.0, 0.0, 0.0, 1.0
154 GLuint vao, a_vertices, a_coords;
156 const char * vertexShader =
157 "#version " GLSL_VERSION
"\n"
158 "precision lowp float; precision lowp int;\n"
159 "layout(location=0) in vec3 a_vertices;\n"
160 "layout(location=1) in vec2 a_coords;\n"
161 "uniform mat4 proj;\n"
165 " gl_Position = proj*vec4(a_vertices.xyz, 1.0);\n"
166 " coords = a_coords;\n"
169 const char * fragmentShader =
170 "#version " GLSL_VERSION
"\n"
171 "precision lowp float; precision lowp int;\n"
172 "uniform vec4 colour;\n"
174 "out vec4 o_colour;\n"
177 " float d = 1.0-2.0*min(min(coords.x, 1.0-coords.x), min(coords.y, 1.0-coords.y));\n"
178 " if (d < 0.98) { d = smoothstep(0.97, 0.98, d); }\n"
179 " else { d = 1.0; }\n"
180 " o_colour = vec4(1.0, 0.0, 0.0, d);\n"
186 glm::vec3 f0 = {0.0, 0.0, 0.0};
187 glm::vec3 f1 = f0 + a;
188 glm::vec3 f2 = f0 + b;
189 glm::vec3 f3 = f0 + a + b;
191 glm::vec3 b0 = f0 + c;
192 glm::vec3 b1 = b0 + a;
193 glm::vec3 b2 = b0 + b;
194 glm::vec3 b3 = b0 + a + b;
196 std::array<glm::vec3, 12*3> vertices =
217 glm::vec3 com = {0.0, 0.0, 0.0};
218 for (
const auto & v : vertices) { com += v; }
219 com /= float(vertices.size());
221 for (uint8_t i = 0; i < vertices.size(); i++)
224 for (uint8_t j = 0; j < 3; j++)
226 cube[i*3+j] = vertices[i][j];
void createBuffer(GLuint &buffer, const float *data, GLuint dataSize, int drawType, GLuint attribute, GLuint size, GLuint divisor)
Create a GL_ARRAY_BUFFER from data.
Definition glUtils.h:71