From: Holger Z. <hz...@us...> - 2004-12-13 21:40:59
|
Update of /cvsroot/jake2/jake2/src/jake2/render/lwjgl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1434/src/jake2/render/lwjgl Added Files: Tag: LWJGL_IMPORT Light.java Image.java Warp.java Main.java Draw.java Model.java Surf.java Mesh.java Anorms.java Misc.java Base.java Log Message: import of LWJGL code --- NEW FILE: Image.java --- /* * Image.java * Copyright (C) 2003 * * $Id: Image.java,v 1.1.2.1 2004/12/13 21:40:44 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. 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. [...1657 lines suppressed...] */ void GL_ShutdownImages() { image_t image; for (int i=0; i < numgltextures ; i++) { image = gltextures[i]; if (image.registration_sequence == 0) continue; // free image_t slot // free it // TODO jogl bug texnumBuffer.clear(); texnumBuffer.put(0,image.texnum); gl.glDeleteTextures(texnumBuffer); image.clear(); } } } --- NEW FILE: Surf.java --- /* * Surf.java * Copyright (C) 2003 * * $Id: Surf.java,v 1.1.2.1 2004/12/13 21:40:45 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. 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. [...1442 lines suppressed...] // IntBuffer pix = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); // // int[] pixel = new int[w * h]; // // pix.get(pixel); // // BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); // image.setRGB(0, 0, w, h, pixel, 0, w); // AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(scale, scale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR); // BufferedImage tmp = op.filter(image, null); // // if (frame == null) { // frame = new ImageFrame(null); // frame.show(); // } // frame.showImage(tmp); // // } } --- NEW FILE: Light.java --- /* * Light.java * Copyright (C) 2003 * * $Id: Light.java,v 1.1.2.1 2004/12/13 21:40:44 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. 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 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.render.lwjgl; import jake2.Defines; import jake2.Globals; import jake2.client.dlight_t; import jake2.game.GameBase; import jake2.game.cplane_t; import jake2.qcommon.Com; import jake2.qcommon.longjmpException; import jake2.render.mnode_t; import jake2.render.msurface_t; import jake2.render.mtexinfo_t; import jake2.util.Math3D; import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.util.Arrays; import org.lwjgl.opengl.GL11; /** * Light * * @author cwei */ public abstract class Light extends Warp { // r_light.c int r_dlightframecount; static final int DLIGHT_CUTOFF = 64; /* ============================================================================= DYNAMIC LIGHTS BLEND RENDERING ============================================================================= */ void R_RenderDlight (dlight_t light) { int i, j; float a; float[] v = {0, 0, 0}; float rad; rad = light.intensity * 0.35f; Math3D.VectorSubtract (light.origin, r_origin, v); gl.glBegin (GL11.GL_TRIANGLE_FAN); gl.glColor3f (light.color[0]*0.2f, light.color[1]*0.2f, light.color[2]*0.2f); for (i=0 ; i<3 ; i++) v[i] = light.origin[i] - vpn[i]*rad; gl.glVertex3f(v[0], v[1], v[2]); gl.glColor3f (0,0,0); for (i=16 ; i>=0 ; i--) { a = (float)(i/16.0f * Math.PI*2); for (j=0 ; j<3 ; j++) v[j] = (float)(light.origin[j] + vright[j]*Math.cos(a)*rad + vup[j]*Math.sin(a)*rad); gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } /* ============= R_RenderDlights ============= */ void R_RenderDlights() { if (gl_flashblend.value == 0) return; r_dlightframecount = r_framecount + 1; // because the count hasn't // advanced yet for this frame gl.glDepthMask(false); gl.glDisable(GL11.GL_TEXTURE_2D); gl.glShadeModel (GL11.GL_SMOOTH); gl.glEnable (GL11.GL_BLEND); gl.glBlendFunc (GL11.GL_ONE, GL11.GL_ONE); for (int i=0 ; i<r_newrefdef.num_dlights ; i++) { R_RenderDlight(r_newrefdef.dlights[i]); } gl.glColor3f (1,1,1); gl.glDisable(GL11.GL_BLEND); gl.glEnable(GL11.GL_TEXTURE_2D); gl.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); gl.glDepthMask(true); } /* ============================================================================= DYNAMIC LIGHTS ============================================================================= */ /* ============= R_MarkLights ============= */ void R_MarkLights (dlight_t light, int bit, mnode_t node) { cplane_t splitplane; float dist; msurface_t surf; int i; int sidebit; if (node.contents != -1) return; splitplane = node.plane; dist = Math3D.DotProduct (light.origin, splitplane.normal) - splitplane.dist; if (dist > light.intensity - DLIGHT_CUTOFF) { R_MarkLights (light, bit, node.children[0]); return; } if (dist < -light.intensity + DLIGHT_CUTOFF) { R_MarkLights (light, bit, node.children[1]); return; } // mark the polygons for (i=0 ; i<node.numsurfaces ; i++) { surf = r_worldmodel.surfaces[node.firstsurface + i]; /* * cwei * bugfix for dlight behind the walls */ dist = Math3D.DotProduct (light.origin, surf.plane.normal) - surf.plane.dist; sidebit = (dist >= 0) ? 0 : Defines.SURF_PLANEBACK; if ( (surf.flags & Defines.SURF_PLANEBACK) != sidebit ) continue; /* * cwei * bugfix end */ if (surf.dlightframe != r_dlightframecount) { surf.dlightbits = 0; surf.dlightframe = r_dlightframecount; } surf.dlightbits |= bit; } R_MarkLights (light, bit, node.children[0]); R_MarkLights (light, bit, node.children[1]); } /* ============= R_PushDlights ============= */ void R_PushDlights() { int i; dlight_t l; if (gl_flashblend.value != 0) return; r_dlightframecount = r_framecount + 1; // because the count hasn't // advanced yet for this frame for (i=0 ; i<r_newrefdef.num_dlights ; i++) { l = r_newrefdef.dlights[i]; R_MarkLights( l, 1<<i, r_worldmodel.nodes[0] ); } } /* ============================================================================= LIGHT SAMPLING ============================================================================= */ float[] pointcolor = {0, 0, 0}; // vec3_t cplane_t lightplane; // used as shadow plane float[] lightspot = {0, 0, 0}; // vec3_t int RecursiveLightPoint (mnode_t node, float[] start, float[] end) { if (node.contents != -1) return -1; // didn't hit anything msurface_t surf; int s, t, ds, dt; int i; mtexinfo_t tex; ByteBuffer lightmap; int maps; float[] mid = {0, 0, 0}; // calculate mid point // FIXME: optimize for axial cplane_t plane = node.plane; float front = Math3D.DotProduct (start, plane.normal) - plane.dist; float back = Math3D.DotProduct (end, plane.normal) - plane.dist; boolean side = (front < 0); int sideIndex = (side) ? 1 : 0; if ( (back < 0) == side) return RecursiveLightPoint (node.children[sideIndex], start, end); float frac = front / (front-back); mid[0] = start[0] + (end[0] - start[0])*frac; mid[1] = start[1] + (end[1] - start[1])*frac; mid[2] = start[2] + (end[2] - start[2])*frac; // go down front side int r = RecursiveLightPoint (node.children[sideIndex], start, mid); if (r >= 0) return r; // hit something if ( (back < 0) == side ) return -1; // didn't hit anuthing // check for impact on this node Math3D.VectorCopy (mid, lightspot); lightplane = plane; int surfIndex = node.firstsurface; float[] scale = {0, 0, 0}; for (i=0 ; i<node.numsurfaces ; i++, surfIndex++) { surf = r_worldmodel.surfaces[surfIndex]; if ((surf.flags & (Defines.SURF_DRAWTURB | Defines.SURF_DRAWSKY)) != 0) continue; // no lightmaps tex = surf.texinfo; s = (int)(Math3D.DotProduct (mid, tex.vecs[0]) + tex.vecs[0][3]); t = (int)(Math3D.DotProduct (mid, tex.vecs[1]) + tex.vecs[1][3]); if (s < surf.texturemins[0] || t < surf.texturemins[1]) continue; ds = s - surf.texturemins[0]; dt = t - surf.texturemins[1]; if ( ds > surf.extents[0] || dt > surf.extents[1] ) continue; if (surf.samples == null) return 0; ds >>= 4; dt >>= 4; lightmap = surf.samples; int lightmapIndex = 0; Math3D.VectorCopy (Globals.vec3_origin, pointcolor); if (lightmap != null) { //float[] scale = {0, 0, 0}; float[] rgb; lightmapIndex += 3 * (dt * ((surf.extents[0] >> 4) + 1) + ds); for (maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255; maps++) { rgb = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb; scale[0] = gl_modulate.value * rgb[0]; scale[1] = gl_modulate.value * rgb[1]; scale[2] = gl_modulate.value * rgb[2]; pointcolor[0] += (lightmap.get(lightmapIndex + 0) & 0xFF) * scale[0] * (1.0f/255); pointcolor[1] += (lightmap.get(lightmapIndex + 1) & 0xFF) * scale[1] * (1.0f/255); pointcolor[2] += (lightmap.get(lightmapIndex + 2) & 0xFF) * scale[2] * (1.0f/255); lightmapIndex += 3 * ((surf.extents[0] >> 4) + 1) * ((surf.extents[1] >> 4) + 1); } } return 1; } // go down back side return RecursiveLightPoint (node.children[1 - sideIndex], mid, end); } /* =============== R_LightPoint =============== */ void R_LightPoint (float[] p, float[] color) { assert (p.length == 3) : "vec3_t bug"; assert (color.length == 3) : "rgb bug"; float[] end = {0, 0, 0}; dlight_t dl; float add; if (r_worldmodel.lightdata == null) { color[0] = color[1] = color[2] = 1.0f; return; } end[0] = p[0]; end[1] = p[1]; end[2] = p[2] - 2048; float r = RecursiveLightPoint(r_worldmodel.nodes[0], p, end); if (r == -1) { Math3D.VectorCopy (GameBase.vec3_origin, color); } else { Math3D.VectorCopy (pointcolor, color); } // // add dynamic lights // for (int lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++) { dl = r_newrefdef.dlights[lnum]; Math3D.VectorSubtract (currententity.origin, dl.origin, end); add = dl.intensity - Math3D.VectorLength(end); add *= (1.0f/256); if (add > 0) { Math3D.VectorMA (color, add, dl.color, color); } } Math3D.VectorScale (color, gl_modulate.value, color); } // =================================================================== float[] s_blocklights = new float[34 * 34 * 3]; /* =============== R_AddDynamicLights =============== */ // TODO sync with jogl renderer. hoz void R_AddDynamicLights(msurface_t surf) { int sd, td; float fdist, frad, fminlight; float[] impact = {0, 0, 0}; float[] local = {0, 0, 0}; int s, t; dlight_t dl; float[] pfBL; float fsacc, ftacc; int smax = (surf.extents[0]>>4)+1; int tmax = (surf.extents[1]>>4)+1; mtexinfo_t tex = surf.texinfo; for (int lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++) { if ( (surf.dlightbits & (1<<lnum)) == 0 ) continue; // not lit by this light dl = r_newrefdef.dlights[lnum]; frad = dl.intensity; fdist = Math3D.DotProduct (dl.origin, surf.plane.normal) - surf.plane.dist; frad -= Math.abs(fdist); // rad is now the highest intensity on the plane fminlight = DLIGHT_CUTOFF; // FIXME: make configurable? if (frad < fminlight) continue; fminlight = frad - fminlight; for (int i=0 ; i<3 ; i++) { impact[i] = dl.origin[i] - surf.plane.normal[i]*fdist; } local[0] = Math3D.DotProduct (impact, tex.vecs[0]) + tex.vecs[0][3] - surf.texturemins[0]; local[1] = Math3D.DotProduct (impact, tex.vecs[1]) + tex.vecs[1][3] - surf.texturemins[1]; pfBL = s_blocklights; int pfBLindex = 0; for (t = 0, ftacc = 0 ; t<tmax ; t++, ftacc += 16) { td = (int)(local[1] - ftacc); if ( td < 0 ) td = -td; for (s=0, fsacc = 0 ; s<smax ; s++, fsacc += 16, pfBLindex += 3) { sd = (int)( local[0] - fsacc ); if ( sd < 0 ) sd = -sd; if (sd > td) fdist = sd + (td>>1); else fdist = td + (sd>>1); if ( fdist < fminlight ) { pfBL[pfBLindex + 0] += ( frad - fdist ) * dl.color[0]; pfBL[pfBLindex + 1] += ( frad - fdist ) * dl.color[1]; pfBL[pfBLindex + 2] += ( frad - fdist ) * dl.color[2]; } } } } } /* ** R_SetCacheState */ void R_SetCacheState( msurface_t surf ) { for (int maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255 ; maps++) { surf.cached_light[maps] = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].white; } } /* =============== R_BuildLightMap Combine and scale multiple lightmaps into the floating format in blocklights =============== */ // TODO sync with jogl renderer. hoz void R_BuildLightMap(msurface_t surf, IntBuffer dest, int stride) { int r, g, b, a, max; int i, j; ByteBuffer lightmap; float[] scale = {0, 0, 0}; int nummaps; float[] bl; //lightstyle_t style; if ( (surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP)) != 0 ) Com.Error(Defines.ERR_DROP, "R_BuildLightMap called for non-lit surface"); int smax = (surf.extents[0] >> 4) + 1; int tmax = (surf.extents[1] >> 4) + 1; int size = smax * tmax; if (size > ((s_blocklights.length * Defines.SIZE_OF_FLOAT) >> 4) ) Com.Error(Defines.ERR_DROP, "Bad s_blocklights size"); try { // set to full bright if no light data if (surf.samples == null) { int maps; for (i=0 ; i<size*3 ; i++) s_blocklights[i] = 255; // TODO useless? hoz // for (maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255; maps++) // { // style = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF]; // } // goto store; throw new longjmpException(); } // count the # of maps for ( nummaps = 0 ; nummaps < Defines.MAXLIGHTMAPS && surf.styles[nummaps] != (byte)255 ; nummaps++) ; lightmap = surf.samples; int lightmapIndex = 0; // add all the lightmaps if ( nummaps == 1 ) { int maps; for (maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255 ; maps++) { bl = s_blocklights; int blp = 0; for (i=0 ; i<3 ; i++) scale[i] = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; if ( scale[0] == 1.0F && scale[1] == 1.0F && scale[2] == 1.0F ) { for (i=0 ; i<size ; i++) { bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; } } else { for (i=0 ; i<size ; i++) { bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale[0]; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale[1]; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale[2]; } } //lightmap += size*3; // skip to next lightmap } } else { int maps; // memset( s_blocklights, 0, sizeof( s_blocklights[0] ) * size * 3 ); Arrays.fill(s_blocklights, 0, size * 3, 0.0f); for (maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255 ; maps++) { bl = s_blocklights; int blp = 0; for (i=0 ; i<3 ; i++) scale[i] = gl_modulate.value*r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; if ( scale[0] == 1.0F && scale[1] == 1.0F && scale[2] == 1.0F ) { for (i=0 ; i<size ; i++) { bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; } } else { for (i=0 ; i<size ; i++) { bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale[0]; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale[1]; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale[2]; } } //lightmap += size*3; // skip to next lightmap } } // add all the dynamic lights if (surf.dlightframe == r_framecount) R_AddDynamicLights(surf); // label store: } catch (longjmpException store) {} // put into texture format stride -= smax; bl = s_blocklights; int blp = 0; int monolightmap = gl_monolightmap.string.charAt(0); int destp = 0; if ( monolightmap == '0' ) { for (i=0 ; i<tmax ; i++, destp += stride) { //dest.position(destp); for (j=0 ; j<smax ; j++) { r = (int)bl[blp++]; g = (int)bl[blp++]; b = (int)bl[blp++]; // catch negative lights if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0; /* ** determine the brightest of the three color components */ if (r > g) max = r; else max = g; if (b > max) max = b; /* ** alpha is ONLY used for the mono lightmap case. For this reason ** we set it to the brightest of the color components so that ** things don't get too dim. */ a = max; /* ** rescale all the color components if the intensity of the greatest ** channel exceeds 1.0 */ if (max > 255) { float t = 255.0F / max; r = (int)(r*t); g = (int)(g*t); b = (int)(b*t); a = (int)(a*t); } //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | (r << 0)); } } } else { for (i=0 ; i<tmax ; i++, destp += stride) { //dest.position(destp); for (j=0 ; j<smax ; j++) { r = (int) bl[blp++]; g = (int) bl[blp++]; b = (int) bl[blp++]; // catch negative lights if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0; /* ** determine the brightest of the three color components */ if (r > g) max = r; else max = g; if (b > max) max = b; /* ** alpha is ONLY used for the mono lightmap case. For this reason ** we set it to the brightest of the color components so that ** things don't get too dim. */ a = max; /* ** rescale all the color components if the intensity of the greatest ** channel exceeds 1.0 */ if (max > 255) { float t = 255.0F / max; r = (int)(r*t); g = (int)(g*t); b = (int)(b*t); a = (int)(a*t); } /* ** So if we are doing alpha lightmaps we need to set the R, G, and B ** components to 0 and we need to set alpha to 1-alpha. */ switch ( monolightmap ) { case 'L': case 'I': r = a; g = b = 0; break; case 'C': // try faking colored lighting a = 255 - ((r+g+b)/3); r *= a/255.0f; g *= a/255.0f; b *= a/255.0f; break; case 'A': default: r = g = b = 0; a = 255 - a; break; } //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | (r << 0)); } } } } } --- NEW FILE: Base.java --- /* * Base.java * Copyright (C) 2003 * * $Id: Base.java,v 1.1.2.1 2004/12/13 21:40:45 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. 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 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.render.lwjgl; import jake2.render.LWJGLBase; import org.lwjgl.opengl.GL11; /** * Base * * @author dsanders/cwei */ public abstract class Base extends LWJGLBase { static final int GL_COLOR_INDEX8_EXT = GL11.GL_COLOR_INDEX; static final String REF_VERSION = "GL 0.01"; // up / down static final int PITCH = 0; // left / right static final int YAW = 1; // fall over static final int ROLL = 2; /* skins will be outline flood filled and mip mapped pics and sprites with alpha will be outline flood filled pic won't be mip mapped model skin sprite frame wall texture pic */ // enum imagetype_t static final int it_skin = 0; static final int it_sprite = 1; static final int it_wall = 2; static final int it_pic = 3; static final int it_sky = 4; // enum modtype_t static final int mod_bad = 0; static final int mod_brush = 1; static final int mod_sprite = 2; static final int mod_alias = 3; static final int TEXNUM_LIGHTMAPS = 1024; static final int TEXNUM_SCRAPS = 1152; static final int TEXNUM_IMAGES = 1153; static final int MAX_GLTEXTURES = 1024; // =================================================================== // // #include "gl_model.h" // // void GL_BeginRendering (int *x, int *y, int *width, int *height); // void GL_EndRendering (void); // // void GL_SetDefaultState( void ); // void GL_UpdateSwapInterval( void ); static class glvert_t { float x, y, z; float s, t; float r, g, b; } static final int MAX_LBM_HEIGHT = 480; static final float BACKFACE_EPSILON = 0.01f; // ==================================================== // // void R_TranslatePlayerSkin (int playernum); // void GL_Bind (int texnum); // void GL_MBind( GLenum target, int texnum ); // void GL_TexEnv( GLenum value ); // void GL_EnableMultitexture( qboolean enable ); // void GL_SelectTexture( GLenum ); // // void R_LightPoint (vec3_t p, vec3_t color); // void R_PushDlights (void); // // ==================================================================== // // extern int registration_sequence; // // // void V_AddBlend (float r, float g, float b, float a, float *v_blend); // // int R_Init( void *hinstance, void *hWnd ); // void R_Shutdown( void ); // // void R_RenderView (refdef_t *fd); // void GL_ScreenShot_f (void); // void R_DrawAliasModel (entity_t *e); // void R_DrawBrushModel (entity_t *e); // void R_DrawSpriteModel (entity_t *e); // void R_DrawBeam( entity_t *e ); // void R_DrawWorld (void); // void R_RenderDlights (void); // void R_DrawAlphaSurfaces (void); // void R_RenderBrushPoly (msurface_t *fa); // void R_InitParticleTexture (void); // void Draw_InitLocal (void); // void GL_SubdivideSurface (msurface_t *fa); // qboolean R_CullBox (vec3_t mins, vec3_t maxs); // void R_RotateForEntity (entity_t *e); // void R_MarkLeaves (void); // // glpoly_t *WaterWarpPolyVerts (glpoly_t *p); // void EmitWaterPolys (msurface_t *fa); // void R_AddSkySurface (msurface_t *fa); // void R_ClearSkyBox (void); // void R_DrawSkyBox (void); // void R_MarkLights (dlight_t *light, int bit, mnode_t *node); // // // void COM_StripExtension (char *in, char *out); // // void Draw_GetPicSize (int *w, int *h, char *name); // void Draw_Pic (int x, int y, char *name); // void Draw_StretchPic (int x, int y, int w, int h, char *name); // void Draw_Char (int x, int y, int c); // void Draw_TileClear (int x, int y, int w, int h, char *name); // void Draw_Fill (int x, int y, int w, int h, int c); // void Draw_FadeScreen (void); // void Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data); // // void R_BeginFrame( float camera_separation ); // void R_SwapBuffers( int ); // void R_SetPalette ( const unsigned char *palette); // // int Draw_GetPalette (void); // // void GL_ResampleTexture (unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight); // // struct image_s *R_RegisterSkin (char *name); // // void LoadPCX (char *filename, byte **pic, byte **palette, int *width, int *height); // image_t *GL_LoadPic (char *name, byte *pic, int width, int height, imagetype_t type, int bits); // image_t *GL_FindImage (char *name, imagetype_t type); // void GL_TextureMode( char *string ); // void GL_ImageList_f (void); // // void GL_SetTexturePalette( unsigned palette[256] ); // // void GL_InitImages (void); // void GL_ShutdownImages (void); // // void GL_FreeUnusedImages (void); // // void GL_TextureAlphaMode( char *string ); // void GL_TextureSolidMode( char *string ); // // /* // ** GL extension emulation functions // */ // void GL_DrawParticles( int n, const particle_t particles[], const unsigned colortable[768] ); // /* ** GL config stuff */ static final int GL_RENDERER_VOODOO = 0x00000001; static final int GL_RENDERER_VOODOO2 = 0x00000002; static final int GL_RENDERER_VOODOO_RUSH = 0x00000004; static final int GL_RENDERER_BANSHEE = 0x00000008; static final int GL_RENDERER_3DFX = 0x0000000F; static final int GL_RENDERER_PCX1 = 0x00000010; static final int GL_RENDERER_PCX2 = 0x00000020; static final int GL_RENDERER_PMX = 0x00000040; static final int GL_RENDERER_POWERVR = 0x00000070; static final int GL_RENDERER_PERMEDIA2 = 0x00000100; static final int GL_RENDERER_GLINT_MX = 0x00000200; static final int GL_RENDERER_GLINT_TX = 0x00000400; static final int GL_RENDERER_3DLABS_MISC = 0x00000800; static final int GL_RENDERER_3DLABS = 0x00000F00; static final int GL_RENDERER_REALIZM = 0x00001000; static final int GL_RENDERER_REALIZM2 = 0x00002000; static final int GL_RENDERER_INTERGRAPH = 0x00003000; static final int GL_RENDERER_3DPRO = 0x00004000; static final int GL_RENDERER_REAL3D = 0x00008000; static final int GL_RENDERER_RIVA128 = 0x00010000; static final int GL_RENDERER_DYPIC = 0x00020000; static final int GL_RENDERER_V1000 = 0x00040000; static final int GL_RENDERER_V2100 = 0x00080000; static final int GL_RENDERER_V2200 = 0x00100000; static final int GL_RENDERER_RENDITION = 0x001C0000; static final int GL_RENDERER_O2 = 0x00100000; static final int GL_RENDERER_IMPACT = 0x00200000; static final int GL_RENDERER_RE = 0x00400000; static final int GL_RENDERER_IR = 0x00800000; static final int GL_RENDERER_SGI = 0x00F00000; static final int GL_RENDERER_MCD = 0x01000000; static final int GL_RENDERER_OTHER = 0x80000000; // typedef struct // { // int renderer; // const char *renderer_string; // const char *vendor_string; // const char *version_string; // const char *extensions_string; // // qboolean allow_cds; // } glconfig_t; // // typedef struct // { // float inverse_intensity; // qboolean fullscreen; // // int prev_mode; // // unsigned char *d_16to8table; // // int lightmap_textures; // // int currenttextures[2]; // int currenttmu; // // float camera_separation; // qboolean stereo_enabled; // // unsigned char originalRedGammaTable[256]; // unsigned char originalGreenGammaTable[256]; // unsigned char originalBlueGammaTable[256]; // } glstate_t; // // /* // ==================================================================== // // IMPORTED FUNCTIONS // // ==================================================================== // */ // // extern refimport_t ri; // // // /* // ==================================================================== // // IMPLEMENTATION SPECIFIC FUNCTIONS // // ==================================================================== // */ // // void GLimp_BeginFrame( float camera_separation ); // void GLimp_EndFrame( void ); // int GLimp_Init( void *hinstance, void *hWnd ); // void GLimp_Shutdown( void ); // int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen ); // void GLimp_AppActivate( qboolean active ); // void GLimp_EnableLogging( qboolean enable ); // void GLimp_LogNewFrame( void ); // } --- NEW FILE: Draw.java --- /* * Draw.java * Copyright (C) 2003 * * $Id: Draw.java,v 1.1.2.1 2004/12/13 21:40:45 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. 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 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.render.lwjgl; import jake2.Defines; import jake2.client.VID; import jake2.qcommon.Com; import jake2.render.image_t; import java.awt.Dimension; import java.nio.ByteBuffer; import java.nio.IntBuffer; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; /** * Draw * (gl_draw.c) * * @author cwei */ public abstract class Draw extends Image { /* =============== Draw_InitLocal =============== */ void Draw_InitLocal() { // load console characters (don't bilerp characters) draw_chars = GL_FindImage("pics/conchars.pcx", it_pic); GL_Bind(draw_chars.texnum); gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); } /* ================ Draw_Char Draws one 8*8 graphics character with 0 being transparent. It can be clipped to the top of the screen to allow the console to be smoothly scrolled off. ================ */ protected void Draw_Char(int x, int y, int num) { num &= 255; if ( (num&127) == 32 ) return; // space if (y <= -8) return; // totally off screen int row = num>>4; int col = num&15; float frow = row*0.0625f; float fcol = col*0.0625f; float size = 0.0625f; GL_Bind(draw_chars.texnum); gl.glBegin (GL11.GL_QUADS); gl.glTexCoord2f (fcol, frow); gl.glVertex2f (x, y); gl.glTexCoord2f (fcol + size, frow); gl.glVertex2f (x+8, y); gl.glTexCoord2f (fcol + size, frow + size); gl.glVertex2f (x+8, y+8); gl.glTexCoord2f (fcol, frow + size); gl.glVertex2f (x, y+8); gl.glEnd (); } /* ============= Draw_FindPic ============= */ protected image_t Draw_FindPic(String name) { image_t image = null; String fullname; if (!name.startsWith("/") && !name.startsWith("\\")) { fullname = "pics/" + name + ".pcx"; image = GL_FindImage(fullname, it_pic); } else { image = GL_FindImage(name.substring(1), it_pic); } return image; } /* ============= Draw_GetPicSize ============= */ protected void Draw_GetPicSize(Dimension dim, String pic) { image_t image = Draw_FindPic(pic); dim.width = (image != null) ? image.width : -1; dim.height = (image != null) ? image.height : -1; } /* ============= Draw_StretchPic ============= */ protected void Draw_StretchPic (int x, int y, int w, int h, String pic) { image_t image; image = Draw_FindPic(pic); if (image == null) { VID.Printf (Defines.PRINT_ALL, "Can't find pic: " + pic +'\n'); return; } if (scrap_dirty) Scrap_Upload(); if ( ( ( gl_config.renderer == GL_RENDERER_MCD ) || ( (gl_config.renderer & GL_RENDERER_RENDITION) != 0) ) && !image.has_alpha) gl.glDisable(GL11.GL_ALPHA_TEST); GL_Bind(image.texnum); gl.glBegin (GL11.GL_QUADS); gl.glTexCoord2f (image.sl, image.tl); gl.glVertex2f (x, y); gl.glTexCoord2f (image.sh, image.tl); gl.glVertex2f (x+w, y); gl.glTexCoord2f (image.sh, image.th); gl.glVertex2f (x+w, y+h); gl.glTexCoord2f (image.sl, image.th); gl.glVertex2f (x, y+h); gl.glEnd (); if ( ( ( gl_config.renderer == GL_RENDERER_MCD ) || ( (gl_config.renderer & GL_RENDERER_RENDITION) !=0 ) ) && !image.has_alpha) gl.glEnable(GL11.GL_ALPHA_TEST); } /* ============= Draw_Pic ============= */ protected void Draw_Pic(int x, int y, String pic) { image_t image; image = Draw_FindPic(pic); if (image == null) { VID.Printf(Defines.PRINT_ALL, "Can't find pic: " +pic + '\n'); return; } if (scrap_dirty) Scrap_Upload(); if ( ( ( gl_config.renderer == GL_RENDERER_MCD ) || ( (gl_config.renderer & GL_RENDERER_RENDITION) != 0 ) ) && !image.has_alpha) gl.glDisable (GL11.GL_ALPHA_TEST); GL_Bind(image.texnum); gl.glBegin (GL11.GL_QUADS); gl.glTexCoord2f (image.sl, image.tl); gl.glVertex2f (x, y); gl.glTexCoord2f (image.sh, image.tl); gl.glVertex2f (x+image.width, y); gl.glTexCoord2f (image.sh, image.th); gl.glVertex2f (x+image.width, y+image.height); gl.glTexCoord2f (image.sl, image.th); gl.glVertex2f (x, y+image.height); gl.glEnd (); if ( ( ( gl_config.renderer == GL_RENDERER_MCD ) || ( (gl_config.renderer & GL_RENDERER_RENDITION) != 0 ) ) && !image.has_alpha) gl.glEnable (GL11.GL_ALPHA_TEST); } /* ============= Draw_TileClear This repeats a 64*64 tile graphic to fill the screen around a sized down refresh window. ============= */ protected void Draw_TileClear(int x, int y, int w, int h, String pic) { image_t image; image = Draw_FindPic(pic); if (image == null) { VID.Printf(Defines.PRINT_ALL, "Can't find pic: " + pic + '\n'); return; } if ( ( ( gl_config.renderer == GL_RENDERER_MCD ) || ( (gl_config.renderer & GL_RENDERER_RENDITION) != 0 ) ) && !image.has_alpha) gl.glDisable(GL11.GL_ALPHA_TEST); GL_Bind(image.texnum); gl.glBegin (GL11.GL_QUADS); gl.glTexCoord2f(x/64.0f, y/64.0f); gl.glVertex2f (x, y); gl.glTexCoord2f( (x+w)/64.0f, y/64.0f); gl.glVertex2f(x+w, y); gl.glTexCoord2f( (x+w)/64.0f, (y+h)/64.0f); gl.glVertex2f(x+w, y+h); gl.glTexCoord2f( x/64.0f, (y+h)/64.0f ); gl.glVertex2f (x, y+h); gl.glEnd (); if ( ( ( gl_config.renderer == GL_RENDERER_MCD ) || ( (gl_config.renderer & GL_RENDERER_RENDITION) != 0 ) ) && !image.has_alpha) gl.glEnable(GL11.GL_ALPHA_TEST); } /* ============= Draw_Fill Fills a box of pixels with a single color ============= */ protected void Draw_Fill(int x, int y, int w, int h, int colorIndex) { if ( colorIndex > 255) Com.Error(Defines.ERR_FATAL, "Draw_Fill: bad color"); gl.glDisable(GL11.GL_TEXTURE_2D); int color = d_8to24table[colorIndex]; gl.glColor3ub( (byte)((color >> 0) & 0xff), // r (byte)((color >> 8) & 0xff), // g (byte)((color >> 16) & 0xff) // b ); gl.glBegin (GL11.GL_QUADS); gl.glVertex2f(x,y); gl.glVertex2f(x+w, y); gl.glVertex2f(x+w, y+h); gl.glVertex2f(x, y+h); gl.glEnd(); gl.glColor3f(1,1,1); gl.glEnable(GL11.GL_TEXTURE_2D); } //============================================================================= /* ================ Draw_FadeScreen ================ */ protected void Draw_FadeScreen() { gl.glEnable(GL11.GL_BLEND); gl.glDisable(GL11.GL_TEXTURE_2D); gl.glColor4f(0, 0, 0, 0.8f); gl.glBegin(GL11.GL_QUADS); gl.glVertex2f(0,0); gl.glVertex2f(vid.width, 0); gl.glVertex2f(vid.width, vid.height); gl.glVertex2f(0, vid.height); gl.glEnd(); gl.glColor4f(1,1,1,1); gl.glEnable(GL11.GL_TEXTURE_2D); gl.glDisable(GL11.GL_BLEND); } // ==================================================================== IntBuffer image32=BufferUtils.createIntBuffer(256*256); ByteBuffer image8=BufferUtils.createByteBuffer(256*256); /* ============= Draw_StretchRaw ============= */ protected void Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte[] data) { int i, j, trows; int sourceIndex; int frac, fracstep; float hscale; int row; float t; GL_Bind(0); if (rows<=256) { hscale = 1; trows = rows; } else { hscale = rows/256.0f; trows = 256; } t = rows*hscale / 256; if ( !qglColorTableEXT ) { //int[] image32 = new int[256*256]; image32.clear(); int destIndex = 0; for (i=0 ; i<trows ; i++) { row = (int)(i*hscale); if (row > rows) break; sourceIndex = cols*row; destIndex = i*256; fracstep = cols*0x10000/256; frac = fracstep >> 1; for (j=0 ; j<256 ; j++) { image32.put(destIndex + j, r_rawpalette[data[sourceIndex + (frac>>16)] & 0xff]); frac += fracstep; } } gl.glTexImage2D (GL11.GL_TEXTURE_2D, 0, gl_tex_solid_format, 256, 256, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image32); } else { //byte[] image8 = new byte[256*256]; image8.clear(); int destIndex = 0;; for (i=0 ; i<trows ; i++) { row = (int)(i*hscale); if (row > rows) break; sourceIndex = cols*row; destIndex = i*256; fracstep = cols*0x10000/256; frac = fracstep >> 1; for (j=0 ; j<256 ; j++) { image8.put(destIndex + j, data[sourceIndex + (frac>>16)]); frac += fracstep; } } gl.glTexImage2D( GL11.GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0, GL11.GL_COLOR_INDEX, GL11.GL_UNSIGNED_BYTE, image8 ); } gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); if ( ( gl_config.renderer == GL_RENDERER_MCD ) || ( (gl_config.renderer & GL_RENDERER_RENDITION) != 0 ) ) gl.glDisable (GL11.GL_ALPHA_TEST); gl.glBegin (GL11.GL_QUADS); gl.glTexCoord2f (0, 0); gl.glVertex2f (x, y); gl.glTexCoord2f (1, 0); gl.glVertex2f (x+w, y); gl.glTexCoord2f (1, t); gl.glVertex2f (x+w, y+h); gl.glTexCoord2f (0, t); gl.glVertex2f (x, y+h); gl.glEnd (); if ( ( gl_config.renderer == GL_RENDERER_MCD ) || ( (gl_config.renderer & GL_RENDERER_RENDITION) != 0 ) ) gl.glEnable (GL11.GL_ALPHA_TEST); } } --- NEW FILE: Model.java --- /* * Model.java * Copyright (C) 2003 * * $Id: Model.java,v 1.1.2.1 2004/12/13 21:40:45 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. 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. [...1327 lines suppressed...] for (int i = 0; i < model.counts.length; i++) { count = ((Integer)tmp.get(i)).intValue(); model.counts[i] = count; count = (count < 0) ? -count : count; model.vertexIndexBuf.position(pos); model.indexElements[i] = model.vertexIndexBuf.slice(); pos += count; } } static void resetModelArrays() { globalModelTextureCoordBuf.rewind(); globalModelVertexIndexBuf.rewind(); } static void modelMemoryUsage() { System.out.println("AliasModels: globalVertexBuffer size " + globalModelVertexIndexBuf.position()); } } --- NEW FILE: Main.java --- /* * Main.java * Copyright (C) 2003 * * $Id: Main.java,v 1.1.2.1 2004/12/13 21:40:45 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. 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. [...1530 lines suppressed...] float[] v; for (i = 0; i < NUM_BEAM_SEGS; i++) { v = start_points[i]; gl.glVertex3f(v[0], v[1], v[2]); v = end_points[i]; gl.glVertex3f(v[0], v[1], v[2]); v = start_points[(i + 1) % NUM_BEAM_SEGS]; gl.glVertex3f(v[0], v[1], v[2]); v = end_points[(i + 1) % NUM_BEAM_SEGS]; gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); gl.glEnable(GL11.GL_TEXTURE_2D); gl.glDisable(GL11.GL_BLEND); gl.glDepthMask(true); } } --- NEW FILE: Warp.java --- /* * Warp.java * Copyright (C) 2003 * * $Id: Warp.java,v 1.1.2.1 2004/12/13 21:40:44 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. 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 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.render.lwjgl; import jake2.Defines; import jake2.Globals; import jake2.qcommon.Com; import jake2.render.glpoly_t; import jake2.render.image_t; import jake2.render.msurface_t; import jake2.util.Math3D; import java.nio.FloatBuffer; import org.lwjgl.opengl.GL11; /** * Warp * * @author cwei */ public abstract class Warp extends Model { // warpsin.h public static final float[] SIN = { 0f, 0.19633f, 0.392541f, 0.588517f, 0.784137f, 0.979285f, 1.17384f, 1.3677f, 1.56072f, 1.75281f, 1.94384f, 2.1337f, 2.32228f, 2.50945f, 2.69512f, 2.87916f, 3.06147f, 3.24193f, 3.42044f, 3.59689f, 3.77117f, 3.94319f, 4.11282f, 4.27998f, 4.44456f, 4.60647f, 4.76559f, 4.92185f, 5.07515f, 5.22538f, 5.37247f, 5.51632f, 5.65685f, 5.79398f, 5.92761f, 6.05767f, 6.18408f, 6.30677f, 6.42566f, 6.54068f, 6.65176f, 6.75883f, 6.86183f, 6.9607f, 7.05537f, 7.14579f, 7.23191f, 7.31368f, 7.39104f, 7.46394f, 7.53235f, 7.59623f, 7.65552f, 7.71021f, 7.76025f, 7.80562f, 7.84628f, 7.88222f, 7.91341f, 7.93984f, 7.96148f, 7.97832f, 7.99036f, 7.99759f, 8f, 7.99759f, 7.99036f, 7.97832f, 7.96148f, 7.93984f, 7.91341f, 7.88222f, 7.84628f, 7.80562f, 7.76025f, 7.71021f, 7.65552f, 7.59623f, 7.53235f, 7.46394f, 7.39104f, 7.31368f, 7.23191f, 7.14579f, 7.05537f, 6.9607f, 6.86183f, 6.75883f, 6.65176f, 6.54068f, 6.42566f, 6.30677f, 6.18408f, 6.05767f, 5.92761f, 5.79398f, 5.65685f, 5.51632f, 5.37247f, 5.22538f, 5.07515f, 4.92185f, 4.76559f, 4.60647f, 4.44456f, 4.27998f, 4.11282f, 3.94319f, 3.77117f, 3.59689f, 3.42044f, 3.24193f, 3.06147f, 2.87916f, 2.69512f, 2.50945f, 2.32228f, 2.1337f, 1.94384f, 1.75281f, 1.56072f, 1.3677f, 1.17384f, 0.979285f, 0.784137f, 0.588517f, 0.392541f, 0.19633f, 9.79717e-16f, -0.19633f, -0.392541f, -0.588517f, -0.784137f, -0.979285f, -1.17384f, -1.3677f, -1.56072f, -1.75281f, -1.94384f, -2.1337f, -2.32228f, -2.50945f, -2.69512f, -2.87916f, -3.06147f, -3.24193f, -3.42044f, -3.59689f, -3.77117f, -3.94319f, -4.11282f, -4.27998f, -4.44456f, -4.60647f, -4.76559f, -4.92185f, -5.07515f, -5.22538f, -5.37247f, -5.51632f, -5.65685f, -5.79398f, -5.92761f, -6.05767f, -6.18408f, -6.30677f, -6.42566f, -6.54068f, -6.65176f, -6.75883f, -6.86183f, -6.9607f, -7.05537f, -7.14579f, -7.23191f, -7.31368f, -7.39104f, -7.46394f, -7.53235f, -7.59623f, -7.65552f, -7.71021f, -7.76025f, -7.80562f, -7.84628f, -7.88222f, -7.91341f, -7.93984f, -7.96148f, -7.97832f, -7.99036f, -7.99759f, -8f, -7.99759f, -7.99036f, -7.97832f, -7.96148f, -7.93984f, -7.91341f, -7.88222f, -7.84628f, -7.80562f, -7.76025f, -7.71021f, -7.65552f, -7.59623f, -7.53235f, -7.46394f, -7.39104f, -7.31368f, -7.23191f, -7.14579f, -7.05537f, -6.9607f, -6.86183f, -6.75883f, -6.65176f, -6.54068f, -6.42566f, -6.30677f, -6.18408f, -6.05767f, -5.92761f, -5.79398f, -5.65685f, -5.51632f, -5.37247f, -5.22538f, -5.07515f, -4.92185f, -4.76559f, -4.60647f, -4.44456f, -4.27998f, -4.11282f, -3.94319f, -3.77117f, -3.59689f, -3.42044f, -3.24193f, -3.06147f, -2.87916f, -2.69512f, -2.50945f, -2.32228f, -2.1337f, -1.94384f, -1.75281f, -1.56072f, -1.3677f, -1.17384f, -0.979285f, -0.784137f, -0.588517f, -0.392541f, -0.19633f }; // gl_warp.c -- sky and water polygons //extern model_t *loadmodel; // Model.java String skyname; float skyrotate; float[] skyaxis = {0, 0, 0}; image_t[] sky_images = new image_t[6]; msurface_t warpface; static final int SUBDIVIDE_SIZE = 64; void BoundPoly(int numverts, float[][] verts, float[] mins, float[] maxs) { int i, j; float[] v; mins[0] = mins[1] = mins[2] = 9999; maxs[0] = maxs[1] = maxs[2] = -9999; for (i=0 ; i<numverts ; i++) { v = verts[i]; for (j=0 ; j<3 ; j++) { if (v[j] < mins[j]) mins[j] = v[j]; if (v[j] > maxs[j]) maxs[j] = v[j]; } } } void SubdividePolygon(int numverts, float[][] verts) { int i, j, k; float[] mins = {0, 0, 0}; float[] maxs = {0, 0, 0}; float m; float[] v = {0, 0, 0}; float[][] front = new float[64][3]; float[][] back = new float[64][3]; int f, b; float[] dist = new float[64]; float frac; float s, t; float[] total = {0, 0, 0}; float total_s, total_t; if (numverts > 60) Com.Error(Defines.ERR_DROP, "numverts = " + numverts); BoundPoly(numverts, verts, mins, maxs); // x,y und z for (i=0 ; i<3 ; i++) { m = (mins[i] + maxs[i]) * 0.5f; m = SUBDIVIDE_SIZE * (float)Math.floor(m / SUBDIVIDE_SIZE + 0.5f); if (maxs[i] - m < 8) continue; if (m - mins[i] < 8) continue; // cut it for (j=0 ; j<numverts ; j++) { dist[j] = verts[j][i] - m; } // wrap cases dist[j] = dist[0]; Math3D.VectorCopy(verts[0], verts[numverts]); f = b = 0; for (j=0 ; j<numverts ; j++) { v = verts[j]; if (dist[j] >= 0) { Math3D.VectorCopy(v, front[f]); f++; } if (dist[j] <= 0) { Math3D.VectorCopy(v, back[b]); b++; } if (dist[j] == 0 || dist[j+1] == 0) continue; if ( (dist[j] > 0) != (dist[j+1] > 0) ) { // clip point frac = dist[j] / (dist[j] - dist[j+1]); for (k=0 ; k<3 ; k++) front[f][k] = back[b][k] = v[k] + frac*(verts[j+1][k] - v[k]); f++; b++; } } SubdividePolygon(f, front); SubdividePolygon(b, back); return; } // add a point in the center to help keep warp valid // wird im Konstruktor erschlagen // poly = Hunk_Alloc (sizeof(glpoly_t) + ((numverts-4)+2) * VERTEXSIZE*sizeof(float)); // init polys glpoly_t poly = new glpoly_t(numverts + 2); poly.next = warpface.polys; warpface.polys = poly; poly.numverts = numverts + 2; Math3D.VectorClear(total); total_s = 0; total_t = 0; for (i=0 ; i<numverts ; i++) { Math3D.VectorCopy(verts[i], poly.verts[i+1]); s = Math3D.DotProduct(verts[i], warpface.texinfo.vecs[0]); t = Math3D.DotProduct(verts[i], warpface.texinfo.vecs[1]); total_s += s; total_t += t; Math3D.VectorAdd(total, verts[i], total); poly.verts[i+1][3] = s; poly.verts[i+1][4] = t; } Math3D.VectorScale(total, (1.0f/numverts), poly.verts[0]); poly.verts[0][3] = total_s/numverts; poly.verts[0][4] = total_t/numverts; // memcpy (poly.verts[i+1], poly.verts[1], sizeof(poly.verts[0])); System.arraycopy(poly.verts[1], 0, poly.verts[i+1], 0, poly.verts[1].length); // :-) precompilePolygon(poly); } /* ================ GL_SubdivideSurface Breaks a polygon up along axial 64 unit boundaries so that turbulent and sky warps can be done reasonably. ================ */ void GL_SubdivideSurface(msurface_t fa) { float[][] verts = new float[64][3]; int numverts; int i; int lindex; float[] vec; warpface = fa; // // convert edges back to a normal polygon // numverts = 0; for (i=0 ; i < fa.numedges ; i++) { lindex = loadmodel.surfedges[fa.firstedge + i]; if (lindex > 0) vec = loadmodel.vertexes[loadmodel.edges[lindex].v[0]].position; else vec = loadmodel.vertexes[loadmodel.edges[-lindex].v[1]].position; Math3D.VectorCopy(vec, verts[numverts]); numverts++; } SubdividePolygon(numverts, verts); } // ========================================================= //// speed up sin calculations - Ed // float r_turbsin[] = // { // #include "warpsin.h" // }; static final float TURBSCALE = (float)(256.0f / (2 * Math.PI)); /* ============= EmitWaterPolys Does a water warp on the pre-fragmented glpoly_t chain ============= */ void EmitWaterPolys(msurface_t fa) { glpoly_t p, bp; float[] v; int i; float s = 0; float t = 0; float os, ot; float scroll; float rdt = r_newrefdef.time; if ((fa.texinfo.flags & Defines.SURF_FLOWING) != 0) scroll = -64 * ( (r_newrefdef.time*0.5f) - (int)(r_newrefdef.time*0.5f) ); else scroll = 0; int index; FloatBuffer texCoord = globalPolygonInterleavedBuf; for (bp=fa.polys ; bp != null ; bp=bp.next) { p = bp; index = p.pos * POLYGON_STRIDE; for (i=0; i<p.numverts ; i++) { v = p.verts[i]; os = v[3]; ot = v[4]; s = os + Warp.SIN[(int)((ot * 0.125f + r_newrefdef.time) * TURBSCALE) & 255]; s += scroll; s *= (1.0f/64); t = ot + Warp.SIN[(int)((os * 0.125f + rdt) * TURBSCALE) & 255]; t *= (1.0f/64); texCoord.put(index, s); texCoord.put(index + 1, t); index += POLYGON_STRIDE; } gl.glDrawArrays(GL11.GL_TRIANGLE_FAN, p.pos, p.numverts); } } // =================================================================== float[][] skyclip = { { 1, 1, 0}, { 1, -1, 0}, { 0, -1, 1}, { 0, 1, 1}, { 1, 0, 1}, {-1, 0, 1} }; int c_sky; // 1 = s, 2 = t, 3 = 2048 int[][] st_to_vec = { {3,-1,2}, {-3,1,2}, {1,3,2}, {-1,-3,2}, {-2,-1,3}, // 0 degrees yaw, look straight up {2,-1,-3} // look straight down }; int[][] vec_to_st = { {-2,3,1}, {2,3,-1}, {1,3,2}, {-1,3,-2}, {-2,-1,3}, {-2,1,-3} }; float[][] skymins = new float[2][6]; float[][] skymaxs = new float[2][6]; float sky_min, sky_max; void DrawSkyPolygon (int nump, float[][] vecs) { int i,j; float[] v = {0, 0, 0}; float[] av = {0, 0, 0}; float s, t, dv; int axis; float[] vp; c_sky++; // decide which face it maps to Math3D.VectorCopy(Globals.vec3_origin, v); for (i=0; i<nump ; i++) { Math3D.VectorAdd(vecs[i], v, v); } av[0] = Math.abs(v[0]); av[1] = Math.abs(v[1]); av[2] = Math.abs(v[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]) { if (v[1] < 0) axis = 3; else axis = 2; } else { if (v[2] < 0) axis = 5; else axis = 4; } // project new texture coords for (i=0 ; i<nump ; i++) { j = vec_to_st[axis][2]; if (j > 0) dv = vecs[i][j - 1]; else dv = -vecs[i][-j - 1]; if (dv < 0.001f) continue; // don't divide by zero j = vec_to_st[axis][0]; if (j < 0) s = -vecs[i][-j -1] / dv; else s = vecs[i][j-1] / dv; j = vec_to_st[axis][1]; if (j < 0) t = -vecs[i][-j -1] / dv; else t = vecs[i][j-1] / dv; if (s < skymins[0][axis]) skymins[0][axis] = s; if (t < skymins[1][axis]) skymins[1][axis] = t; if (s > skymaxs[0][axis]) skymaxs[0][axis] = s; if (t > skymaxs[1][axis]) skymaxs[1][axis] = t; } } static final float ON_EPSILON = 0.1f; // point on plane side epsilon static final int MAX_CLIP_VERTS = 64; static final int SIDE_BACK = 1; static final int SIDE_FRONT = 0; static final int SIDE_ON = 2; float[] dists = new float[MAX_CLIP_VERTS]; int[] sides = new int[MAX_CLIP_VERTS]; float[][][][] newv = new float[6][2][MAX_CLIP_VERTS][3]; void ClipSkyPolygon(int nump, float[][] vecs, int stage) { float[] norm; float[] v; boolean front, back; float d, e; int[] newc = { 0, 0 }; int i, j; if (nump > MAX_CLIP_VERTS-2) Com.Error(Defines.ERR_DROP, "ClipSkyPolygon: MAX_CLIP_VERTS"); if (stage == 6) { // fully clipped, so draw it DrawSkyPolygon(nump, vecs); return; } front = back = false; norm = skyclip[stage]; for (i=0 ; i<nump ; i++) { d = Math3D.DotProduct(vecs[i], norm); if (d > ON_EPSILON) { front = true; sides[i] = SIDE_FRONT; } else if (d < -ON_EPSILON) { back = true; sides[i] = SIDE_BACK; } else sides[i] = SIDE_ON; dists[i] = d; } if (!front || !back) { // not clipped ClipSkyPolygon (nump, vecs, stage+1); return; } // clip it sides[i] = sides[0]; dists[i] = dists[0]; Math3D.VectorCopy(vecs[0], vecs[i]); newc[0] = newc[1] = 0; for (i=0; i<nump ; i++) { v = vecs[i]; switch (sides[i]) { case SIDE_FRONT: Math3D.VectorCopy(v, newv[stage][0][newc[0]]); newc[0]++; break; case SIDE_BACK: Math3D.VectorCopy(v, newv[stage][1][newc[1]]); newc[1]++; break; case SIDE_ON: Math3D.VectorCopy(v, newv[stage][0][newc[0]]); newc[0]++; Math3D.VectorCopy (v, newv[stage][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++) { e = v[j] + d * (vecs[i + 1][j] - v[j]); newv[stage][0][newc[0]][j] = e; newv[stage][1][newc[1]][j] = e; } newc[0]++; newc[1]++; } // continue ClipSkyPolygon(newc[0], newv[stage][0], stage+1); ClipSkyPolygon(newc[1], newv[stage][1], stage+1); } float[][] verts = new float[MAX_CLIP_VERTS][3]; /* ================= R_AddSkySurface ================= */ void R_AddSkySurface(msurface_t fa) { int i; glpoly_t p; // calculate vertex values for sky box for (p=fa.polys ; p != null ; p=p.next) { for (i=0 ; i < p.numverts ; i++) { Math3D.VectorSubtract(p.verts[i], r_origin, verts[i]); } ClipSkyPolygon (p.numverts, verts, 0); } } /* ============== R_ClearSkyBox ============== */ void R_ClearSkyBox() { int 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) { float[] v = {0, 0, 0}; float[] b = {0, 0, 0}; int j, k; b[0] = s*2300; b[1] = t*2300; b[2] = 2300; for (j=0 ; j<3 ; j++) { k = st_to_vec[axis][j]; if (k < 0) v[j] = -b[-k - 1]; else v[j] = b[k - 1]; } // avoid bilerp seam s = (s + 1) * 0.5f; t = (t + 1) * 0.5f; if (s < sky_min) s = sky_min; else if (s > sky_max) s = sky_max; if (t < sky_min) t = sky_min; else if (t > sky_max) t = sky_max; t = 1.0f - t; gl.glTexCoord2f (s, t); gl.glVertex3f(v[0], v[1], v[2]); } /* ============== R_DrawSkyBox ============== */ int[] skytexorder = {0,2,1,3,4,5}; void R_DrawSkyBox() { int i; if (skyrotate != 0) { // check for no sky at all for (i=0 ; i<6 ; i++) if (skymins[0][i] < skymaxs[0][i] && skymins[1][i] < skymaxs[1][i]) break; if (i == 6) return; // nothing visible } gl.glPushMatrix (); gl.glTranslatef (r_origin[0], r_origin[1], r_origin[2]); gl.glRotatef (r_newrefdef.time * skyrotate, skyaxis[0], skyaxis[1], skyaxis[2]); for (i=0 ; i<6 ; i++) { if (skyrotate != 0) { // hack, forces full sky to draw when rotating skymins[0][i] = -1; skymins[1][i] = -1; skymaxs[0][i] = 1; skymaxs[1][i] = 1; } if (skymins[0][i] >= skymaxs[0][i] || skymins[1][i] >= skymaxs[1][i]) continue; GL_Bind(sky_images[skytexorder[i]].texnum); gl.glBegin(GL11.GL_QUADS); MakeSkyVec(skymins[0][i], skymins[1][i], i); MakeSkyVec(skymins[0][i], skymaxs[1][i], i); MakeSkyVec(skymaxs[0][i], skymaxs[1][i], i); MakeSkyVec(skymaxs[0][i], skymins[1][i], i); gl.glEnd (); } gl.glPopMatrix (); } /* ============ R_SetSky ============ */ // 3dstudio environment map names String[] suf = {"rt", "bk", "lf", "ft", "up", "dn"}; protected void R_SetSky(String name, float rotate, float[] axis) { assert (axis.length == 3) : "vec3_t bug"; int i; String pathname; // strncpy (skyname, name, sizeof(skyname)-1); skyname = name; skyrotate = rotate; Math3D.VectorCopy(axis, skyaxis); for (i=0 ; i<6 ; i++) { // chop down rotating skies for less memory if (gl_skymip.value != 0 || skyrotate != 0) gl_picmip.value++; if ( qglColorTableEXT && gl_ext_palettedtexture.value != 0) { // Com_sprintf (pathname, sizeof(pathname), "env/%s%s.pcx", skyname, suf[i]); pathname = "env/" + skyname + suf[i] + ".pcx"; } else { // Com_sprintf (pathname, sizeof(pathname), "env/%s%s.tga", skyname, suf[i]); pathname = "env/" + skyname + suf[i] + ".tga"; } sky_images[i] = GL_FindImage(pathname, it_sky); if (sky_images[i] == null) sky_images[i] = r_notexture; if (gl_skymip.value != 0 || skyrotate != 0) { // take less memory gl_picmip.value--; sky_min = 1.0f / 256; sky_max = 255.0f / 256; } else { sky_min = 1.0f / 512; sky_max = 511.0f / 512; } } } } --- NEW FILE: Anorms.java --- /* * Anorms.java * Copyright (C) 2003 * * $Id: Anorms.java,v 1.1.2.1 2004/12/13 21:40:45 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. 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 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.render.lwjgl; /** * Anorms * * @author cwei */ public interface Anorms { final float[][] VERTEXNORMALS = { {-0.525731f, 0.000000f, 0.850651f}, {-0.442863f, 0.238856f, 0.864188f}, {-0.295242f, 0.000000f, 0.955423f}, {-0.309017f, 0.500000f, 0.809017f}, {-0.162460f, 0.262866f, 0.951056f}, {0.000000f, 0.000000f, 1.000000f}, {0.000000f, 0.850651f, 0.525731f}, {-0.147621f, 0.716567f, 0.681718f}, {0.147621f, 0.716567f, 0.681718f}, {0.000000f, 0.525731f, 0.850651f}, {0.309017f, 0.500000f, 0.809017f}, {0.525731f, 0.000000f, 0.850651f}, {0.295242f, 0.000000f, 0.955423f}, {0.442863f, 0.238856f, 0.864188f}, {0.162460f, 0.262866f, 0.951056f}, {-0.681718f, 0.147621f, 0.716567f}, {-0.809017f, 0.309017f, 0.500000f}, {-0.587785f, 0.425325f, 0.688191f}, {-0.850651f, 0.525731f, 0.000000f}, {-0.864188f, 0.442863f, 0.238856f}, {-0.716567f, 0.681718f, 0.147621f}, {-0.688191f, 0.587785f, 0.425325f}, {-0.500000f, 0.809017f, 0.309017f}, {-0.238856f, 0.864188f, 0.442863f}, {-0.425325f, 0.688191f, 0.587785f}, {-0.716567f, 0.681718f, -0.147621f}, {-0.500000f, 0.809017f, ... [truncated message content] |