src/shadertoy: animated
This commit is contained in:
parent
74886b60c4
commit
a32667e0ef
@ -130,6 +130,9 @@ struct location {
|
||||
struct {
|
||||
unsigned int position;
|
||||
} attrib;
|
||||
struct {
|
||||
unsigned int time;
|
||||
} uniform;
|
||||
};
|
||||
|
||||
int main()
|
||||
@ -140,7 +143,7 @@ int main()
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
|
||||
//glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(1200, 1200, "LearnOpenGL", NULL, NULL);
|
||||
GLFWwindow* window = glfwCreateWindow(1600, 1200, "LearnOpenGL", NULL, NULL);
|
||||
if (window == NULL) {
|
||||
const char* description;
|
||||
glfwGetError(&description);
|
||||
@ -150,7 +153,7 @@ int main()
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glViewport(0, 0, 1200, 1200);
|
||||
glViewport(0, 0, 1600, 1200);
|
||||
//glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
unsigned int vertex_buffer = make_buffer(GL_ARRAY_BUFFER,
|
||||
@ -167,6 +170,11 @@ int main()
|
||||
printf("attributes:\n position %u\n",
|
||||
location.attrib.position);
|
||||
|
||||
location.uniform.time = glGetUniformLocation(shaderProgram, "time");
|
||||
printf("uniforms:\n time %u\n",
|
||||
location.uniform.time);
|
||||
|
||||
float time = 0;
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
@ -188,6 +196,8 @@ int main()
|
||||
(void*)0
|
||||
);
|
||||
glEnableVertexAttribArray(location.attrib.position);
|
||||
glUniform1f(location.uniform.time, time);
|
||||
time += 0.01;
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
|
||||
@ -2,7 +2,53 @@
|
||||
|
||||
varying vec2 pos_out;
|
||||
|
||||
uniform float time;
|
||||
|
||||
/*
|
||||
vec3 palette(float t) {
|
||||
vec3 a = vec3(0.5, 0.5, 0.5);
|
||||
vec3 b = vec3(0.5, 0.5, 0.5);
|
||||
vec3 c = vec3(1.0, 1.0, 1.0);
|
||||
vec3 d = vec3(0.263, 0.416, 0.557);
|
||||
|
||||
return a + b * cos(6.28318548202514648438 * (c * t + d));
|
||||
}
|
||||
*/
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(pos_out, 0, 1);
|
||||
vec2 uv = pos_out;
|
||||
//gl_FragColor = vec4(uv, 0, 1);
|
||||
//gl_FragColor = gl_Color;
|
||||
float d = length(uv);
|
||||
|
||||
//d -= 0.5;
|
||||
//d = abs(d);
|
||||
//d = step(0.1, d);
|
||||
//d = smoothstep(0.0, 0.1, d);
|
||||
|
||||
gl_FragColor = vec4(d, 0, 0, 1);
|
||||
|
||||
/*
|
||||
vec3 col = vec3(1.0, 2.0, 3.0);
|
||||
|
||||
d = sin(d * 8.0 + time)/8.0;
|
||||
d = abs(d);
|
||||
d = 0.02 / d;
|
||||
|
||||
col *= d;
|
||||
|
||||
gl_FragColor = vec4(col, 1);
|
||||
*/
|
||||
/*
|
||||
vec3 col = palette(d + time);
|
||||
|
||||
d = sin(d * 8.0 + time)/8.0;
|
||||
d = abs(d);
|
||||
d = 0.02 / d;
|
||||
|
||||
col *= d;
|
||||
|
||||
gl_FragColor = vec4(col, 1);
|
||||
*/
|
||||
}
|
||||
|
||||
@ -7,5 +7,6 @@ varying vec2 pos_out;
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(position, 1);
|
||||
pos_out = vec2(position);
|
||||
pos_out = vec2(position.x * 4.0 / 3.0, pos_out.y);
|
||||
//gl_FrontColor = vec4(position.xy, 0, 1);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user