static blue pulsating noise
This commit is contained in:
parent
652d9fa921
commit
1a190594fe
2 changed files with 41 additions and 12 deletions
|
|
@ -2,8 +2,13 @@
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
in vec2 uv;
|
in vec2 uv;
|
||||||
uniform vec2 WindowSize;
|
uniform vec2 WindowSize;
|
||||||
|
uniform float time;
|
||||||
|
|
||||||
void main()
|
float rand(vec2 co){
|
||||||
{
|
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
|
||||||
FragColor = vec4(gl_FragCoord.xy / WindowSize, 0.0, 1.0);
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float glob = rand(gl_FragCoord.xy / WindowSize + time);
|
||||||
|
FragColor = vec4(glob * (sin(time)/2 + 0.5), glob, 1.0, 1.0); //vec4(gl_FragCoord.xy / WindowSize, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
42
main.c
42
main.c
|
|
@ -1,6 +1,7 @@
|
||||||
#define GL_GLEXT_PROTOTYPES
|
#define GL_GLEXT_PROTOTYPES
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
@ -51,7 +52,10 @@ GLuint load_shader(const char *path) {
|
||||||
long length = ftell(handle);
|
long length = ftell(handle);
|
||||||
fseek(handle, 0L, SEEK_SET);
|
fseek(handle, 0L, SEEK_SET);
|
||||||
char *string = malloc(length * sizeof(char));
|
char *string = malloc(length * sizeof(char));
|
||||||
fread(string, sizeof(char), length, handle);
|
if (!fread(string, sizeof(char), length, handle)) {
|
||||||
|
printf("failed to read shader file");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
fclose(handle);
|
fclose(handle);
|
||||||
|
|
||||||
GLuint shader = create_shader(string);
|
GLuint shader = create_shader(string);
|
||||||
|
|
@ -60,7 +64,23 @@ GLuint load_shader(const char *path) {
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct timespec program_start;
|
||||||
|
|
||||||
|
void init_timer() {
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &program_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
double time_since_start() {
|
||||||
|
struct timespec now;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
||||||
|
return (now.tv_sec - program_start.tv_sec) +
|
||||||
|
(now.tv_nsec - program_start.tv_nsec) / 1e9;
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
init_timer();
|
||||||
|
|
||||||
printf("Good Morning 🍵\n");
|
printf("Good Morning 🍵\n");
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
SDL_Window* window = SDL_CreateWindow("SDL3 OpenGL Cube",
|
SDL_Window* window = SDL_CreateWindow("SDL3 OpenGL Cube",
|
||||||
|
|
@ -82,12 +102,11 @@ int main() {
|
||||||
|
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
int running = 1;
|
int running = 1;
|
||||||
float angle = 0.0;
|
|
||||||
|
|
||||||
GLuint shader = load_shader("fragment.glsl"); //create_shader(fragment_shader_source);
|
GLuint shader = load_shader("fragment.glsl"); //create_shader(fragment_shader_source);
|
||||||
glUseProgram(shader);
|
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
|
double time;
|
||||||
while (running) {
|
while (running) {
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e)) {
|
||||||
if (e.type == SDL_EVENT_QUIT) running = false;
|
if (e.type == SDL_EVENT_QUIT) running = false;
|
||||||
|
|
@ -100,14 +119,20 @@ int main() {
|
||||||
// Rendorrrr
|
// Rendorrrr
|
||||||
glViewport(0, 0, w, h);
|
glViewport(0, 0, w, h);
|
||||||
|
|
||||||
int uniform_WindowSize = glGetUniformLocation(shader, "WindowSize");
|
|
||||||
glUniform2f(uniform_WindowSize, w, h);
|
|
||||||
|
|
||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // Dark gray background
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // Dark gray background
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
//drawCube();
|
// Shader parameters.
|
||||||
// Front
|
glUseProgram(shader);
|
||||||
|
|
||||||
|
int uniform_WindowSize = glGetUniformLocation(shader, "WindowSize");
|
||||||
|
glUniform2f(uniform_WindowSize, w, h);
|
||||||
|
|
||||||
|
time = time_since_start();
|
||||||
|
int uniform_time = glGetUniformLocation(shader, "time");
|
||||||
|
glUniform1f(uniform_time, (float)time);
|
||||||
|
|
||||||
|
// Draw quad.
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex2f(-1, 1);
|
glVertex2f(-1, 1);
|
||||||
glVertex2f(-1,-1);
|
glVertex2f(-1,-1);
|
||||||
|
|
@ -117,7 +142,6 @@ int main() {
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
angle += 0.5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkGlError();
|
checkGlError();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue