static blue pulsating noise
This commit is contained in:
parent
652d9fa921
commit
1a190594fe
2 changed files with 41 additions and 12 deletions
42
main.c
42
main.c
|
|
@ -1,6 +1,7 @@
|
|||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/gl.h>
|
||||
#include <SDL3/SDL.h>
|
||||
|
|
@ -51,7 +52,10 @@ GLuint load_shader(const char *path) {
|
|||
long length = ftell(handle);
|
||||
fseek(handle, 0L, SEEK_SET);
|
||||
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);
|
||||
|
||||
GLuint shader = create_shader(string);
|
||||
|
|
@ -60,7 +64,23 @@ GLuint load_shader(const char *path) {
|
|||
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() {
|
||||
init_timer();
|
||||
|
||||
printf("Good Morning 🍵\n");
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
SDL_Window* window = SDL_CreateWindow("SDL3 OpenGL Cube",
|
||||
|
|
@ -82,12 +102,11 @@ int main() {
|
|||
|
||||
SDL_Event e;
|
||||
int running = 1;
|
||||
float angle = 0.0;
|
||||
|
||||
GLuint shader = load_shader("fragment.glsl"); //create_shader(fragment_shader_source);
|
||||
glUseProgram(shader);
|
||||
|
||||
int w, h;
|
||||
double time;
|
||||
while (running) {
|
||||
while (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_EVENT_QUIT) running = false;
|
||||
|
|
@ -100,14 +119,20 @@ int main() {
|
|||
// Rendorrrr
|
||||
glViewport(0, 0, w, h);
|
||||
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // Dark gray background
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Shader parameters.
|
||||
glUseProgram(shader);
|
||||
|
||||
int uniform_WindowSize = glGetUniformLocation(shader, "WindowSize");
|
||||
glUniform2f(uniform_WindowSize, w, h);
|
||||
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // Dark gray background
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//drawCube();
|
||||
// Front
|
||||
time = time_since_start();
|
||||
int uniform_time = glGetUniformLocation(shader, "time");
|
||||
glUniform1f(uniform_time, (float)time);
|
||||
|
||||
// Draw quad.
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(-1, 1);
|
||||
glVertex2f(-1,-1);
|
||||
|
|
@ -117,7 +142,6 @@ int main() {
|
|||
glEnd();
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
angle += 0.5;
|
||||
}
|
||||
|
||||
checkGlError();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue