diff --git a/bootstrap b/bootstrap index 842e07a..a9e4266 100755 --- a/bootstrap +++ b/bootstrap @@ -1,5 +1,6 @@ #!/bin/sh +echo "NOTE: two \"AC_TRY_RUN\" warnings below are not a problem!" aclocal autoheader automake --add-missing diff --git a/include/Makefile.am b/include/Makefile.am index f1b0b70..d43f62a 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -11,4 +11,4 @@ EXTRA_DIST = adivtab.h anorm_dots.h anorms.h asm_draw.h asm_i386.h block16.h \ sbar.h screen.h server.h sizebuf.h sound.h spritegn.h sys.h \ uint32.h vid.h view.h wad.h winquake.h world.h zone.h \ win32/fnmatch.h win32/bc/config.h win32/vc/config.h win32/vc/dirent.h \ - win32/version.h context_x11.h dga_check.h + win32/version.h context_x11.h dga_check.h gl_poly.h diff --git a/include/gl_poly.h b/include/gl_poly.h new file mode 100644 index 0000000..2482d69 --- /dev/null +++ b/include/gl_poly.h @@ -0,0 +1,71 @@ +/* + gl_poly.h + + Interface to the OpenGL poly list renderer + + Copyright (C) 2000 Joseph Carter + + Author: Joseph Carter + Date: 15 Jun 2000 + + 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. + + 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: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ + +#ifndef __GL_POLY_H +#define __GL_POLY_H + +// +// Depth polys +// + +#define MAX_DEPTHPOLYS 8192 +#define MAX_DEPTHVERTS (MAX_DEPTHPOLYS*4) + +typedef struct +{ + vec3_t v; +} depthvert_t; + +typedef struct +{ + unsigned short firstvert; + unsigned short verts; +} depthpoly_t; + +extern depthvert_t *depthvert; +extern depthpoly_t *depthpoly; +extern unsigned short currentdepthpoly; +extern unsigned short currentdepthvert; + +void Poly_ClearDepthPolys (void); +void Poly_BeginDepthPoly (void); +void Poly_EndDepthPoly (void); +void Poly_DepthPolyVert (vec3_t v); +void Poly_RenderDepthPolys (void); + +// +// Poly list housekeeping +// + +void Poly_Init (void); +void Poly_Shutdown (void); + +#endif // __GL_POLY_H diff --git a/include/glquake.h b/include/glquake.h index 7d14324..a3db929 100644 --- a/include/glquake.h +++ b/include/glquake.h @@ -307,5 +307,10 @@ void GL_BuildLightmaps (void); // void R_NetGraph (void); +// +// gl_warp.c +// +void EmitDepthPolys (msurface_t *fa); + #endif // _GLQUAKE_H diff --git a/source/Makefile.am b/source/Makefile.am index c858c1f..f6880bf 100644 --- a/source/Makefile.am +++ b/source/Makefile.am @@ -80,7 +80,7 @@ soft_SOURCES= cl_model.c cl_trans.c d_edge.c d_fill.c d_init.c d_modech.c \ screen.c model.c $(SOFT_ASM) ogl_SOURCES= gl_draw.c gl_mesh.c gl_model.c gl_ngraph.c gl_part.c \ gl_refrag.c gl_rlight.c gl_rmain.c gl_rmisc.c gl_rsurf.c \ - gl_screen.c gl_trans.c gl_view.c gl_warp.c + gl_screen.c gl_trans.c gl_view.c gl_warp.c gl_poly.c mgl_SOURCES= vid_mgl.c in_win.c ggi_SOURCES= vid_ggi.c diff --git a/source/gl_poly.c b/source/gl_poly.c new file mode 100644 index 0000000..0bb7168 --- /dev/null +++ b/source/gl_poly.c @@ -0,0 +1,169 @@ +/* + gl_poly.c + + Poly list renderer for OpenGL + + Copyright (C) 2000 Joseph Carter + Copyright (C) 2000 Forest Hale + + Author: Joseph Carter + Date: 15 June 2000 + + 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. + + 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: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include + +#include "glquake.h" +#include "gl_poly.h" +#include "console.h" + +// =========== +// DEPTH POLYS +// =========== + +depthvert_t *depthvert; +depthpoly_t *depthpoly; +unsigned short currentdepthpoly; +unsigned short currentdepthvert; + + +/* + Poly_ClearDepthPolys +*/ +void +Poly_ClearDepthPolys (void) +{ + currentdepthpoly = currentdepthvert = 0; +} + + +/* + Poly_BeginDepthPoly +*/ +void +Poly_BeginDepthPoly (void) +{ + if (currentdepthpoly >= MAX_DEPTHPOLYS + || currentdepthvert >= MAX_DEPTHVERTS) + return; + + depthpoly[currentdepthpoly].firstvert = currentdepthvert; + depthpoly[currentdepthpoly].verts = 0; +} + + +/* + Poly_EndDepthPoly +*/ +void +Poly_EndDepthPoly (void) +{ + if (currentdepthpoly >= MAX_DEPTHPOLYS) + return; + + if (depthpoly[currentdepthpoly].verts < 3) + { + // invalid poly - reset vert pointer + currentdepthvert = depthpoly[currentdepthpoly].firstvert; + return; + } + + if (currentdepthvert >= MAX_DEPTHVERTS) + return; + currentdepthpoly++; +} + +/* + Poly_DepthPolyVert +*/ +void +Poly_DepthPolyVert (vec3_t v) +{ + if (currentdepthpoly >= MAX_DEPTHPOLYS + || currentdepthvert >= MAX_DEPTHVERTS) + return; + + VectorCopy (depthvert[currentdepthvert].v, v); + currentdepthvert++; + depthpoly[currentdepthpoly].verts++; +} + +/* + Poly_RenderDepthPolys + + When drawn with a 0 colormask, a poly is transparent +*/ +void +Poly_RenderDepthPolys (void) +{ + int i, j; + depthpoly_t *p; + depthvert_t *vert; + + if (currentdepthpoly < 1) + return; + + glColorMask (0, 0, 0, 0); + glDepthMask (1); + + for (i = 0, p = depthpoly; i < currentdepthpoly; i++, p++) + { + vert = &depthvert[p->firstvert]; + glBegin (GL_TRIANGLE_FAN); + for (j=0 ; jverts ; j++, vert++) + glVertex3fv (vert->v); + glEnd (); + } + + glColorMask (1, 1, 1, 1); +} + +// ================= +// Poly housekeeping +// ================= + +/* + Poly_Init +*/ +void +Poly_Init (void) +{ + // depth polys + depthvert = malloc(MAX_DEPTHVERTS * sizeof(depthvert_t)); + depthpoly = malloc(MAX_DEPTHPOLYS * sizeof(depthpoly_t)); +} + + +/* + Poly_Shutdown +*/ +void +Poly_Shutdown (void) +{ + // depth polys + free (depthvert); + free (depthpoly); +} + diff --git a/source/gl_rmisc.c b/source/gl_rmisc.c index e04ee7c..38da4c3 100644 --- a/source/gl_rmisc.c +++ b/source/gl_rmisc.c @@ -55,6 +55,7 @@ #include "model.h" // needed by: glquake.h #include "console.h" #include "glquake.h" +#include "gl_poly.h" qboolean VID_Is8bit(void); extern void R_InitBubble(); @@ -248,7 +249,7 @@ void R_Init (void) gl_texsort = Cvar_Get("gl_texsort", "1", CVAR_NONE, "None"); if (gl_mtexable) - Cvar_SetValue(gl_texsort, 0.0); + Cvar_SetValue (gl_texsort, 0.0); gl_cull = Cvar_Get("gl_cull", "1", CVAR_NONE, "None"); gl_smoothmodels = Cvar_Get("gl_smoothmodels", "1", CVAR_NONE, "None"); @@ -274,6 +275,8 @@ void R_Init (void) playertextures = texture_extension_number; texture_extension_number += MAX_CLIENTS; + + Poly_Init (); } /* diff --git a/source/gl_rsurf.c b/source/gl_rsurf.c index a54ed73..a918959 100644 --- a/source/gl_rsurf.c +++ b/source/gl_rsurf.c @@ -55,6 +55,7 @@ #include "model.h" // needed by: glquake.h #include "console.h" #include "glquake.h" +#include "gl_poly.h" extern double realtime; int skytexturenum; @@ -422,6 +423,7 @@ void R_DrawSequentialPoly (msurface_t *s) glEnd (); return; } else { + glDisable (GL_BLEND); p = s->polys; t = R_TextureAnimation (s->texinfo->texture); @@ -436,6 +438,8 @@ void R_DrawSequentialPoly (msurface_t *s) glEnd (); glBindTexture (GL_TEXTURE_2D, lightmap_textures + s->lightmaptexturenum); + glEnable (GL_BLEND); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBegin (GL_POLYGON); v = p->verts[0]; for (i=0 ; inumverts ; i++, v+= VERTEXSIZE) @@ -457,6 +461,15 @@ void R_DrawSequentialPoly (msurface_t *s) EmitWaterPolys (s); return; } + + // + // depth polys for sky surfaces + // + if (s->flags & SURF_DRAWSKY) + { + EmitDepthPolys (s); + return; + } } @@ -1009,9 +1022,9 @@ void R_RecursiveWorldNode (mnode_t *node) surf->texturechain = surf->texinfo->texture->texturechain; surf->texinfo->texture->texturechain = surf; } - } else if (surf->flags & SURF_DRAWSKY) { - surf->texturechain = skychain; - skychain = surf; +// } else if (surf->flags & SURF_DRAWSKY) { +// surf->texturechain = skychain; +// skychain = surf; } else if (surf->flags & SURF_DRAWTURB) { surf->texturechain = waterchain; waterchain = surf; @@ -1044,10 +1057,12 @@ void R_DrawWorld (void) glColor3f (1.0, 1.0, 1.0); memset (lightmap_polys, 0, sizeof(lightmap_polys)); - // Be sure to clear the skybox --KB + + Poly_ClearDepthPolys (); R_DrawSky (); R_RecursiveWorldNode (cl.worldmodel->nodes); + Poly_RenderDepthPolys (); DrawTextureChains (); diff --git a/source/gl_warp.c b/source/gl_warp.c index 72d8b54..550e881 100644 --- a/source/gl_warp.c +++ b/source/gl_warp.c @@ -42,6 +42,7 @@ #include "console.h" #include "model.h" #include "glquake.h" +#include "gl_poly.h" #include "sys.h" extern double realtime; @@ -586,9 +587,6 @@ void R_LoadSkys (char * skyname) void R_SkyBoxPolyVec(vec5_t v) { - // avoid interpolation seams -// s = s * (254.0/256.0) + (1.0/256.0); -// t = t * (254.0/256.0) + (1.0/256.0); glTexCoord2fv (v); glVertex3f (r_refdef.vieworg[0] + v[2], r_refdef.vieworg[1] + v[3], @@ -831,3 +829,22 @@ 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); } + +/* + EmitDepthPolys +*/ +void +EmitDepthPolys (msurface_t *fa) +{ + glpoly_t *p; + float *v; + int i; + + for (p=fa->polys ; p ; p=p->next) + { + Poly_BeginDepthPoly (); + for (i=0,v=p->verts[0] ; inumverts ; i++, v+=VERTEXSIZE) + Poly_DepthPolyVert (v); + Poly_EndDepthPoly (); + } +}