blob: ca2988e95e78ad0feb7e106b7901fadaf296d0cb (
plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#ifndef MANDEL_H
# define MANDEL_H
# include <stdio.h>
# include <stdlib.h>
# include <stdbool.h>
# include <math.h>
# include <GL/glew.h>
# include <SDL2/SDL.h>
# include <assert.h>
#define SDL_CALL(x) do { \
SDL_ClearError(); \
x; \
error_check_sdl(#x, __FILE__, __LINE__); \
} while (0)
# define GL_CALL(x) do { \
error_clear_gl(); \
x; \
error_check_gl(#x, __FILE__, __LINE__); \
} while (0)
typedef struct
{
uint8_t r;
uint8_t b;
uint8_t g;
} Color;
typedef struct
{
uint8_t h;
uint8_t s;
uint8_t l;
} ColorHSL;
typedef struct
{
double x;
double y;
} Point;
typedef struct
{
unsigned int id;
struct
{
int width;
int height;
int real_start;
int real_end;
int imag_start;
int imag_end;
int iterations;
int texture;
} location;
} Shader;
typedef struct
{
SDL_Window *window;
SDL_GLContext context;
bool running;
int width;
int height;
unsigned int vertex_buf;
unsigned int vertex_array;
unsigned int texture;
Shader shader;
// Color *palette;
double real_start;
double real_end;
double imag_start;
double imag_end;
int iterations;
} State;
// mandelbrot.c
int mandelbrot(double ca, double cb, int iterations);
// state.c
bool state_init(State *state);
void state_quit(State *state);
void state_run(State *state);
// event.c
void event_handle(State *state);
// error.c
void error_check_sdl(const char *code, const char *filename, int line_num);
void error_clear_gl(void);
void error_check_gl(const char *code, const char *filename, int line_num);
// color.c
unsigned int color_texture_new(int iterations);
// shader.c
bool shader_init(Shader *shader);
void shader_set_uniforms(Shader *shader, State *state);
#endif
|