17 , noiseTexture(true, true)
21 std::uniform_int_distribution distribution(0, 255);
22 std::array<uint8_t, 128 * 128> buf;
24#if OPENGL_VERSION < OPENGL_3_3
25 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 128, 128, 0,
26 GL_LUMINANCE, GL_UNSIGNED_BYTE, buf.data());
29 glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, 128, 128, 0,
30 GL_RED, GL_UNSIGNED_BYTE, buf.data());
31 GLint swizzleMask[] = {GL_RED, GL_RED, GL_RED, GL_ONE};
32 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
35 static constexpr std::array pos = {
45 glBindBuffer(GL_ARRAY_BUFFER, vbo[0].get());
46 glBufferData(GL_ARRAY_BUFFER,
sizeof(pos), pos.data(), GL_STATIC_DRAW);
47 glBindBuffer(GL_ARRAY_BUFFER, 0);
54 static unsigned cnt = 0;
58 const std::array tex = {
59 offset +
vec2(0.0f, 2.0f),
60 offset +
vec2(2.0f, 2.0f),
61 offset +
vec2(2.0f, 0.0f),
62 offset +
vec2(0.0f, 0.0f),
66 glContext.progTex.activate();
67 glUniform4f(glContext.unifTexColor, 1.0f, 1.0f, 1.0f, 1.0f);
69 glUniformMatrix4fv(glContext.unifTexMvp, 1, GL_FALSE, I.
data());
71 glBindBuffer(GL_ARRAY_BUFFER, vbo[0].get());
72 const vec2* base =
nullptr;
73 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, base + 4 * cnt);
74 glEnableVertexAttribArray(0);
76 glBindBuffer(GL_ARRAY_BUFFER, vbo[1].get());
77 glBufferData(GL_ARRAY_BUFFER,
sizeof(tex), tex.data(), GL_STREAM_DRAW);
78 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0,
nullptr);
79 glEnableVertexAttribArray(1);
82 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
83 glDisableVertexAttribArray(1);
84 glDisableVertexAttribArray(0);
85 glBindBuffer(GL_ARRAY_BUFFER, 0);
void bind() const
Makes this texture the active GL texture.
float random_float(float from, float upto)
Return a random float in the range [from, upto) (note: half-open interval).