ccdemos/textures.cc
author Radek Brich <radek.brich@devl.cz>
Thu, 24 Apr 2008 18:12:32 +0200
branchpyrit
changeset 83 e3a2a5b26abb
parent 81 9dbb9c8c115b
child 88 f7edb3b90816
permissions -rw-r--r--
vectorize makeRayPacket() using SSE intrinsics
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#include "raytracer.h"
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
#include "octree.h"
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
#include "image.h"
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
#include "common_sdl.h"
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
     7
Camera cam(Vector3(0.,6.,6.), Vector3(0.,2.,-7.), Vector3(0.,0.,-1.));
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
Light light(Vector3(-2.0, 10.0, -2.0), Colour(0.9, 0.9, 0.9));
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
Float lx, ly, lz, cf;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
81
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 79
diff changeset
    12
void update_callback(Float*)
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
{
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
	if (lx != 0.0)
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
		light.pos.x += lx;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
	if (ly != 0.0)
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
		light.pos.y += ly;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
	if (lz != 0.0)
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
		light.pos.z += lz;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
	if (cf != 0.0)
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    21
		cam.F += cf;
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
}
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
void key_callback(int key, int down)
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
{
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
	switch (key)
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
	{
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
		case SDLK_r:
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
			lx = -0.1 * down;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
			break;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
		case SDLK_t:
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
			lx = +0.1 * down;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
			break;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
		case SDLK_f:
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
			ly = -0.1 * down;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
			break;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
		case SDLK_g:
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
			ly = +0.1 * down;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
			break;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
		case SDLK_v:
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
			lz = -0.1 * down;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
			break;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
		case SDLK_b:
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
			lz = +0.1 * down;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
			break;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
		case SDLK_z:
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
			cf = -0.02 * down;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
			break;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
		case SDLK_x:
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
			cf = +0.02 * down;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
			break;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
	}
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
}
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
int main(int argc, char **argv)
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
{
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
	Raytracer rt;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
	Octree top;
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    61
	rt.setCamera(&cam);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
	rt.setTop(&top);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    63
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    64
	rt.addLight(&light);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
	light.castShadows(false);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    66
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    67
	Material mat0a(Colour(0.7, 0.7, 0.7));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    68
	mat0a.setReflectivity(0.0);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    69
	Box box(Vector3(-12.0, -1.2, -20.0), Vector3(12.0, -1.0, 0.0), &mat0a);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    70
	rt.addShape(&box);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
	Material mat0b(Colour(0.1, 0.7, 0.8));
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    73
	mat0b.setReflectivity(0.7);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    74
	Box box2(Vector3(-12.0, -1.2, -10.0), Vector3(12.0, 10.0, -10.2), &mat0b);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    75
	rt.addShape(&box2);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    76
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    77
	Float bounds[] = {0.3, 0.6, 1.1};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    78
	Colour colours[] = {Colour(0,0,0), Colour(1,1,1), Colour(0,0,0)};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    79
	BoundColourMap cmap(bounds, colours);
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    80
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    81
	// spheres
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    82
	Material mat1(Colour(1.0, 1.0, 1.0));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    83
	mat1.texture = new CheckersTexture(new PlanarMap(Vector3(-4.5, 2.0, -7.0), 0.48), &cmap);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    84
	Sphere sphere1(Vector3(-4.5, 2.0, -7.0), 1.0, &mat1);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    85
	rt.addShape(&sphere1);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    86
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    87
	Material mat2(Colour(1.0, 1.0, 1.0));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    88
	mat2.texture = new CheckersTexture(new CubicMap(Vector3(-1.5, 2.0, -7.0), 0.48), &cmap);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    89
	Sphere sphere2(Vector3(-1.5, 2.0, -7.0), 1.0, &mat2);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    90
	rt.addShape(&sphere2);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    91
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    92
	Material mat3(Colour(1.0, 1.0, 1.0));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    93
	mat3.texture = new CheckersTexture(new CylinderMap(Vector3(1.5, 2.0, -7.0), 0.48), &cmap);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    94
	Sphere sphere3(Vector3(1.5, 2.0, -7.0), 1.0, &mat3);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    95
	rt.addShape(&sphere3);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    96
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    97
	Material mat4(Colour(1.0, 1.0, 1.0));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    98
	mat4.texture = new CheckersTexture(new SphereMap(Vector3(4.5, 2.0, -7.0), 0.48), &cmap);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    99
	Sphere sphere4(Vector3(4.5, 2.0, -7.0), 1.0, &mat4);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   100
	rt.addShape(&sphere4);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   101
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   102
	// cubes
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   103
	Material mat5(Colour(1.0, 1.0, 1.0));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   104
	mat5.texture = new CheckersTexture(new PlanarMap(Vector3(-4.5, 0.0, -7.0), 0.48), &cmap);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   105
	Box cube1(Vector3(-4.5, 0.0, -7.0)-1.0, Vector3(-4.5, 0.0, -7.0)+1.0, &mat5);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   106
	rt.addShape(&cube1);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   107
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   108
	Material mat6(Colour(1.0, 1.0, 1.0));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   109
	mat6.texture = new CheckersTexture(new CubicMap(Vector3(-1.5, 0.0, -7.0), 0.48), &cmap);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   110
	Box cube2(Vector3(-1.5, 0.0, -7.0)-1.0, Vector3(-1.5, 0.0, -7.0)+1.0, &mat6);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   111
	rt.addShape(&cube2);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   112
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   113
	Material mat7(Colour(1.0, 1.0, 1.0));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   114
	mat7.texture = new CheckersTexture(new CylinderMap(Vector3(1.5, 0.0, -7.0), 0.48), &cmap);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   115
	Box cube3(Vector3(1.5, 0.0, -7.0)-1.0, Vector3(1.5, 0.0, -7.0)+1.0, &mat7);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   116
	rt.addShape(&cube3);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   118
	Material mat8(Colour(1.0, 1.0, 1.0));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   119
	mat8.texture = new CheckersTexture(new SphereMap(Vector3(4.5, 0.0, -7.0), 0.48), &cmap);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   120
	Box cube4(Vector3(4.5, 0.0, -7.0)-1.0, Vector3(4.5, 0.0, -7.0)+1.0, &mat8);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   121
	rt.addShape(&cube4);
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   122
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   123
	mat1.setReflectivity(0);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   124
	mat2.setReflectivity(0);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   125
	mat3.setReflectivity(0);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   126
	mat4.setReflectivity(0);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   127
	mat5.setReflectivity(0);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   128
	mat6.setReflectivity(0);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   129
	mat7.setReflectivity(0);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   130
	mat8.setReflectivity(0);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   131
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   132
	top.optimize();
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   133
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   134
	w = 1024;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   135
	h = 600;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   136
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   137
	/* run interactive mode */
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   138
	loop_sdl(rt, cam, update_callback, key_callback);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   139
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   140
	/* render image */
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   141
	if (argc == 2 && !strcmp(argv[1], "-r"))
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   142
	{
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   143
		pyrit_verbosity = 2;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   144
		Float *fdata = (Float *) malloc(w*h*3*sizeof(Float));
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   145
		rt.ambientOcclusion(300, 5.0, 0.5);
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 43
diff changeset
   146
		DefaultSampler sampler(fdata, w, h);
48
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   147
		sampler.setOversample(2);
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   148
		sampler.setSubsample(1);
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 43
diff changeset
   149
		rt.setSampler(&sampler);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 43
diff changeset
   150
		rt.render();
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   151
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   152
		struct image *img;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   153
		new_image(&img, w, h, 3);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   154
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   155
		Float *fd = fdata;
60
a23b5089b9c3 moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   156
		for (unsigned char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) {
42
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   157
			if (*fd > 1.0)
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   158
				*cd = 255;
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   159
			else
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   160
				*cd = (unsigned char)(*fd * 255.0);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   161
		}
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   162
		free(fdata);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   163
		save_png("textures.png", img);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   164
		destroy_image(&img);
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   165
	}
fbdeb3e04543 cleaned Texture interface
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   166
}