155 int bx = (size.x > 0) ? borderSize : -borderSize;
156 int by = (size.y > 0) ? borderSize : -borderSize;
157 std::array<ivec2, 8> positions = {
158 pos +
ivec2( + bx, + by),
159 pos +
ivec2( + bx, size.y - by),
160 pos +
ivec2(size.x - bx, size.y - by),
161 pos +
ivec2(size.x - bx, + by),
163 pos +
ivec2(0 , size.y ),
164 pos +
ivec2(size.x , size.y ),
165 pos +
ivec2(size.x , 0 ),
169 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
171 glBindBuffer(GL_ARRAY_BUFFER, vbo[0].get());
172 glBufferData(GL_ARRAY_BUFFER,
sizeof(positions), positions.data(), GL_STREAM_DRAW);
176 std::array<vec2, 4> tex = {
183 glContext.progTex.activate();
184 glUniform4f(glContext.unifTexColor,
185 narrow<float>(r) * (1.0f / 255.0f),
186 narrow<float>(
g) * (1.0f / 255.0f),
187 narrow<float>(b) * (1.0f / 255.0f),
188 narrow<float>(alpha) * (1.0f / 255.0f));
189 glUniformMatrix4fv(glContext.unifTexMvp, 1, GL_FALSE,
190 glContext.pixelMvp.data());
191 const ivec2* offset =
nullptr;
192 glVertexAttribPointer(0, 2, GL_INT, GL_FALSE, 0, offset + 4);
193 glEnableVertexAttribArray(0);
194 glBindBuffer(GL_ARRAY_BUFFER, vbo[1].get());
195 glBufferData(GL_ARRAY_BUFFER,
sizeof(tex), tex.data(), GL_STREAM_DRAW);
196 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0,
nullptr);
197 glEnableVertexAttribArray(1);
199 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
200 glDisableVertexAttribArray(1);
201 glDisableVertexAttribArray(0);
206 glContext.progFill.activate();
207 glUniformMatrix4fv(glContext.unifFillMvp, 1, GL_FALSE,
208 glContext.pixelMvp.data());
209 glVertexAttribPointer(0, 2, GL_INT, GL_FALSE, 0,
nullptr);
210 glEnableVertexAttribArray(0);
212 narrow<float>(borderR) * (1.0f / 255.0f),
213 narrow<float>(borderG) * (1.0f / 255.0f),
214 narrow<float>(borderB) * (1.0f / 255.0f),
215 narrow<float>(borderA * alpha) * (1.0f / (255.0f * 255.0f)));
217 if ((2 * borderSize >= abs(size.x)) ||
218 (2 * borderSize >= abs(size.y))) {
220 glDrawArrays(GL_TRIANGLE_FAN, 4, 4);
223 if (borderSize > 0) {
224 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementsBuffer.
get());
225 glDrawElements(GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_BYTE,
nullptr);
226 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
231 std::array<uint8_t, 4>{bgR[0], bgG[0], bgB[0], uint8_t((bgA[0] * alpha) / 256)},
232 std::array<uint8_t, 4>{bgR[2], bgG[2], bgB[2], uint8_t((bgA[2] * alpha) / 256)},
233 std::array<uint8_t, 4>{bgR[3], bgG[3], bgB[3], uint8_t((bgA[3] * alpha) / 256)},
234 std::array<uint8_t, 4>{bgR[1], bgG[1], bgB[1], uint8_t((bgA[1] * alpha) / 256)},
236 glBindBuffer(GL_ARRAY_BUFFER, vbo[2].get());
237 glBufferData(GL_ARRAY_BUFFER,
sizeof(col), col.data(), GL_STREAM_DRAW);
238 glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0,
nullptr);
239 glEnableVertexAttribArray(1);
240 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
241 glDisableVertexAttribArray(1);
243 glDisableVertexAttribArray(0);
245 glDisableVertexAttribArray(0);
246 glBindBuffer(GL_ARRAY_BUFFER, 0);
Most basic/generic texture: only contains a texture ID.
void bind() const
Makes this texture the active GL texture.
GLuint get() const
Returns the underlying openGL handler id.