summaryrefslogtreecommitdiff
path: root/src/renderer.cc
blob: 77dcde980fa06a457769485cb45a0f80e44722a9 (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
87
88
#include "renderer.h"
#include "rendersettings.h"
#include "linalg.h"

void Renderer::setColor(const float color[4], GLint *shaderinfo) const
{
	Color4f col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR);
	float c[4] = {color[0], color[1], color[2], color[3]};
	if (c[0] < 0) c[0] = col[0];
	if (c[1] < 0) c[1] = col[1];
	if (c[2] < 0) c[2] = col[2];
	if (c[3] < 0) c[3] = col[3];
	glColor4fv(c);
	if (shaderinfo) {
		glUniform4f(shaderinfo[1], c[0], c[1], c[2], c[3]);
		glUniform4f(shaderinfo[2], (c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0);
	}
}

void Renderer::setColor(ColorMode colormode, const float color[4], GLint *shaderinfo) const
{
	if (colormode == COLORMODE_BACKGROUND && 
			color[0] >= 0 || color[1] >= 0 || color[2] >= 0 || color[3] >= 0) {

		Color4f col;
    col.setRgb(180, 180, 180, 255);
		float c[4] = {color[0], color[1], color[2], color[3]};
		if (c[0] < 0) c[0] = col[0];
		if (c[1] < 0) c[1] = col[1];
		if (c[2] < 0) c[2] = col[2];
		if (c[3] < 0) c[3] = col[3];

		c[3] /= 2; // Background objects are half-transparent
		setColor(c, shaderinfo);
	}
	else {
		setColor(colormode, shaderinfo);
	}
}

void Renderer::setColor(ColorMode colormode, GLint *shaderinfo) const
{
	Color4f col;
	switch (colormode) {
	case COLORMODE_NONE:
		return;
		break;
	case COLORMODE_MATERIAL:
		col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR);
		break;
	case COLORMODE_CUTOUT:
		col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_BACK_COLOR);
		break;
	case COLORMODE_HIGHLIGHT:
		col.setRgb(255, 157, 81, 128);
		break;
	case COLORMODE_BACKGROUND:
    col.setRgb(180, 180, 180, 128);
		break;
	case COLORMODE_MATERIAL_EDGES:
		col.setRgb(255, 236, 94);
		break;
	case COLORMODE_CUTOUT_EDGES:
		col.setRgb(171, 216, 86);
		break;
	case COLORMODE_HIGHLIGHT_EDGES:
		col.setRgb(255, 171, 86, 128);
		break;
	case COLORMODE_BACKGROUND_EDGES:
		col.setRgb(150, 150, 150, 128);
		break;
	default:
		return;
		break;
	}
	float rgba[4];
	rgba[0] = col[0];
	rgba[1] = col[1];
	rgba[2] = col[2];
	rgba[3] = col[3];
	glColor4fv(rgba);
#ifdef ENABLE_OPENCSG
	if (shaderinfo) {
		glUniform4f(shaderinfo[1], col[0], col[1], col[2], 1.0f);
		glUniform4f(shaderinfo[2], (col[0]+1)/2, (col[1]+1)/2, (col[2]+1)/2, 1.0f);
	}
#endif
}
contact: Jan Huwald // Impressum