6 #include <GLFW/glfw3.h>
50 if (action == GLFW_PRESS) {
51 int shift = mods & GLFW_MOD_SHIFT;
52 int ctrl = mods & GLFW_MOD_CONTROL;
65 int direction = yoffset > 0 ? 1 : yoffset < 0 ? -1 : 0;
66 bool shift = glfwGetKey(w, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(w, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS;
67 bool ctrl = glfwGetKey(w, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || glfwGetKey(w, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS;
79 bool shift = mods & GLFW_MOD_SHIFT;
80 bool ctrl = mods & GLFW_MOD_CONTROL;
81 if (action == GLFW_PRESS) {
108 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
109 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
110 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
111 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
112 glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
113 GLFWwindow *window = glfwCreateWindow(width, height,
"mightymandel", 0, 0);
115 log_message(level,
"couldn't create window with OpenGL core %d.%d context\n", major, minor);
121 #define ADD(key,format,...) do{ \
122 if (0 <= mpfr_asprintf(&s, format, __VA_ARGS__)) { \
123 metadata_update(meta, key, s); \
132 s = strrchr(render_options->
filename,
'/');
135 ADD(
"view.real",
"%Re", render_options->
centerx);
136 ADD(
"view.imag",
"%Re", render_options->
centery);
137 ADD(
"view.radius",
"%Re", render_options->
radius);
138 ADD(
"view.aspect",
"%f", render_options->
width / (
double) render_options->
height);
139 ADD(
"image.width",
"%d", render_options->
width);
140 ADD(
"image.height",
"%d", render_options->
height);
141 ADD(
"image.pixels",
"%d", render_options->
width * render_options->
height);
143 double pxs = 2.0 * mpfr_get_d(render_options->
radius, MPFR_RNDN) / render_options->
height;
144 ADD(
"calc.pixelspacing",
"%.16e", pxs);
149 ADD(
"calc.perturb.maxglitch",
"%.16e", render_options->
max_glitch);
150 ADD(
"calc.perturb.maxblob",
"%d", render_options->
max_blob);
151 ADD(
"calc.sharpness",
"%.16e", render_options->
sharpness);
154 ADD(
"colour.weight",
"%.16e", render_options->
weight);
161 ADD(
"zoom.frame",
"%d", zoom->
frame);
171 ADD(
"tiling.col",
"%d", tiling->
col);
172 ADD(
"tiling.row",
"%d", tiling->
row);
174 double iterations = 0, exterior = 0, interior = 0, glitch = 0;
177 ADD(
"stats.maxiters",
"%f", iterations);
178 ADD(
"stats.exterior",
"%f", exterior);
179 ADD(
"stats.interior",
"%f", interior);
180 ADD(
"stats.glitch",
"%f", glitch);
181 int n = mpfr_snprintf(0, 0,
"%smightymandel %Re + %Re i @ %Re\n", prefix, render_options->
centerx, render_options->
centery, render_options->
radius);
183 s = malloc(n + m + 1);
184 mpfr_snprintf(s, n + m + 1,
"%smightymandel %Re + %Re i @ %Re\n", prefix, render_options->
centerx, render_options->
centery, render_options->
radius);
192 int main(
int argc,
char **argv) {
198 memset(&options, 0,
sizeof(
struct options));
199 options.
width = 1280;
218 log_message(
LOG_FATAL,
"at most one of --interactive --one-shot (--tile || -zoom) can be used\n");
220 }
else if (sanity == 0) {
267 mpfr_set_d(render_options.
centerx, -0.75, MPFR_RNDN);
268 mpfr_set_d(render_options.
centery, 0, MPFR_RNDN);
269 mpfr_set_d(render_options.
radius, 2, MPFR_RNDN);
293 mpfr_inits2(53, cx, cy, cz, (mpfr_ptr) 0);
300 mpfr_clears(cx, cy, cz, (mpfr_ptr) 0);
319 glfwMakeContextCurrent(window);
320 glewExperimental = GL_TRUE;
329 render.
begun =
false;
331 GLsizei bytes_allocated = 0;
335 int kb_allocated = (bytes_allocated + 1023) / 1024;
337 if (vram < kb_allocated) {
377 glfwSetWindowShouldClose(window, GL_TRUE);
398 struct render_options last_render_options;
403 while (! glfwWindowShouldClose(window)) {
405 if (first || ! mpfr_equal_p(last_render_options.
centerx, render_options.
centerx)) {
408 if (first || ! mpfr_equal_p(last_render_options.
centery, render_options.
centery)) {
411 if (first || ! mpfr_equal_p(last_render_options.
radius, render_options.
radius)) {
414 if (first || last_render_options.
method != render_options.
method) {
437 for (
int frame = 0; ! glfwWindowShouldClose(window) && frame < frames; ++frame) {
441 for (
int row = 0; ! glfwWindowShouldClose(window) && row < rows; ++row) {
442 for (
int col = 0; ! glfwWindowShouldClose(window) && col < cols; ++col) {
450 timeout = fmax(timeout, 1.1 * tile_took);
453 char *name =
filename_name(&filename,
"ppm", frame, col, row);
464 if (! glfwWindowShouldClose(window) && options.
zoom) {
468 if (! glfwWindowShouldClose(window) && options.
tile) {