From b5e820f7c361842aca1b53332f9e27b67eff18d4 Mon Sep 17 00:00:00 2001 From: davidovski Date: Fri, 23 Apr 2021 09:26:10 +0100 Subject: initial commit --- brotshader.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 brotshader.c (limited to 'brotshader.c') diff --git a/brotshader.c b/brotshader.c new file mode 100644 index 0000000..d0fd96b --- /dev/null +++ b/brotshader.c @@ -0,0 +1,70 @@ +#include + +const int width = 1280; +const int height = 1280; + +int main() { + InitWindow(width, height, "brotshader"); + + Shader shader = LoadShader(0, "mandelbrot.glsl"); + + RenderTexture2D target = LoadRenderTexture(width, height); + + float c[2] = {0, 0}; + + float offset[2] = {0, 0}; + float zoom = 2.0f; + int max = 255; + + int resolutionLoc = GetShaderLocation(shader, "resolution"); + int locationLoc = GetShaderLocation(shader, "location"); + int zoomLoc = GetShaderLocation(shader, "zoom"); + int maxLoc = GetShaderLocation(shader, "max"); + + float screen[2] = {(float)width, (float)height}; + + SetShaderValue(shader, resolutionLoc, screen, UNIFORM_VEC2); + SetShaderValue(shader, locationLoc, &offset, UNIFORM_VEC2); + SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT); + SetShaderValue(shader, maxLoc, &max, UNIFORM_INT); + + SetTargetFPS(60); + + while (!WindowShouldClose()) { + + if (IsKeyDown(KEY_UP)) offset[1] -= zoom * 0.01f; + if (IsKeyDown(KEY_DOWN)) offset[1] += zoom * 0.01f; + if (IsKeyDown(KEY_RIGHT)) offset[0] -= zoom * 0.01f; + if (IsKeyDown(KEY_LEFT)) offset[0] += zoom * 0.01f; + + if (IsKeyDown(KEY_W)) zoom -= zoom * 0.01f; + if (IsKeyDown(KEY_S)) zoom += zoom * 0.01f; + if (IsKeyDown(KEY_A)) max -= 1; + if (IsKeyDown(KEY_D)) max += 1; + + SetShaderValue(shader, resolutionLoc, screen, UNIFORM_VEC2); + SetShaderValue(shader, locationLoc, &offset, UNIFORM_VEC2); + SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT); + SetShaderValue(shader, maxLoc, &max, UNIFORM_INT); + + BeginDrawing(); + + ClearBackground(RAYWHITE); + + BeginTextureMode(target); + DrawRectangle(0, 0, width, height, BLACK); + EndTextureMode(); + + BeginShaderMode(shader); + DrawTexture(target.texture, 0, 0, WHITE); + EndShaderMode(); + + EndDrawing(); + } + + UnloadShader(shader); + UnloadRenderTexture(target); + + CloseWindow(); +} + -- cgit v1.2.1