diff options
author | Leonard Kugis <leonardkugis@gmail.com> | 2018-02-01 01:27:30 +0100 |
---|---|---|
committer | Leonard Kugis <leonardkugis@gmail.com> | 2018-02-01 01:27:30 +0100 |
commit | 18e5b2554b4cd73207e936e76e32c9d376cd1ba8 (patch) | |
tree | 917dba471db5b3c40c78f247a601e8db2d73056b /src/render_cpu.c | |
parent | be4f2582062196dd6ecf393f55566367bc1dfa9f (diff) |
abstracted rendering, cpu currently crashing randomly while zooming
Diffstat (limited to 'src/render_cpu.c')
-rw-r--r-- | src/render_cpu.c | 104 |
1 files changed, 3 insertions, 101 deletions
diff --git a/src/render_cpu.c b/src/render_cpu.c index ef66e37..d5e0c09 100644 --- a/src/render_cpu.c +++ b/src/render_cpu.c @@ -8,51 +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(config_t *config) { config_cpu = config; - x_min_s = -2.0; - x_max_s = 1.0; - y_min_s = -1.0; - y_max_s = 1.0; - x_min = x_min_s; - x_max = x_max_s; - y_min = y_min_s; - 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) +void render_cpu(d64 x_min, d64 y_min, d64 x_max, d64 y_max) { - 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); - - glBegin(GL_QUADS); - glTexCoord2i(0, 0); glVertex2i(0, 0); - glTexCoord2i(0, 1); glVertex2i(0, config_cpu->height); - glTexCoord2i(1, 1); glVertex2i(config_cpu->width, config_cpu->height); - glTexCoord2i(1, 0); glVertex2i(config_cpu->width, 0); - glEnd(); - - glDisable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, 0); - glutSwapBuffers(); + calculate(x_min, y_min, x_max, y_max, config_cpu->set_func, config_cpu->arr); + printf("end render cpu\n"); } void calculate(d64 x_min, d64 y_min, d64 x_max, d64 y_max, u32 (*sfunc) (d64, d64, u32), u32 *arr) @@ -90,67 +54,5 @@ void calculate_t(void *args) void idle_cpu(void) { - int t = 0, delta = 0; - do - { - t = glutGet(GLUT_ELAPSED_TIME); - delta = t - t_old_cpu; - } - while(delta < 16); // TODO: Hardcoded FPS - t_old_cpu = t; - - calculate(x_min, y_min, x_max, y_max, config_cpu->set_func, config_cpu->arr); - //glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, config_cpu->tex); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - 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); - ft+=(config_cpu->speed*(delta/1000.0)); - x_min = x_min_s + config_cpu->zoom_func(ft, (d64)2.0 + config_cpu->to_x); - y_min = y_min_s + config_cpu->zoom_func(ft, (d64)1.0 + config_cpu->to_y); - x_max = x_max_s - config_cpu->zoom_func(ft, (d64)1.0 - config_cpu->to_x); - 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); - } } |