aboutsummaryrefslogtreecommitdiff
path: root/src/render.c
blob: 6c010298341b9031b30a7ecbab801cfdf6a3fdf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * render.c
 *
 *  Created on: 15.01.2018
 *      Author: Superleo1810
 */

#include "render.h"
//#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>

void init_render(Config *config)
{
	_config = config;
	s_arr = (u32 *) malloc((_config->width) * (_config->height) * sizeof(u32));
	_config->config_cpu.arr = s_arr;
	_config->config_opencl.arr = s_arr;
	//glutInit(0, NULL);
	glutInitWindowPosition(0, 0);
	glutInitWindowSize(_config->width, _config->height);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutCreateWindow("Renderer");

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, 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->width, _config->height, 0,
			GL_RGBA, GL_UNSIGNED_BYTE, s_arr);
	glBindTexture(GL_TEXTURE_2D, 0);
	//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _config->width, _config->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_arr);

	glMatrixMode(GL_PROJECTION);
	glOrtho(0, _config->width, 0, _config->height, -1, 1);
	glMatrixMode(GL_MODELVIEW);

	_config->config_cpu.tex = tex;
	_config->config_opencl.tex = tex;
	_config->config_cpu.zoom_func = zoom_func;
	_config->config_opencl.zoom_func = zoom_func;

	switch(_config->mode)
	{
	case MODE_CPU:
		init_cpu(&_config->config_cpu);
		glutDisplayFunc(render_cpu);
		if (_config->zoomSpecific)
		{
			glutIdleFunc(idle_cpu);
		}
		else
		{
			glutIdleFunc(idle_cpu_dummy);
			glutKeyboardFunc(keyboard_cpu);
			glutMouseFunc(mouse_cpu);
		}
		break;
	case MODE_OPENCL:
		init_opencl(&_config->config_opencl);
		glutDisplayFunc(render_opencl);
		if (_config->zoomSpecific)
		{
			glutIdleFunc(idle_opencl);
		}
		else
		{
			glutIdleFunc(idle_opencl_dummy);
			glutKeyboardFunc(keyboard_opencl);
			glutMouseFunc(mouse_opencl);
		}
		break;
	}

	glutMainLoop();

}

void show_render()
{

}

d64 zoom_func(d64 ft, d64 s)
{
	return (s - expl(-ft));
}