Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
|
178c4a3782 | |
|
ddfe9bfc3c |
110
src/main.c
110
src/main.c
|
@ -129,81 +129,14 @@ void init(void) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GLfloat vertices[] = {
|
GLfloat vertices[] = {
|
||||||
// X // Y
|
// X // Y // vertValue
|
||||||
|
-0.75f, -0.1f, 0.0f,
|
||||||
|
-0.75f, 0.1f, 0.0f,
|
||||||
|
0.75f, 0.1f, 1.0f,
|
||||||
|
|
||||||
// left vertical bar
|
-0.75f, -0.1f, 0.0f,
|
||||||
-0.35f, -0.6f,
|
0.75f, -0.1f, 1.0f,
|
||||||
-0.35f, 0.6f,
|
0.75f, 0.1f, 1.0f
|
||||||
-0.2f, 0.6f,
|
|
||||||
|
|
||||||
-0.35f, -0.6f,
|
|
||||||
-0.2f, 0.6f,
|
|
||||||
-0.2f, -0.6f,
|
|
||||||
|
|
||||||
// right vertical bar
|
|
||||||
0.35f, -0.6f,
|
|
||||||
0.35f, 0.6f,
|
|
||||||
0.2f, 0.6f,
|
|
||||||
|
|
||||||
0.35f, -0.6f,
|
|
||||||
0.2f, 0.6f,
|
|
||||||
0.2f, -0.6f,
|
|
||||||
|
|
||||||
// middle bar
|
|
||||||
-0.2f, -0.1f,
|
|
||||||
-0.2f, 0.1f,
|
|
||||||
0.2f, 0.1f,
|
|
||||||
|
|
||||||
-0.2f, -0.1f,
|
|
||||||
0.2f, 0.1f,
|
|
||||||
0.2f, -0.1f,
|
|
||||||
|
|
||||||
// bottom bar
|
|
||||||
-0.35f, -0.7f,
|
|
||||||
-0.35f, -0.9f,
|
|
||||||
0.35f, -0.9f,
|
|
||||||
|
|
||||||
-0.35f, -0.7f,
|
|
||||||
0.35f, -0.9f,
|
|
||||||
0.35f, -0.7f
|
|
||||||
};
|
|
||||||
|
|
||||||
GLfloat colors[] = {
|
|
||||||
// R // G // B
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f, 0.3f,
|
|
||||||
1.0f, 0.3f, 0.0f,
|
|
||||||
|
|
||||||
1.0f, 0.3f, 0.3f,
|
|
||||||
1.0f, 0.3f, 0.6f,
|
|
||||||
1.0f, 0.6f, 0.3f,
|
|
||||||
|
|
||||||
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.3f,
|
|
||||||
0.3f, 1.0f, 0.0f,
|
|
||||||
|
|
||||||
0.3f, 1.0f, 0.3f,
|
|
||||||
0.3f, 1.0f, 0.6f,
|
|
||||||
0.6f, 1.0f, 0.3f,
|
|
||||||
|
|
||||||
|
|
||||||
0.3f, 0.3f, 1.0f,
|
|
||||||
0.3f, 0.6f, 1.0f,
|
|
||||||
0.6f, 0.3f, 1.0f,
|
|
||||||
|
|
||||||
0.3f, 0.3f, 1.0f,
|
|
||||||
0.3f, 0.6f, 1.0f,
|
|
||||||
0.6f, 0.3f, 1.0f,
|
|
||||||
|
|
||||||
|
|
||||||
1.0f, 1.0f, 0.0f,
|
|
||||||
1.0f, 1.0f, 0.1f,
|
|
||||||
1.0f, 1.0f, 0.2f,
|
|
||||||
|
|
||||||
1.0f, 1.0f, 0.7f,
|
|
||||||
1.0f, 1.0f, 0.8f,
|
|
||||||
1.0f, 1.0f, 0.9f
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DEBUG("Creating vertext buffer");
|
DEBUG("Creating vertext buffer");
|
||||||
|
@ -213,13 +146,6 @@ void init(void) {
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
DEBUG("Creating colour buffer");
|
|
||||||
GLuint colorBuffer;
|
|
||||||
glGenBuffers(1, &colorBuffer);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
DEBUG("Creating vertex array object");
|
DEBUG("Creating vertex array object");
|
||||||
// create vertex array object
|
// create vertex array object
|
||||||
glGenVertexArrays(1, &vertexArrayObject);
|
glGenVertexArrays(1, &vertexArrayObject);
|
||||||
|
@ -232,17 +158,14 @@ void init(void) {
|
||||||
2, // number of values to read
|
2, // number of values to read
|
||||||
GL_FLOAT, // type of value
|
GL_FLOAT, // type of value
|
||||||
GL_FALSE, // if values are normalised
|
GL_FALSE, // if values are normalised
|
||||||
2 * sizeof(GLfloat), // stride - distance between vertices
|
3 * sizeof(GLfloat), // stride - distance between vertices
|
||||||
0 // start offset
|
0 // start offset
|
||||||
);
|
);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
// vertex color data
|
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void*)(2*sizeof(GLfloat)));
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
|
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
|
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
@ -265,11 +188,18 @@ void draw(void) {
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
|
|
||||||
GLuint positionLocation = glGetUniformLocation(program, "uPosition");
|
|
||||||
glUniform2f(positionLocation, cos(currentHue * 2 * M_PI) * 0.2f, sin(currentHue * 2 * M_PI) * 0.2f);
|
|
||||||
|
|
||||||
glBindVertexArray(vertexArrayObject);
|
glBindVertexArray(vertexArrayObject);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 48);
|
|
||||||
|
GLuint yPositionLocation = glGetUniformLocation(program, "uYPosition");
|
||||||
|
GLuint patternLocation = glGetUniformLocation(program, "uPattern");
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
glUniform1f(yPositionLocation, i / 4.0f * -1.4f + 0.7f);
|
||||||
|
glUniform1i(patternLocation, i);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
||||||
|
|
|
@ -1,5 +1,55 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
in vec3 vertexColor;
|
|
||||||
void main() {
|
float pi = 3.14159;
|
||||||
gl_FragColor = vec4(vertexColor, 1.0);
|
vec3 hsvToRgb(vec3 hsl) {
|
||||||
|
while (hsl.x > 1) {
|
||||||
|
hsl.x -= 1;
|
||||||
|
}
|
||||||
|
int hi = int(floor(hsl.x * 6));
|
||||||
|
float f = hsl.x * 6 - hi;
|
||||||
|
|
||||||
|
float p = hsl.z * (1 - hsl.y);
|
||||||
|
float q = hsl.z * (1 - hsl.y * f);
|
||||||
|
float t = hsl.z * (1 - hsl.y * (1 - f));
|
||||||
|
|
||||||
|
switch (hi) {
|
||||||
|
case 0: return vec3(hsl.z, t, p);
|
||||||
|
case 1: return vec3(q, hsl.z, p);
|
||||||
|
case 2: return vec3(p, hsl.z, t);
|
||||||
|
case 3: return vec3(p, q, hsl.z);
|
||||||
|
case 4: return vec3(t, p, hsl.z);
|
||||||
|
case 5: return vec3(hsl.z, p, q);
|
||||||
|
default: return vec3(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
in float fragValue;
|
||||||
|
flat in int pattern;
|
||||||
|
void main() {
|
||||||
|
vec4 fragColor1 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
vec4 fragColor2 = vec4(0.0, 1.0, 0.0, 1.0);
|
||||||
|
switch (pattern) {
|
||||||
|
case 0:
|
||||||
|
gl_FragColor = vec4(hsvToRgb(vec3(fragValue, 1, 1)), 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
gl_FragColor = vec4(hsvToRgb(vec3(0, fragValue, 1)), 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
gl_FragColor = vec4(hsvToRgb(vec3(0, 1, fragValue)), 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
gl_FragColor = mix(fragColor1, fragColor2, sin(fragValue * 4 * 3.14159) * 0.5 + 0.5);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
gl_FragColor = mix(fragColor1, fragColor2, step(0.5, sin(fragValue * 4 * 3.14159) * 0.5 + 0.5));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
gl_FragColor = vec4(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,15 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
layout (location = 0) in vec2 aPosition;
|
layout (location = 0) in vec2 aPosition;
|
||||||
layout (location = 1) in vec3 aColor;
|
layout (location = 1) in float vertValue;
|
||||||
uniform vec2 uPosition;
|
|
||||||
|
|
||||||
out vec3 vertexColor;
|
uniform float uYPosition;
|
||||||
|
uniform int uPattern;
|
||||||
|
|
||||||
|
out float fragValue;
|
||||||
|
flat out int pattern;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vertexColor = aColor;
|
pattern = uPattern;
|
||||||
gl_Position = vec4(uPosition + aPosition, 0.0, 1.0);
|
fragValue = vertValue;
|
||||||
|
gl_Position = vec4(aPosition.x, aPosition.y + uYPosition, 0.0, 1.0);
|
||||||
}
|
}
|
Loading…
Reference in New Issue