︙ | | | ︙ | |
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
v.x = v1; \
v.y = v2; \
v.z = v3; \
v.r = ls->r; \
v.g = ls->g; \
v.b = ls->b; \
v.a = 255; \
};
#define vert(v1, v2, v3, ls, t1, t2) \
{ \
vertf((float)(v1), (float)(v2), (float)(v3), ls, t1, t2); \
}
int nquads;
|
<
>
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
v.x = v1; \
v.y = v2; \
v.z = v3; \
v.r = ls->r; \
v.g = ls->g; \
v.b = ls->b; \
v.a = 255; \
}
#define vert(v1, v2, v3, ls, t1, t2) \
{ \
vertf((float)(v1), (float)(v2), (float)(v3), ls, t1, t2); \
}
int nquads;
|
︙ | | | ︙ | |
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
|
}
#define stripend() \
{ \
if (floorstrip || deltastrip) { \
addstrip(ogltex, firstindex, curvert - firstindex); \
floorstrip = deltastrip = false; \
}; \
};
void
finishstrips()
{
stripend();
}
sqr sbright, sdark;
VAR(lighterror, 1, 8, 100);
void
render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3,
sqr *l4, bool isceil) // floor/ceil quads
{
vertcheck();
if (showm) {
l3 = l1 = &sbright;
l4 = l2 = &sdark;
};
int sx, sy;
int gltex = lookuptexture(wtex, &sx, &sy);
float xf = TEXTURESCALE / sx;
float yf = TEXTURESCALE / sy;
float xs = size * xf;
float ys = size * yf;
|
|
<
>
<
>
|
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
|
}
#define stripend() \
{ \
if (floorstrip || deltastrip) { \
addstrip(ogltex, firstindex, curvert - firstindex); \
floorstrip = deltastrip = false; \
} \
}
void
finishstrips()
{
stripend();
}
sqr sbright, sdark;
VAR(lighterror, 1, 8, 100);
void
render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3,
sqr *l4, bool isceil) // floor/ceil quads
{
vertcheck();
if (showm) {
l3 = l1 = &sbright;
l4 = l2 = &sdark;
}
int sx, sy;
int gltex = lookuptexture(wtex, &sx, &sy);
float xf = TEXTURESCALE / sx;
float yf = TEXTURESCALE / sy;
float xs = size * xf;
float ys = size * yf;
|
︙ | | | ︙ | |
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
floorstrip = true;
if (isceil) {
vert(x + size, h, y, l2, xo + xs, yo);
vert(x, h, y, l1, xo, yo);
} else {
vert(x, h, y, l1, xo, yo);
vert(x + size, h, y, l2, xo + xs, yo);
};
ol3r = l1->r;
ol3g = l1->g;
ol3b = l1->b;
ol4r = l2->r;
ol4g = l2->g;
ol4b = l2->b;
} else // continue strip
|
<
>
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
floorstrip = true;
if (isceil) {
vert(x + size, h, y, l2, xo + xs, yo);
vert(x, h, y, l1, xo, yo);
} else {
vert(x, h, y, l1, xo, yo);
vert(x + size, h, y, l2, xo + xs, yo);
}
ol3r = l1->r;
ol3g = l1->g;
ol3b = l1->b;
ol4r = l2->r;
ol4g = l2->g;
ol4b = l2->b;
} else // continue strip
|
︙ | | | ︙ | |
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
ol3r = p3[0];
ol3g = p3[1];
ol3b = p3[2];
uchar *p4 = (uchar *)(&verts[curvert - 2].r);
ol4r = p4[0];
ol4g = p4[1];
ol4b = p4[2];
};
};
if (isceil) {
vert(x + size, h, y + size, l3, xo + xs, yo + ys);
vert(x, h, y + size, l4, xo, yo + ys);
} else {
vert(x, h, y + size, l4, xo, yo + ys);
vert(x + size, h, y + size, l3, xo + xs, yo + ys);
};
oy = y;
nquads++;
}
void
render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3,
float h4, sqr *l1, sqr *l2, sqr *l3, sqr *l4,
bool isceil) // floor/ceil quads on a slope
{
vertcheck();
if (showm) {
l3 = l1 = &sbright;
l4 = l2 = &sdark;
};
int sx, sy;
int gltex = lookuptexture(wtex, &sx, &sy);
float xf = TEXTURESCALE / sx;
float yf = TEXTURESCALE / sy;
float xs = size * xf;
float ys = size * yf;
|
<
<
>
>
<
>
<
>
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
ol3r = p3[0];
ol3g = p3[1];
ol3b = p3[2];
uchar *p4 = (uchar *)(&verts[curvert - 2].r);
ol4r = p4[0];
ol4g = p4[1];
ol4b = p4[2];
}
}
if (isceil) {
vert(x + size, h, y + size, l3, xo + xs, yo + ys);
vert(x, h, y + size, l4, xo, yo + ys);
} else {
vert(x, h, y + size, l4, xo, yo + ys);
vert(x + size, h, y + size, l3, xo + xs, yo + ys);
}
oy = y;
nquads++;
}
void
render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3,
float h4, sqr *l1, sqr *l2, sqr *l3, sqr *l4,
bool isceil) // floor/ceil quads on a slope
{
vertcheck();
if (showm) {
l3 = l1 = &sbright;
l4 = l2 = &sdark;
}
int sx, sy;
int gltex = lookuptexture(wtex, &sx, &sy);
float xf = TEXTURESCALE / sx;
float yf = TEXTURESCALE / sy;
float xs = size * xf;
float ys = size * yf;
|
︙ | | | ︙ | |
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
deltastrip = true;
if (isceil) {
vertf((float)x + size, h2, (float)y, l2, xo + xs, yo);
vertf((float)x, h1, (float)y, l1, xo, yo);
} else {
vertf((float)x, h1, (float)y, l1, xo, yo);
vertf((float)x + size, h2, (float)y, l2, xo + xs, yo);
};
ol3r = l1->r;
ol3g = l1->g;
ol3b = l1->b;
ol4r = l2->r;
ol4g = l2->g;
ol4b = l2->b;
};
if (isceil) {
vertf(
(float)x + size, h3, (float)y + size, l3, xo + xs, yo + ys);
vertf((float)x, h4, (float)y + size, l4, xo, yo + ys);
} else {
vertf((float)x, h4, (float)y + size, l4, xo, yo + ys);
vertf(
(float)x + size, h3, (float)y + size, l3, xo + xs, yo + ys);
};
oy = y;
nquads++;
}
void
render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3,
|
<
>
<
>
<
>
|
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
deltastrip = true;
if (isceil) {
vertf((float)x + size, h2, (float)y, l2, xo + xs, yo);
vertf((float)x, h1, (float)y, l1, xo, yo);
} else {
vertf((float)x, h1, (float)y, l1, xo, yo);
vertf((float)x + size, h2, (float)y, l2, xo + xs, yo);
}
ol3r = l1->r;
ol3g = l1->g;
ol3b = l1->b;
ol4r = l2->r;
ol4g = l2->g;
ol4b = l2->b;
}
if (isceil) {
vertf(
(float)x + size, h3, (float)y + size, l3, xo + xs, yo + ys);
vertf((float)x, h4, (float)y + size, l4, xo, yo + ys);
} else {
vertf((float)x, h4, (float)y + size, l4, xo, yo + ys);
vertf(
(float)x + size, h3, (float)y + size, l3, xo + xs, yo + ys);
}
oy = y;
nquads++;
}
void
render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3,
|
︙ | | | ︙ | |
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
} else {
if (h1)
render_2tris(
h1, s, x, y, x + size, y, x, y + size, s, t, u);
if (h2)
render_2tris(h2, s, x + size, y, x + size, y + size, x,
y + size, t, u, v);
};
}
void
render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2,
int x1, int y1, int x2, int y2, int size, sqr *l1, sqr *l2,
bool flip) // wall quads
{
stripend();
vertcheck();
if (showm) {
l1 = &sbright;
l2 = &sdark;
};
int sx, sy;
int gltex = lookuptexture(wtex, &sx, &sy);
float xf = TEXTURESCALE / sx;
float yf = TEXTURESCALE / sy;
float xs = size * xf;
float xo = xf * (x1 == x2 ? min(y1, y2) : min(x1, x2));
if (!flip) {
vertf((float)x2, ceil2, (float)y2, l2, xo + xs, -yf * ceil2);
vertf((float)x1, ceil1, (float)y1, l1, xo, -yf * ceil1);
vertf((float)x2, floor2, (float)y2, l2, xo + xs, -floor2 * yf);
vertf((float)x1, floor1, (float)y1, l1, xo, -floor1 * yf);
} else {
vertf((float)x1, ceil1, (float)y1, l1, xo, -yf * ceil1);
vertf((float)x2, ceil2, (float)y2, l2, xo + xs, -yf * ceil2);
vertf((float)x1, floor1, (float)y1, l1, xo, -floor1 * yf);
vertf((float)x2, floor2, (float)y2, l2, xo + xs, -floor2 * yf);
};
nquads++;
addstrip(gltex, curvert - 4, 4);
}
int wx1, wy1, wx2, wy2;
|
<
>
<
>
<
>
|
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
} else {
if (h1)
render_2tris(
h1, s, x, y, x + size, y, x, y + size, s, t, u);
if (h2)
render_2tris(h2, s, x + size, y, x + size, y + size, x,
y + size, t, u, v);
}
}
void
render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2,
int x1, int y1, int x2, int y2, int size, sqr *l1, sqr *l2,
bool flip) // wall quads
{
stripend();
vertcheck();
if (showm) {
l1 = &sbright;
l2 = &sdark;
}
int sx, sy;
int gltex = lookuptexture(wtex, &sx, &sy);
float xf = TEXTURESCALE / sx;
float yf = TEXTURESCALE / sy;
float xs = size * xf;
float xo = xf * (x1 == x2 ? min(y1, y2) : min(x1, x2));
if (!flip) {
vertf((float)x2, ceil2, (float)y2, l2, xo + xs, -yf * ceil2);
vertf((float)x1, ceil1, (float)y1, l1, xo, -yf * ceil1);
vertf((float)x2, floor2, (float)y2, l2, xo + xs, -floor2 * yf);
vertf((float)x1, floor1, (float)y1, l1, xo, -floor1 * yf);
} else {
vertf((float)x1, ceil1, (float)y1, l1, xo, -yf * ceil1);
vertf((float)x2, ceil2, (float)y2, l2, xo + xs, -yf * ceil2);
vertf((float)x1, floor1, (float)y1, l1, xo, -floor1 * yf);
vertf((float)x2, floor2, (float)y2, l2, xo + xs, -floor2 * yf);
}
nquads++;
addstrip(gltex, curvert - 4, 4);
}
int wx1, wy1, wx2, wy2;
|
︙ | | | ︙ | |
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
for (int yy = wy1; yy < wy2; yy += watersubdiv) {
float xo = xf * (xx + t2);
float yo = yf * (yy + t2);
if (yy == wy1) {
vertw(xx, hf, yy, &dl, dx(xo), dy(yo), t1);
vertw(xx + watersubdiv, hf, yy, &dl,
dx(xo + xs), dy(yo), t1);
};
vertw(xx, hf, yy + watersubdiv, &dl, dx(xo),
dy(yo + ys), t1);
vertw(xx + watersubdiv, hf, yy + watersubdiv, &dl,
dx(xo + xs), dy(yo + ys), t1);
};
int n = (wy2 - wy1 - 1) / watersubdiv;
nquads += n;
n = (n + 2) * 2;
glDrawArrays(GL_TRIANGLE_STRIP, curvert -= n, n);
};
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
return nquads;
}
|
<
>
<
>
<
>
|
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
for (int yy = wy1; yy < wy2; yy += watersubdiv) {
float xo = xf * (xx + t2);
float yo = yf * (yy + t2);
if (yy == wy1) {
vertw(xx, hf, yy, &dl, dx(xo), dy(yo), t1);
vertw(xx + watersubdiv, hf, yy, &dl,
dx(xo + xs), dy(yo), t1);
}
vertw(xx, hf, yy + watersubdiv, &dl, dx(xo),
dy(yo + ys), t1);
vertw(xx + watersubdiv, hf, yy + watersubdiv, &dl,
dx(xo + xs), dy(yo + ys), t1);
}
int n = (wy2 - wy1 - 1) / watersubdiv;
nquads += n;
n = (n + 2) * 2;
glDrawArrays(GL_TRIANGLE_STRIP, curvert -= n, n);
}
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
return nquads;
}
|
︙ | | | ︙ | |
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
wx1 = x;
if (y < wy1)
wy1 = y;
if (x2 > wx2)
wx2 = x2;
if (y2 > wy2)
wy2 = y2;
};
}
void
resetcubes()
{
if (!verts)
reallocv();
floorstrip = deltastrip = false;
wx1 = -1;
nquads = 0;
sbright.r = sbright.g = sbright.b = 255;
sdark.r = sdark.g = sdark.b = 0;
}
|
<
>
|
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
wx1 = x;
if (y < wy1)
wy1 = y;
if (x2 > wx2)
wx2 = x2;
if (y2 > wy2)
wy2 = y2;
}
}
void
resetcubes()
{
if (!verts)
reallocv();
floorstrip = deltastrip = false;
wx1 = -1;
nquads = 0;
sbright.r = sbright.g = sbright.b = 255;
sdark.r = sdark.g = sdark.b = 0;
}
|