diff options
Diffstat (limited to 'src/render_cpu.c')
-rw-r--r-- | src/render_cpu.c | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/src/render_cpu.c b/src/render_cpu.c index 5065d4d..64fc9ec 100644 --- a/src/render_cpu.c +++ b/src/render_cpu.c @@ -8,6 +8,15 @@ #include "render_cpu.h" #define HAVE_STRUCT_TIMESPEC +void idle_cpu_dummy(void) +{ +// glBindTexture(GL_TEXTURE_2D, config_cpu->tex); +// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, config_cpu->width, +// config_cpu->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, config_cpu->arr); +// glBindTexture(GL_TEXTURE_2D, 0); + glutPostRedisplay(); +} + void init_cpu(CpuConfig *config) { config_cpu = config; @@ -21,10 +30,15 @@ void init_cpu(CpuConfig *config) y_max = y_max_s; calculate(x_min, y_min, x_max, y_max, config_cpu->set_func, config_cpu->arr); + t_old_cpu = glutGet(GLUT_ELAPSED_TIME); } void render_cpu(void) { + glBindTexture(GL_TEXTURE_2D, config_cpu->tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, config_cpu->width, + config_cpu->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, config_cpu->arr); + glBindTexture(GL_TEXTURE_2D, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, config_cpu->tex); glEnable(GL_TEXTURE_2D); @@ -66,6 +80,9 @@ void calculate_t(void *args) x_math = _args->x_min + ((d64) x * (_args->x_max - _args->x_min)) / config_cpu->width; y_math = _args->y_min + ((d64) (config_cpu->height - y) * (_args->y_max - _args->y_min)) / config_cpu->height; iterations = _args->sfunc(x_math, y_math, config_cpu->iterations); +// color[2].s0 = ((1.0f + native_cos(c)) * 0.5f) * 255; +// color[2].s1 = ((1.0f + native_cos(2.0f * c + 2.0f * 3.1416f / 3.0f)) * 0.5f) * 255; +// color[2].s2 = ((1.0f + native_cos(c - 2.0f * 3.1416f / 3.0f)) * 0.5f) * 255; _args->arr[COORDS(x, y, config_cpu->width)] = (((1<<24)-1)*iterations)/config_cpu->iterations; } } @@ -73,15 +90,14 @@ void calculate_t(void *args) void idle_cpu(void) { - static int t_old; int t = 0, delta = 0; do { t = glutGet(GLUT_ELAPSED_TIME); - delta = t - t_old; + delta = t - t_old_cpu; } while(delta < 16); // TODO: Hardcoded FPS - t_old = t; + t_old_cpu = t; calculate(x_min, y_min, x_max, y_max, config_cpu->set_func, config_cpu->arr); //glGenTextures(1, &tex); @@ -97,3 +113,44 @@ void idle_cpu(void) y_max = y_max_s - config_cpu->zoom_func(ft, (d64)1.0 - config_cpu->to_y); glutPostRedisplay(); } + +void keyboard_cpu(unsigned char key, int mouseX, int mouseY) +{ + switch(key) + { + case 'i': + config_cpu->iterations++; + break; + case 'd': + config_cpu->iterations--; + break; + } +} + +void mouse_cpu(int button, int state, int x, int y) +{ + if (state == GLUT_DOWN) + { + switch (button) + { + case GLUT_LEFT_BUTTON: + if (config_cpu->speed < 0) + config_cpu->speed = (-1) * config_cpu->speed; + break; + case GLUT_RIGHT_BUTTON: + if (config_cpu->speed > 0) + config_cpu->speed = (-1) * config_cpu->speed; + break; + } + config_cpu->to_x = x_min + + ((d64) x * (x_max - x_min)) / config_cpu->width; + config_cpu->to_y = y_min + + ((d64) y * (y_max - y_min)) / config_cpu->height; + t_old_cpu = glutGet(GLUT_ELAPSED_TIME); + glutIdleFunc(idle_cpu); + } + else if (state == GLUT_UP) + { + glutIdleFunc(idle_cpu_dummy); + } +} |