aboutsummaryrefslogtreecommitdiff
path: root/src/render_cpu.c
diff options
context:
space:
mode:
authorLeonard Kugis <leonardkugis@gmail.com>2018-01-28 22:26:04 +0100
committerLeonard Kugis <leonardkugis@gmail.com>2018-01-28 22:26:04 +0100
commitcc884ee71f017d9493da22565fc33e6828da123d (patch)
tree33f97802d7f1461155d34fed0da2cfe1fe657945 /src/render_cpu.c
parentda4b72ea58e97d14306cfd322a8ef7a40337645d (diff)
Added point and click functionality
Diffstat (limited to 'src/render_cpu.c')
-rw-r--r--src/render_cpu.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/src/render_cpu.c b/src/render_cpu.c
index 5065d4d..8f8d439 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,35 @@ 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:
+ config_cpu->to_x = x_min + ((d64) x * (x_max - x_min)) / config_cpu->width;
+ config_cpu->to_y = y_min + ((d64) (config_cpu->height - y) * (y_max - y_min)) / config_cpu->height;
+ t_old_cpu = glutGet(GLUT_ELAPSED_TIME);
+ glutIdleFunc(idle_cpu);
+ break;
+ case GLUT_RIGHT_BUTTON:
+ glutIdleFunc(idle_cpu_dummy);
+ break;
+ }
+ }
+}