diff options
author | Leonard Kugis <leonardkugis@gmail.com> | 2018-01-16 01:21:27 +0100 |
---|---|---|
committer | Leonard Kugis <leonardkugis@gmail.com> | 2018-01-16 01:21:27 +0100 |
commit | c4b5e0a48835b6bdbf4d3d92fd42b29a22662ed4 (patch) | |
tree | 807f2c1ac0010ce91f5560d6bf852ecca45a221a /src/render.c | |
parent | 9d46c7e44b0c8e0625894dbb688e9b2804d83c9d (diff) |
Mandelbrot drawing possible
Diffstat (limited to 'src/render.c')
-rw-r--r-- | src/render.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/render.c b/src/render.c new file mode 100644 index 0000000..e06c967 --- /dev/null +++ b/src/render.c @@ -0,0 +1,72 @@ +/* + * render.c + * + * Created on: 15.01.2018 + * Author: Superleo1810 + */ + +#include "render.h" + +void render_init(Config *config, u32 (*sfunc) (double, double, u32)) +{ + _config = config; + _sfunc = sfunc; + + ui_render.window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); + gtk_window_set_default_size(ui_render.window, config->width, config->height); + + ui_render.frame = GTK_FRAME(gtk_frame_new(NULL)); + gtk_container_add(GTK_CONTAINER(ui_render.window), ui_render.frame); + + ui_render.drawing_area = GTK_DRAWING_AREA(gtk_drawing_area_new()); + gtk_widget_set_size_request(GTK_WIDGET(ui_render.drawing_area), config->width, config->height); + g_signal_connect(G_OBJECT(ui_render.drawing_area), "draw", G_CALLBACK(on_draw), NULL); + gtk_container_add(GTK_CONTAINER(ui_render.frame), ui_render.drawing_area); + +} + +void render_show() +{ + gtk_widget_show_all(GTK_WIDGET(ui_render.window)); +} + +void on_draw(GtkWidget *widget, cairo_t *cr, gpointer data) +{ + cairo_surface_t *image; + // TODO: MUSS UNBEDINGT SEPARAT GECALLT WERDEN, SONST KEINE 60 FPS + image = render_surface(); + cairo_set_source_surface(cr, image, 0, 0); + cairo_paint(cr); +} + +cairo_surface_t *render_surface() +{ + cairo_surface_t *result; + unsigned char *current_row; + int stride; + double x_math, y_math; + u32 iterations; + + result = cairo_image_surface_create(CAIRO_FORMAT_RGB24, _config->width, _config->height); + if (cairo_surface_status(result) != CAIRO_STATUS_SUCCESS) + return result; + + cairo_surface_flush(result); + current_row = cairo_image_surface_get_data(result); + stride = cairo_image_surface_get_stride(result); + for (int y = 0; y < _config->height; y++) { + u32 *row = (void *) current_row; + for (int x = 0; x < _config->width; x++) { + x_math = /*x_MIN*/-2.0 + ((double) x * (/*x_MAX*/1.0 - /*x_MIN*/-2.0)) / _config->width; + y_math = /*y_MIN*/-1.0 + ((double) (_config->height - y) * (/*y_MAX*/1.0 - /*y_MIN*/-1.0)) / _config->height; + iterations = _sfunc(x_math, y_math, _config->iterations); + row[x] = (((1<<24)-1)*iterations)/_config->iterations; +// if (iterations > 1<<8) +// printf("schon gruen\n"); + } + + current_row += stride; + } + cairo_surface_mark_dirty(result); + return result; +} |