mirror of
https://git.code.sf.net/p/quake/quakeforge-old
synced 2025-02-20 18:42:34 +00:00
Fixed gl_doubleeyes and made it common, whitesize cleanup to gl_warp.c
This commit is contained in:
parent
9a6d5d1f70
commit
092d32cd23
2 changed files with 201 additions and 276 deletions
472
common/gl_warp.c
472
common/gl_warp.c
|
@ -1,26 +1,31 @@
|
|||
/*
|
||||
Copyright (C) 1996-1997 Id Software, Inc.
|
||||
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
||||
gl_warp.c
|
||||
|
||||
Sky and water polygons
|
||||
|
||||
Copyright (C) 1996-1997 Id Software, Inc.
|
||||
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
||||
Please see the file "AUTHORS" for a list of contributors
|
||||
Portions Copyright (C) 1999,2000 Nelson Rush.
|
||||
Please see the file "AUTHORS" for a list of contributors
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
*/
|
||||
// gl_warp.c -- sky and water polygons
|
||||
|
||||
#include "quakedef.h"
|
||||
|
||||
|
@ -36,8 +41,12 @@ msurface_t *warpface;
|
|||
|
||||
extern cvar_t gl_subdivide_size;
|
||||
|
||||
void BoundPoly (int numverts, float *verts, vec3_t mins, vec3_t maxs)
|
||||
{
|
||||
/*
|
||||
BoundPoly (int, float, vec3_t, vec3_t)
|
||||
*/
|
||||
void
|
||||
BoundPoly (int numverts, float *verts, vec3_t mins, vec3_t maxs) {
|
||||
|
||||
int i, j;
|
||||
float *v;
|
||||
|
||||
|
@ -45,8 +54,7 @@ void BoundPoly (int numverts, float *verts, vec3_t mins, vec3_t maxs)
|
|||
maxs[0] = maxs[1] = maxs[2] = -9999;
|
||||
v = verts;
|
||||
for (i=0 ; i<numverts ; i++)
|
||||
for (j=0 ; j<3 ; j++, v++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++, v++) {
|
||||
if (*v < mins[j])
|
||||
mins[j] = *v;
|
||||
if (*v > maxs[j])
|
||||
|
@ -54,8 +62,9 @@ void BoundPoly (int numverts, float *verts, vec3_t mins, vec3_t maxs)
|
|||
}
|
||||
}
|
||||
|
||||
void SubdividePolygon (int numverts, float *verts)
|
||||
{
|
||||
void
|
||||
SubdividePolygon ( int numverts, float *verts ) {
|
||||
|
||||
int i, j, k;
|
||||
vec3_t mins, maxs;
|
||||
float m;
|
||||
|
@ -72,8 +81,7 @@ void SubdividePolygon (int numverts, float *verts)
|
|||
|
||||
BoundPoly (numverts, verts, mins, maxs);
|
||||
|
||||
for (i=0 ; i<3 ; i++)
|
||||
{
|
||||
for (i=0 ; i<3 ; i++) {
|
||||
m = (mins[i] + maxs[i]) * 0.5;
|
||||
m = gl_subdivide_size.value * floor (m/gl_subdivide_size.value + 0.5);
|
||||
if (maxs[i] - m < 8)
|
||||
|
@ -93,22 +101,18 @@ void SubdividePolygon (int numverts, float *verts)
|
|||
|
||||
f = b = 0;
|
||||
v = verts;
|
||||
for (j=0 ; j<numverts ; j++, v+= 3)
|
||||
{
|
||||
if (dist[j] >= 0)
|
||||
{
|
||||
for (j=0 ; j<numverts ; j++, v+= 3) {
|
||||
if (dist[j] >= 0) {
|
||||
VectorCopy (v, front[f]);
|
||||
f++;
|
||||
}
|
||||
if (dist[j] <= 0)
|
||||
{
|
||||
if (dist[j] <= 0) {
|
||||
VectorCopy (v, back[b]);
|
||||
b++;
|
||||
}
|
||||
if (dist[j] == 0 || dist[j+1] == 0)
|
||||
continue;
|
||||
if ( (dist[j] > 0) != (dist[j+1] > 0) )
|
||||
{
|
||||
if ( (dist[j] > 0) != (dist[j+1] > 0) ) {
|
||||
// clip point
|
||||
frac = dist[j] / (dist[j] - dist[j+1]);
|
||||
for (k=0 ; k<3 ; k++)
|
||||
|
@ -127,8 +131,7 @@ void SubdividePolygon (int numverts, float *verts)
|
|||
poly->next = warpface->polys;
|
||||
warpface->polys = poly;
|
||||
poly->numverts = numverts;
|
||||
for (i=0 ; i<numverts ; i++, verts+= 3)
|
||||
{
|
||||
for (i=0 ; i<numverts ; i++, verts+= 3) {
|
||||
VectorCopy (verts, poly->verts[i]);
|
||||
s = DotProduct (verts, warpface->texinfo->vecs[0]);
|
||||
t = DotProduct (verts, warpface->texinfo->vecs[1]);
|
||||
|
@ -138,16 +141,14 @@ void SubdividePolygon (int numverts, float *verts)
|
|||
}
|
||||
|
||||
/*
|
||||
================
|
||||
GL_SubdivideSurface
|
||||
GL_SubdivideSurface
|
||||
|
||||
Breaks a polygon up along axial 64 unit
|
||||
boundaries so that turbulent and sky warps
|
||||
can be done reasonably.
|
||||
================
|
||||
Break a polygon up along axial 64 unit boundaries so that turbulent
|
||||
and sky warps can be done reasonably.
|
||||
*/
|
||||
void GL_SubdivideSurface (msurface_t *fa)
|
||||
{
|
||||
void
|
||||
GL_SubdivideSurface (msurface_t *fa) {
|
||||
|
||||
vec3_t verts[64];
|
||||
int numverts;
|
||||
int i;
|
||||
|
@ -156,12 +157,11 @@ void GL_SubdivideSurface (msurface_t *fa)
|
|||
|
||||
warpface = fa;
|
||||
|
||||
//
|
||||
// convert edges back to a normal polygon
|
||||
//
|
||||
/*
|
||||
convert edges back to a normal polygon
|
||||
*/
|
||||
numverts = 0;
|
||||
for (i=0 ; i<fa->numedges ; i++)
|
||||
{
|
||||
for (i=0 ; i<fa->numedges ; i++) {
|
||||
lindex = loadmodel->surfedges[fa->firstedge + i];
|
||||
|
||||
if (lindex > 0)
|
||||
|
@ -180,32 +180,28 @@ void GL_SubdivideSurface (msurface_t *fa)
|
|||
|
||||
|
||||
// speed up sin calculations - Ed
|
||||
float turbsin[] =
|
||||
{
|
||||
float turbsin[] = {
|
||||
#include "gl_warp_sin.h"
|
||||
};
|
||||
|
||||
#define TURBSCALE (256.0 / (2 * M_PI))
|
||||
|
||||
/*
|
||||
=============
|
||||
EmitWaterPolys
|
||||
EmitWaterPolys
|
||||
|
||||
Does a water warp on the pre-fragmented glpoly_t chain
|
||||
=============
|
||||
Do a water warp on the pre-fragmented glpoly_t chain
|
||||
*/
|
||||
void EmitWaterPolys (msurface_t *fa)
|
||||
{
|
||||
void
|
||||
EmitWaterPolys ( msurface_t *fa ) {
|
||||
|
||||
glpoly_t *p;
|
||||
float *v;
|
||||
int i;
|
||||
float s, t, os, ot;
|
||||
|
||||
|
||||
for (p=fa->polys ; p ; p=p->next)
|
||||
{
|
||||
for (p=fa->polys ; p ; p=p->next) {
|
||||
glBegin (GL_POLYGON);
|
||||
for (i=0,v=p->verts[0] ; i<p->numverts ; i++, v+=VERTEXSIZE)
|
||||
{
|
||||
for (i=0,v=p->verts[0] ; i<p->numverts ; i++, v+=VERTEXSIZE) {
|
||||
os = v[3];
|
||||
ot = v[4];
|
||||
|
||||
|
@ -222,16 +218,12 @@ void EmitWaterPolys (msurface_t *fa)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
EmitSkyPolys
|
||||
=============
|
||||
EmitSkyPolys
|
||||
*/
|
||||
void EmitSkyPolys (msurface_t *fa)
|
||||
{
|
||||
void
|
||||
EmitSkyPolys ( msurface_t *fa ) {
|
||||
|
||||
glpoly_t *p;
|
||||
float *v;
|
||||
int i;
|
||||
|
@ -265,16 +257,13 @@ void EmitSkyPolys (msurface_t *fa)
|
|||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
EmitBothSkyLayers
|
||||
EmitBothSkyLayers
|
||||
|
||||
Does a sky warp on the pre-fragmented glpoly_t chain
|
||||
This will be called for brushmodels, the world
|
||||
will have them chained together.
|
||||
===============
|
||||
Do a sky warp on the pre-fragmented glpoly_t chain. This will be
|
||||
called for brushmodels, the world will have them chained together.
|
||||
*/
|
||||
void EmitBothSkyLayers (msurface_t *fa)
|
||||
{
|
||||
void
|
||||
EmitBothSkyLayers ( msurface_t *fa ) {
|
||||
GL_DisableMultitexture();
|
||||
|
||||
GL_Bind (solidskytexture);
|
||||
|
@ -293,14 +282,12 @@ void EmitBothSkyLayers (msurface_t *fa)
|
|||
glDisable (GL_BLEND);
|
||||
}
|
||||
|
||||
#ifndef QUAKE2
|
||||
/*
|
||||
=================
|
||||
R_DrawSkyChain
|
||||
=================
|
||||
R_DrawSkyChain
|
||||
*/
|
||||
void R_DrawSkyChain (msurface_t *s)
|
||||
{
|
||||
void
|
||||
R_DrawSkyChain ( msurface_t *s ) {
|
||||
|
||||
msurface_t *fa;
|
||||
|
||||
GL_DisableMultitexture();
|
||||
|
@ -324,31 +311,19 @@ void R_DrawSkyChain (msurface_t *s)
|
|||
glDisable (GL_BLEND);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
=================================================================
|
||||
|
||||
Quake 2 environment sky
|
||||
|
||||
=================================================================
|
||||
Quake 2 sky rendering ("skyboxes")
|
||||
*/
|
||||
|
||||
#ifdef QUAKE2
|
||||
|
||||
|
||||
#define SKY_TEX 2000
|
||||
|
||||
/*
|
||||
=================================================================
|
||||
|
||||
PCX Loading
|
||||
|
||||
=================================================================
|
||||
PCX Loading
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
char manufacturer;
|
||||
char version;
|
||||
char encoding;
|
||||
|
@ -367,12 +342,11 @@ typedef struct
|
|||
byte *pcx_rgb;
|
||||
|
||||
/*
|
||||
============
|
||||
LoadPCX
|
||||
============
|
||||
LoadPCX
|
||||
*/
|
||||
void LoadPCX (FILE *f)
|
||||
{
|
||||
void
|
||||
LoadPCX (FILE *f) {
|
||||
|
||||
pcx_t *pcx, pcxbuf;
|
||||
byte palette[768];
|
||||
byte *pix;
|
||||
|
@ -380,21 +354,17 @@ void LoadPCX (FILE *f)
|
|||
int dataByte, runLength;
|
||||
int count;
|
||||
|
||||
//
|
||||
// parse the PCX file
|
||||
//
|
||||
/*
|
||||
Parse PCX file
|
||||
*/
|
||||
fread (&pcxbuf, 1, sizeof(pcxbuf), f);
|
||||
|
||||
pcx = &pcxbuf;
|
||||
|
||||
if (pcx->manufacturer != 0x0a
|
||||
|| pcx->version != 5
|
||||
|| pcx->encoding != 1
|
||||
|| pcx->bits_per_pixel != 8
|
||||
|| pcx->xmax >= 320
|
||||
|| pcx->ymax >= 256)
|
||||
{
|
||||
Con_Printf ("Bad pcx file\n");
|
||||
if (pcx->manufacturer != 0x0a || pcx->version != 5 || pcx->encoding != 1
|
||||
|| pcx->bits_per_pixel != 8 || pcx->xmax >= 320
|
||||
|| pcx->ymax >= 256) {
|
||||
Con_Printf ("Bad PCX file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -407,23 +377,19 @@ void LoadPCX (FILE *f)
|
|||
count = (pcx->xmax+1) * (pcx->ymax+1);
|
||||
pcx_rgb = malloc( count * 4);
|
||||
|
||||
for (y=0 ; y<=pcx->ymax ; y++)
|
||||
{
|
||||
for (y=0 ; y<=pcx->ymax ; y++) {
|
||||
pix = pcx_rgb + 4*y*(pcx->xmax+1);
|
||||
for (x=0 ; x<=pcx->ymax ; )
|
||||
{
|
||||
for (x=0 ; x<=pcx->ymax ; ) {
|
||||
dataByte = fgetc(f);
|
||||
|
||||
if((dataByte & 0xC0) == 0xC0)
|
||||
{
|
||||
if((dataByte & 0xC0) == 0xC0) {
|
||||
runLength = dataByte & 0x3F;
|
||||
dataByte = fgetc(f);
|
||||
}
|
||||
else
|
||||
runLength = 1;
|
||||
|
||||
while(runLength-- > 0)
|
||||
{
|
||||
while(runLength-- > 0) {
|
||||
pix[0] = palette[dataByte*3];
|
||||
pix[1] = palette[dataByte*3+1];
|
||||
pix[2] = palette[dataByte*3+2];
|
||||
|
@ -436,11 +402,7 @@ void LoadPCX (FILE *f)
|
|||
}
|
||||
|
||||
/*
|
||||
=========================================================
|
||||
|
||||
TARGA LOADING
|
||||
|
||||
=========================================================
|
||||
TARGA LOADING
|
||||
*/
|
||||
|
||||
typedef struct _TargaHeader {
|
||||
|
@ -451,12 +413,12 @@ typedef struct _TargaHeader {
|
|||
unsigned char pixel_size, attributes;
|
||||
} TargaHeader;
|
||||
|
||||
|
||||
TargaHeader targa_header;
|
||||
byte *targa_rgba;
|
||||
|
||||
int fgetLittleShort (FILE *f)
|
||||
{
|
||||
int
|
||||
fgetLittleShort ( FILE *f ) {
|
||||
|
||||
byte b1, b2;
|
||||
|
||||
b1 = fgetc(f);
|
||||
|
@ -465,8 +427,9 @@ int fgetLittleShort (FILE *f)
|
|||
return (short)(b1 + b2*256);
|
||||
}
|
||||
|
||||
int fgetLittleLong (FILE *f)
|
||||
{
|
||||
int
|
||||
fgetLittleLong (FILE *f) {
|
||||
|
||||
byte b1, b2, b3, b4;
|
||||
|
||||
b1 = fgetc(f);
|
||||
|
@ -477,17 +440,15 @@ int fgetLittleLong (FILE *f)
|
|||
return b1 + (b2<<8) + (b3<<16) + (b4<<24);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
LoadTGA
|
||||
=============
|
||||
LoadTGA
|
||||
*/
|
||||
void LoadTGA (FILE *fin)
|
||||
{
|
||||
int columns, rows, numPixels;
|
||||
byte *pixbuf;
|
||||
int row, column;
|
||||
void
|
||||
LoadTGA (FILE *fin) {
|
||||
|
||||
int columns, rows, numPixels;
|
||||
byte *pixbuf;
|
||||
int row, column;
|
||||
|
||||
targa_header.id_length = fgetc(fin);
|
||||
targa_header.colormap_type = fgetc(fin);
|
||||
|
@ -503,13 +464,13 @@ void LoadTGA (FILE *fin)
|
|||
targa_header.pixel_size = fgetc(fin);
|
||||
targa_header.attributes = fgetc(fin);
|
||||
|
||||
if (targa_header.image_type!=2
|
||||
&& targa_header.image_type!=10)
|
||||
if (targa_header.image_type!=2 && targa_header.image_type!=10)
|
||||
Sys_Error ("LoadTGA: Only type 2 and 10 targa RGB images supported\n");
|
||||
|
||||
if (targa_header.colormap_type !=0
|
||||
|| (targa_header.pixel_size!=32 && targa_header.pixel_size!=24))
|
||||
if (targa_header.colormap_type !=0 ||
|
||||
(targa_header.pixel_size!=32 && targa_header.pixel_size!=24)) {
|
||||
Sys_Error ("Texture_LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");
|
||||
}
|
||||
|
||||
columns = targa_header.width;
|
||||
rows = targa_header.height;
|
||||
|
@ -627,29 +588,26 @@ void LoadTGA (FILE *fin)
|
|||
breakOut:;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fin);
|
||||
}
|
||||
|
||||
/*
|
||||
==================
|
||||
R_LoadSkys
|
||||
==================
|
||||
R_LoadSkys
|
||||
*/
|
||||
char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
|
||||
void R_LoadSkys (void)
|
||||
{
|
||||
|
||||
void
|
||||
R_LoadSkys ( void ) {
|
||||
|
||||
int i;
|
||||
FILE *f;
|
||||
char name[64];
|
||||
|
||||
for (i=0 ; i<6 ; i++)
|
||||
{
|
||||
for (i=0 ; i<6 ; i++) {
|
||||
GL_Bind (SKY_TEX + i);
|
||||
snprintf(name, sizeof(name), "gfx/env/bkgtst%s.tga", suf[i]);
|
||||
COM_FOpenFile (name, &f);
|
||||
if (!f)
|
||||
{
|
||||
if (!f) {
|
||||
Con_Printf ("Couldn't load %s\n", name);
|
||||
continue;
|
||||
}
|
||||
|
@ -679,8 +637,7 @@ vec3_t skyclip[6] = {
|
|||
int c_sky;
|
||||
|
||||
// 1 = s, 2 = t, 3 = 2048
|
||||
int st_to_vec[6][3] =
|
||||
{
|
||||
int st_to_vec[6][3] = {
|
||||
{3,-1,2},
|
||||
{-3,1,2},
|
||||
|
||||
|
@ -695,8 +652,7 @@ int st_to_vec[6][3] =
|
|||
};
|
||||
|
||||
// s = [0]/[2], t = [1]/[2]
|
||||
int vec_to_st[6][3] =
|
||||
{
|
||||
int vec_to_st[6][3] = {
|
||||
{-2,3,1},
|
||||
{2,3,-1},
|
||||
|
||||
|
@ -712,8 +668,9 @@ int vec_to_st[6][3] =
|
|||
|
||||
float skymins[2][6], skymaxs[2][6];
|
||||
|
||||
void DrawSkyPolygon (int nump, vec3_t vecs)
|
||||
{
|
||||
void
|
||||
DrawSkyPolygon (int nump, vec3_t vecs) {
|
||||
|
||||
int i,j;
|
||||
vec3_t v, av;
|
||||
float s, t, dv;
|
||||
|
@ -722,40 +679,33 @@ void DrawSkyPolygon (int nump, vec3_t vecs)
|
|||
|
||||
c_sky++;
|
||||
#if 0
|
||||
glBegin (GL_POLYGON);
|
||||
for (i=0 ; i<nump ; i++, vecs+=3)
|
||||
{
|
||||
VectorAdd(vecs, r_origin, v);
|
||||
glVertex3fv (v);
|
||||
}
|
||||
glEnd();
|
||||
return;
|
||||
glBegin (GL_POLYGON);
|
||||
for (i=0 ; i<nump ; i++, vecs+=3) {
|
||||
VectorAdd(vecs, r_origin, v);
|
||||
glVertex3fv (v);
|
||||
}
|
||||
glEnd();
|
||||
return;
|
||||
#endif
|
||||
// decide which face it maps to
|
||||
VectorCopy (vec3_origin, v);
|
||||
for (i=0, vp=vecs ; i<nump ; i++, vp+=3)
|
||||
{
|
||||
for (i=0, vp=vecs ; i<nump ; i++, vp+=3) {
|
||||
VectorAdd (vp, v, v);
|
||||
}
|
||||
av[0] = fabs(v[0]);
|
||||
av[1] = fabs(v[1]);
|
||||
av[2] = fabs(v[2]);
|
||||
if (av[0] > av[1] && av[0] > av[2])
|
||||
{
|
||||
if (av[0] > av[1] && av[0] > av[2]) {
|
||||
if (v[0] < 0)
|
||||
axis = 1;
|
||||
else
|
||||
axis = 0;
|
||||
}
|
||||
else if (av[1] > av[2] && av[1] > av[0])
|
||||
{
|
||||
} else if (av[1] > av[2] && av[1] > av[0]) {
|
||||
if (v[1] < 0)
|
||||
axis = 3;
|
||||
else
|
||||
axis = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (v[2] < 0)
|
||||
axis = 5;
|
||||
else
|
||||
|
@ -763,8 +713,7 @@ return;
|
|||
}
|
||||
|
||||
// project new texture coords
|
||||
for (i=0 ; i<nump ; i++, vecs+=3)
|
||||
{
|
||||
for (i=0 ; i<nump ; i++, vecs+=3) {
|
||||
j = vec_to_st[axis][2];
|
||||
if (j > 0)
|
||||
dv = vecs[j - 1];
|
||||
|
@ -794,8 +743,9 @@ return;
|
|||
}
|
||||
|
||||
#define MAX_CLIP_VERTS 64
|
||||
void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
||||
{
|
||||
void
|
||||
ClipSkyPolygon (int nump, vec3_t vecs, int stage) {
|
||||
|
||||
float *norm;
|
||||
float *v;
|
||||
qboolean front, back;
|
||||
|
@ -808,34 +758,27 @@ void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
|||
|
||||
if (nump > MAX_CLIP_VERTS-2)
|
||||
Sys_Error ("ClipSkyPolygon: MAX_CLIP_VERTS");
|
||||
if (stage == 6)
|
||||
{ // fully clipped, so draw it
|
||||
if (stage == 6) { // fully clipped, so draw it
|
||||
DrawSkyPolygon (nump, vecs);
|
||||
return;
|
||||
}
|
||||
|
||||
front = back = false;
|
||||
norm = skyclip[stage];
|
||||
for (i=0, v = vecs ; i<nump ; i++, v+=3)
|
||||
{
|
||||
for (i=0, v = vecs ; i<nump ; i++, v+=3) {
|
||||
d = DotProduct (v, norm);
|
||||
if (d > ON_EPSILON)
|
||||
{
|
||||
if (d > ON_EPSILON) {
|
||||
front = true;
|
||||
sides[i] = SIDE_FRONT;
|
||||
}
|
||||
else if (d < ON_EPSILON)
|
||||
{
|
||||
} else if (d < ON_EPSILON) {
|
||||
back = true;
|
||||
sides[i] = SIDE_BACK;
|
||||
}
|
||||
else
|
||||
} else
|
||||
sides[i] = SIDE_ON;
|
||||
dists[i] = d;
|
||||
}
|
||||
|
||||
if (!front || !back)
|
||||
{ // not clipped
|
||||
if (!front || !back) { // not clipped
|
||||
ClipSkyPolygon (nump, vecs, stage+1);
|
||||
return;
|
||||
}
|
||||
|
@ -846,32 +789,29 @@ void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
|||
VectorCopy (vecs, (vecs+(i*3)) );
|
||||
newc[0] = newc[1] = 0;
|
||||
|
||||
for (i=0, v = vecs ; i<nump ; i++, v+=3)
|
||||
{
|
||||
switch (sides[i])
|
||||
{
|
||||
case SIDE_FRONT:
|
||||
VectorCopy (v, newv[0][newc[0]]);
|
||||
newc[0]++;
|
||||
break;
|
||||
case SIDE_BACK:
|
||||
VectorCopy (v, newv[1][newc[1]]);
|
||||
newc[1]++;
|
||||
break;
|
||||
case SIDE_ON:
|
||||
VectorCopy (v, newv[0][newc[0]]);
|
||||
newc[0]++;
|
||||
VectorCopy (v, newv[1][newc[1]]);
|
||||
newc[1]++;
|
||||
break;
|
||||
for (i=0, v = vecs ; i<nump ; i++, v+=3) {
|
||||
switch (sides[i]) {
|
||||
case SIDE_FRONT:
|
||||
VectorCopy (v, newv[0][newc[0]]);
|
||||
newc[0]++;
|
||||
break;
|
||||
case SIDE_BACK:
|
||||
VectorCopy (v, newv[1][newc[1]]);
|
||||
newc[1]++;
|
||||
break;
|
||||
case SIDE_ON:
|
||||
VectorCopy (v, newv[0][newc[0]]);
|
||||
newc[0]++;
|
||||
VectorCopy (v, newv[1][newc[1]]);
|
||||
newc[1]++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (sides[i] == SIDE_ON || sides[i+1] == SIDE_ON || sides[i+1] == sides[i])
|
||||
continue;
|
||||
|
||||
d = dists[i] / (dists[i] - dists[i+1]);
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++) {
|
||||
e = v[j] + d*(v[j+3] - v[j]);
|
||||
newv[0][newc[0]][j] = e;
|
||||
newv[1][newc[1]][j] = e;
|
||||
|
@ -886,12 +826,11 @@ void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
|||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
R_DrawSkyChain
|
||||
=================
|
||||
R_DrawSkyChain
|
||||
*/
|
||||
void R_DrawSkyChain (msurface_t *s)
|
||||
{
|
||||
void
|
||||
R_DrawSkyChain (msurface_t *s) {
|
||||
|
||||
msurface_t *fa;
|
||||
|
||||
int i;
|
||||
|
@ -903,12 +842,9 @@ void R_DrawSkyChain (msurface_t *s)
|
|||
|
||||
// calculate vertex values for sky box
|
||||
|
||||
for (fa=s ; fa ; fa=fa->texturechain)
|
||||
{
|
||||
for (p=fa->polys ; p ; p=p->next)
|
||||
{
|
||||
for (i=0 ; i<p->numverts ; i++)
|
||||
{
|
||||
for (fa=s ; fa ; fa=fa->texturechain) {
|
||||
for (p=fa->polys ; p ; p=p->next) {
|
||||
for (i=0 ; i<p->numverts ; i++) {
|
||||
VectorSubtract (p->verts[i], r_origin, verts[i]);
|
||||
}
|
||||
ClipSkyPolygon (p->numverts, verts[0], 0);
|
||||
|
@ -916,26 +852,21 @@ void R_DrawSkyChain (msurface_t *s)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
R_ClearSkyBox
|
||||
==============
|
||||
R_ClearSkyBox
|
||||
*/
|
||||
void R_ClearSkyBox (void)
|
||||
{
|
||||
void
|
||||
R_ClearSkyBox (void) {
|
||||
int i;
|
||||
|
||||
for (i=0 ; i<6 ; i++)
|
||||
{
|
||||
for (i=0 ; i<6 ; i++) {
|
||||
skymins[0][i] = skymins[1][i] = 9999;
|
||||
skymaxs[0][i] = skymaxs[1][i] = -9999;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MakeSkyVec (float s, float t, int axis)
|
||||
{
|
||||
void
|
||||
MakeSkyVec (float s, float t, int axis) {
|
||||
vec3_t v, b;
|
||||
int j, k;
|
||||
|
||||
|
@ -943,8 +874,7 @@ void MakeSkyVec (float s, float t, int axis)
|
|||
b[1] = t*2048;
|
||||
b[2] = 2048;
|
||||
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++) {
|
||||
k = st_to_vec[axis][j];
|
||||
if (k < 0)
|
||||
v[j] = -b[-k - 1];
|
||||
|
@ -972,22 +902,22 @@ void MakeSkyVec (float s, float t, int axis)
|
|||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
R_DrawSkyBox
|
||||
==============
|
||||
R_DrawSkyBox
|
||||
*/
|
||||
int skytexorder[6] = {0,2,1,3,4,5};
|
||||
void R_DrawSkyBox (void)
|
||||
{
|
||||
|
||||
void
|
||||
R_DrawSkyBox (void) {
|
||||
|
||||
int i, j, k;
|
||||
vec3_t v;
|
||||
float s, t;
|
||||
|
||||
#if 0
|
||||
glEnable (GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glColor4f (1,1,1,0.5);
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glColor4f (1,1,1,0.5);
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
#endif
|
||||
for (i=0 ; i<6 ; i++)
|
||||
{
|
||||
|
@ -997,10 +927,10 @@ glDisable (GL_DEPTH_TEST);
|
|||
|
||||
GL_Bind (SKY_TEX+skytexorder[i]);
|
||||
#if 0
|
||||
skymins[0][i] = -1;
|
||||
skymins[1][i] = -1;
|
||||
skymaxs[0][i] = 1;
|
||||
skymaxs[1][i] = 1;
|
||||
skymins[0][i] = -1;
|
||||
skymins[1][i] = -1;
|
||||
skymaxs[0][i] = 1;
|
||||
skymaxs[1][i] = 1;
|
||||
#endif
|
||||
glBegin (GL_QUADS);
|
||||
MakeSkyVec (skymins[0][i], skymins[1][i], i);
|
||||
|
@ -1010,27 +940,23 @@ skymaxs[1][i] = 1;
|
|||
glEnd ();
|
||||
}
|
||||
#if 0
|
||||
glDisable (GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glColor4f (1,1,1,0.5);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDisable (GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glColor4f (1,1,1,0.5);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//===============================================================
|
||||
#endif // QUAKE2
|
||||
|
||||
/*
|
||||
=============
|
||||
R_InitSky
|
||||
R_InitSky
|
||||
|
||||
A sky texture is 256*128, with the right side being a masked overlay
|
||||
==============
|
||||
A sky texture is 256*128, with the right side being a masked overlay
|
||||
*/
|
||||
void R_InitSky (texture_t *mt)
|
||||
{
|
||||
void
|
||||
R_InitSky (texture_t *mt) {
|
||||
|
||||
int i, j, p;
|
||||
byte *src;
|
||||
unsigned trans[128*128];
|
||||
|
@ -1044,9 +970,8 @@ void R_InitSky (texture_t *mt)
|
|||
// a fringe on the top level
|
||||
|
||||
r = g = b = 0;
|
||||
for (i=0 ; i<128 ; i++)
|
||||
for (j=0 ; j<128 ; j++)
|
||||
{
|
||||
for (i=0 ; i<128 ; i++) {
|
||||
for (j=0 ; j<128 ; j++) {
|
||||
p = src[i*256 + j + 128];
|
||||
rgba = &d_8to24table[p];
|
||||
trans[(i*128) + j] = *rgba;
|
||||
|
@ -1054,13 +979,13 @@ void R_InitSky (texture_t *mt)
|
|||
g += ((byte *)rgba)[1];
|
||||
b += ((byte *)rgba)[2];
|
||||
}
|
||||
}
|
||||
|
||||
((byte *)&transpix)[0] = r/(128*128);
|
||||
((byte *)&transpix)[1] = g/(128*128);
|
||||
((byte *)&transpix)[2] = b/(128*128);
|
||||
((byte *)&transpix)[3] = 0;
|
||||
|
||||
|
||||
if (!solidskytexture)
|
||||
solidskytexture = texture_extension_number++;
|
||||
GL_Bind (solidskytexture );
|
||||
|
@ -1068,18 +993,17 @@ void R_InitSky (texture_t *mt)
|
|||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
|
||||
for (i=0 ; i<128 ; i++)
|
||||
for (j=0 ; j<128 ; j++)
|
||||
{
|
||||
for (i=0 ; i<128 ; i++) {
|
||||
for (j=0 ; j<128 ; j++) {
|
||||
p = src[i*256 + j];
|
||||
if (p == 0)
|
||||
trans[(i*128) + j] = transpix;
|
||||
else
|
||||
trans[(i*128) + j] = d_8to24table[p];
|
||||
}
|
||||
}
|
||||
|
||||
if (!alphaskytexture)
|
||||
if ( !alphaskytexture )
|
||||
alphaskytexture = texture_extension_number++;
|
||||
GL_Bind(alphaskytexture);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
|
||||
|
|
|
@ -19,10 +19,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
// disable data conversion warnings
|
||||
|
||||
/*#pragma warning(disable : 4244) // MIPS
|
||||
#pragma warning(disable : 4244) // MIPS
|
||||
#pragma warning(disable : 4136) // X86
|
||||
#pragma warning(disable : 4051) // ALPHA
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
@ -231,6 +231,7 @@ extern cvar_t gl_keeptjunctions;
|
|||
extern cvar_t gl_flashblend;
|
||||
extern cvar_t gl_nocolors;
|
||||
extern cvar_t gl_finish;
|
||||
extern cvar_t gl_doubleeyes;
|
||||
|
||||
extern int gl_lightmap_format;
|
||||
extern int gl_solid_format;
|
||||
|
|
Loading…
Reference in a new issue