-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmulticam.c
More file actions
143 lines (120 loc) · 3.18 KB
/
Copy pathmulticam.c
File metadata and controls
143 lines (120 loc) · 3.18 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// multicam.c: multiple cameras using the same framebuffer example
// owo
#include <float.h>
#include <time.h>
#include <stdio.h>
#include <math.h>
#include <plush/plush.h>
#include "ex.h"
pl_Light *light;
pl_Obj *teapot;
pl_Mat *material;
pl_Cam *cameras[4];
uint8_t framebuffer[W * H];
float zbuffer[W * H];
uint8_t palette[768];
int main(int argc, char **argv)
{
int i;
/* setup graphics mode */
exSetGraphics();
/* create material */
/* these ambient/diffuse/specular values are taken from Haiku's GLTeapot */
material = plMatCreate();
material->NumGradients = 50;
material->ShadeType = PL_SHADE_GOURAUD;
material->Ambient[0] = 0.1745 * 255;
material->Ambient[1] = 0.03175 * 255;
material->Ambient[2] = 0.03175 * 255;
material->Diffuse[0] = 0.61424 * 255;
material->Diffuse[1] = 0.10136 * 255;
material->Diffuse[2] = 0.10136 * 255;
material->Specular[0] = 0.727811 * 255;
material->Specular[1] = 0.626959 * 255;
material->Specular[2] = 0.626959 * 255;
plMatInit(material);
/* create palette */
plMatMakeOptPal(palette, 1, 255, &material, 1);
palette[0] = palette[1] = palette[2] = 0;
plMatMapToPal(material, palette, 0, 255);
exSetPalette(palette);
/* load fork model */
teapot = plObjCreate(NULL);
teapot->Model = plReadWavefrontMdl("teapot.obj", material);
plMdlScale(teapot->Model, 32);
plMdlTranslate(teapot->Model, 0, -32, 0);
/* create cameras */
for (i = 0; i < 4; i++)
{
cameras[i] = plCamCreate(W, H, W * 3.0 / (H * 4.0), 90.0, framebuffer, zbuffer);
cameras[i]->Z = -300;
switch (i)
{
case 0:
cameras[i]->CenterX = W / 4;
cameras[i]->CenterY = H / 4;
cameras[i]->ClipTop = 0;
cameras[i]->ClipLeft = 0;
cameras[i]->ClipBottom = H / 2;
cameras[i]->ClipRight = W / 2;
break;
case 1:
cameras[i]->CenterX = (W / 4) * 3;
cameras[i]->CenterY = H / 4;
cameras[i]->ClipTop = 0;
cameras[i]->ClipLeft = W / 2;
cameras[i]->ClipBottom = H / 2;
cameras[i]->ClipRight = W;
break;
case 2:
cameras[i]->CenterX = W / 4;
cameras[i]->CenterY = (H / 4) * 3;
cameras[i]->ClipTop = H / 2;
cameras[i]->ClipLeft = 0;
cameras[i]->ClipBottom = H;
cameras[i]->ClipRight = W / 2;
break;
case 3:
cameras[i]->CenterX = (W / 4) * 3;
cameras[i]->CenterY = (H / 4) * 3;
cameras[i]->ClipTop = H / 2;
cameras[i]->ClipLeft = W / 2;
cameras[i]->ClipBottom = H;
cameras[i]->ClipRight = W;
break;
}
}
/* create light */
light = plLightSet(plLightCreate(), PL_LIGHT_VECTOR, 0.0, 0.0, 0.0, 1.0, 1.0);
/* main loop */
while (!exGetKey())
{
/* rotate model */
teapot->Xa += 1.0;
teapot->Ya += 1.0;
teapot->Za += 1.0;
/* clear back buffer */
memset(zbuffer, 0, sizeof(zbuffer));
memset(framebuffer, 0, sizeof(framebuffer));
/* render frame */
for (i = 0; i < 4; i++)
{
plRenderBegin(cameras[i]);
plRenderLight(light);
plRenderObj(teapot);
plRenderEnd();
}
/* wait for vsync, then copy to screen */
exWaitVSync();
memcpy(exGraphMem, framebuffer, sizeof(framebuffer));
}
/* clean up */
for (i = 0; i < 4; i++)
plCamDelete(cameras[i]);
plLightDelete(light);
plObjDelete(teapot);
plMatDelete(material);
/* shut down video */
exSetText();
return 0;
}