1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include <raylib.h>
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();
}
|