📄 surf.java
字号:
float intens; // // go back to the world matrix // gl.glLoadMatrixf(r_world_matrix); gl.glEnable (GL.GL_BLEND); GL_TexEnv(GL.GL_MODULATE ); // the textures are prescaled up for a better lighting range, // so scale it back down intens = gl_state.inverse_intensity; for (s=r_alpha_surfaces ; s != null ; s=s.texturechain) { GL_Bind(s.texinfo.image.texnum); c_brush_polys++; if ((s.texinfo.flags & Defines.SURF_TRANS33) != 0) gl.glColor4f (intens, intens, intens, 0.33f); else if ((s.texinfo.flags & Defines.SURF_TRANS66) != 0) gl.glColor4f (intens, intens, intens, 0.66f); else gl.glColor4f (intens,intens,intens,1); if ((s.flags & Defines.SURF_DRAWTURB) != 0) EmitWaterPolys(s); else if((s.texinfo.flags & Defines.SURF_FLOWING) != 0) // PGM 9/16/98 DrawGLFlowingPoly (s); // PGM else DrawGLPoly (s.polys); } GL_TexEnv( GL.GL_REPLACE ); gl.glColor4f (1,1,1,1); gl.glDisable (GL.GL_BLEND); r_alpha_surfaces = null; } /* ================ DrawTextureChains ================ */ void DrawTextureChains() { int i; msurface_t s; image_t image; c_visible_textures = 0; if ( !qglSelectTextureSGIS && !qglActiveTextureARB ) { for (i = 0; i < numgltextures ; i++) { image = gltextures[i]; if (image.registration_sequence == 0) continue; s = image.texturechain; if (s == null) continue; c_visible_textures++; for ( ; s != null ; s=s.texturechain) R_RenderBrushPoly(s); image.texturechain = null; } } else { for (i = 0; i < numgltextures ; i++) { image = gltextures[i]; if (image.registration_sequence == 0) continue; if (image.texturechain == null) continue; c_visible_textures++; for ( s = image.texturechain; s != null ; s=s.texturechain) { if ( ( s.flags & Defines.SURF_DRAWTURB) == 0 ) R_RenderBrushPoly(s); } } GL_EnableMultitexture( false ); for (i = 0; i < numgltextures ; i++) { image = gltextures[i]; if (image.registration_sequence == 0) continue; s = image.texturechain; if (s == null) continue; for ( ; s != null ; s=s.texturechain) { if ( (s.flags & Defines.SURF_DRAWTURB) != 0 ) R_RenderBrushPoly(s); } image.texturechain = null; } } GL_TexEnv( GL.GL_REPLACE ); } // direct buffer private IntBuffer temp = Lib.newIntBuffer(128 * 128, ByteOrder.LITTLE_ENDIAN); void GL_RenderLightmappedPoly( msurface_t surf ) { int i, nv = surf.polys.numverts; int map = 0; float[] v; image_t image = R_TextureAnimation( surf.texinfo ); boolean is_dynamic = false; int lmtex = surf.lightmaptexturenum; glpoly_t p; // ersetzt goto boolean gotoDynamic = false; for ( map = 0; map < Defines.MAXLIGHTMAPS && (surf.styles[map] != (byte)255); map++ ) { if ( r_newrefdef.lightstyles[surf.styles[map] & 0xFF].white != surf.cached_light[map] ) { gotoDynamic = true; break; } } // this is a hack from cwei if (map == 4) map--; // dynamic this frame or dynamic previously if ( gotoDynamic || ( surf.dlightframe == r_framecount ) ) { // label dynamic: if ( gl_dynamic.value != 0 ) { if ( (surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP )) == 0 ) { is_dynamic = true; } } } if ( is_dynamic ) { // ist raus gezogen worden int[] temp = new int[128*128]; int smax, tmax; if ( ( (surf.styles[map] & 0xFF) >= 32 || surf.styles[map] == 0 ) && ( surf.dlightframe != r_framecount ) ) { smax = (surf.extents[0]>>4)+1; tmax = (surf.extents[1]>>4)+1; R_BuildLightMap( surf, temp, smax); R_SetCacheState( surf ); GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + surf.lightmaptexturenum ); lmtex = surf.lightmaptexturenum; gl.glTexSubImage2D( GL.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax, GL_LIGHTMAP_FORMAT, GL.GL_UNSIGNED_BYTE, temp ); } else { smax = (surf.extents[0]>>4)+1; tmax = (surf.extents[1]>>4)+1; R_BuildLightMap( surf, temp, smax); GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + 0 ); lmtex = 0; gl.glTexSubImage2D( GL.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax, GL_LIGHTMAP_FORMAT, GL.GL_UNSIGNED_BYTE, temp ); } c_brush_polys++; GL_MBind( GL_TEXTURE0, image.texnum ); GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + lmtex ); // ========== // PGM if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0) { float scroll; scroll = -64 * ( (r_newrefdef.time / 40.0f) - (int)(r_newrefdef.time / 40.0f) ); if(scroll == 0.0f) scroll = -64.0f; for ( p = surf.polys; p != null; p = p.chain ) { gl.glBegin (GL.GL_POLYGON); for (i=0 ; i< nv; i++) { gl.glMultiTexCoord2fARB(GL_TEXTURE0, p.s1(i) + scroll, p.t1(i)); gl.glMultiTexCoord2fARB(GL_TEXTURE1, p.s2(i), p.t2(i)); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3] + scroll, v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); gl.glVertex3f(p.x(i), p.y(i), p.z(i)); } gl.glEnd (); } } else { for ( p = surf.polys; p != null; p = p.chain ) { gl.glBegin (GL.GL_POLYGON); for (i=0 ; i< nv; i++) { gl.glMultiTexCoord2fARB(GL_TEXTURE0, p.s1(i), p.t1(i)); gl.glMultiTexCoord2fARB(GL_TEXTURE1, p.s2(i), p.t2(i)); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); gl.glVertex3f(p.x(i), p.y(i), p.z(i)); } gl.glEnd (); } } // PGM // ========== } else { c_brush_polys++; GL_MBind( GL_TEXTURE0, image.texnum ); GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + lmtex); // ========== // PGM if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0) { float scroll; scroll = -64 * ( (r_newrefdef.time / 40.0f) - (int)(r_newrefdef.time / 40.0f) ); if(scroll == 0.0) scroll = -64.0f; for ( p = surf.polys; p != null; p = p.chain ) { gl.glBegin(GL.GL_POLYGON); for (i=0 ; i< nv; i++) { gl.glMultiTexCoord2fARB(GL_TEXTURE0, p.s1(i) + scroll, p.t1(i)); gl.glMultiTexCoord2fARB(GL_TEXTURE1, p.s2(i), p.t2(i)); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3] + scroll, v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); gl.glVertex3f(p.x(i), p.y(i), p.z(i)); } gl.glEnd(); } } else { // PGM // ========== for ( p = surf.polys; p != null; p = p.chain ) { gl.glBegin (GL.GL_POLYGON); for (i=0 ; i< nv; i++) { gl.glMultiTexCoord2fARB(GL_TEXTURE0, p.s1(i), p.t1(i)); gl.glMultiTexCoord2fARB(GL_TEXTURE1, p.s2(i), p.t2(i)); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); gl.glVertex3f(p.x(i), p.y(i), p.z(i)); } gl.glEnd (); } // ========== // PGM } // PGM // ========== } } /* ================= R_DrawInlineBModel ================= */ void R_DrawInlineBModel() { int i, k; cplane_t pplane; float dot; msurface_t psurf; dlight_t lt; // calculate dynamic lighting for bmodel if ( gl_flashblend.value == 0 ) { for (k=0 ; k<r_newrefdef.num_dlights ; k++) { lt = r_newrefdef.dlights[k]; R_MarkLights(lt, 1<<k, currentmodel.nodes[currentmodel.firstnode]); } } // psurf = ¤tmodel->surfaces[currentmodel->firstmodelsurface]; int psurfp = currentmodel.firstmodelsurface; msurface_t[] surfaces; surfaces = currentmodel.surfaces; //psurf = surfaces[psurfp]; if ( (currententity.flags & Defines.RF_TRANSLUCENT) != 0 ) { gl.glEnable (GL.GL_BLEND); gl.glColor4f (1,1,1,0.25f); GL_TexEnv( GL.GL_MODULATE ); } // // draw texture // for (i=0 ; i<currentmodel.nummodelsurfaces ; i++) { psurf = surfaces[psurfp++]; // find which side of the node we are on pplane = psurf.plane; dot = Math3D.DotProduct(modelorg, pplane.normal) - pplane.dist; // draw the polygon if (((psurf.flags & Defines.SURF_PLANEBACK) != 0 && (dot < -BACKFACE_EPSILON)) || ((psurf.flags & Defines.SURF_PLANEBACK) == 0 && (dot > BACKFACE_EPSILON))) { if ((psurf.texinfo.flags & (Defines.SURF_TRANS33 | Defines.SURF_TRANS66)) != 0 ) { // add to the translucent chain psurf.texturechain = r_alpha_surfaces; r_alpha_surfaces = psurf; } else if ( qglMTexCoord2fSGIS && ( psurf.flags & Defines.SURF_DRAWTURB ) == 0 ) { GL_RenderLightmappedPoly( psurf ); } else { GL_EnableMultitexture( false ); R_RenderBrushPoly( psurf ); GL_EnableMultitexture( true ); } } } if ( (currententity.flags & Defines.RF_TRANSLUCENT) == 0 ) { if ( !qglMTexCoord2fSGIS ) R_BlendLightmaps(); } else { gl.glDisable (GL.GL_BLEND); gl.glColor4f (1,1,1,1); GL_TexEnv( GL.GL_REPLACE ); } } /* ================= R_DrawBrushModel ================= */ void R_DrawBrushModel(entity_t e) { float[] mins = {0, 0, 0}; float[] maxs = {0, 0, 0}; int i; boolean rotated; if (currentmodel.nummodelsurfaces == 0) return; currententity = e; gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1; if (e.angles[0] != 0 || e.angles[1] != 0 || e.angles[2] != 0) { rotated = true; for (i=0 ; i<3 ; i++) { mins[i] = e.origin[i] - currentmodel.radius; maxs[i] = e.origin[i] + currentmodel.radius; //System.out.println("rotate: " + Lib.vtos(mins) + " " + Lib.vtos(maxs)); } } else { rotated = false; Math3D.VectorAdd(e.origin, currentmodel.mins, mins); Math3D.VectorAdd(e.origin, currentmodel.maxs, maxs); //System.out.println(" " + Lib.vtos(mins) + " " + Lib.vtos(maxs)); } if (R_CullBox(mins, maxs)) { //System.out.println("origin " + Lib.vtos(e.origin) + " +++ " + Lib.vtos(currentmodel.mins)); return; } gl.glColor3f (1,1,1); // memset (gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces)); gl_lms.clearLightmapSurfaces(); Math3D.VectorSubtract (r_newrefdef.vieworg, e.origin, modelorg); if (rotated) { float[] temp = {0, 0, 0}; float[] forward = {0, 0, 0}; float[] right = {0, 0, 0}; float[] up = {0, 0, 0}; Math3D.VectorCopy (modelorg, temp); Math3D.AngleVectors (e.angles, forward, right, up); modelorg[0] = Math3D.DotProduct (temp, forward); modelorg[1] = -Math3D.DotProduct (temp, right); modelorg[2] = Math3D.DotProduct (temp, up); } gl.glPushMatrix(); e.angles[0] = -e.angles[0]; // stupid quake bug e.angles[2] = -e.angles[2]; // stupid quake bug R_RotateForEntity(e); e.angles[0] = -e.angles[0]; // stupid quake bug e.angles[2] = -e.angles[2]; // stupid quake bug GL_EnableMultitexture( true ); GL_SelectTexture(GL_TEXTURE0); GL_TexEnv( GL.GL_REPLACE ); GL_SelectTexture(GL_TEXTURE1); GL_TexEnv( GL.GL_MODULATE ); R_DrawInlineBModel(); GL_EnableMultitexture( false ); gl.glPopMatrix(); } /* ============================================================= WORLD MODEL ============================================================= */ /* ================ R_RecursiveWorldNode ================ */ void R_RecursiveWorldNode (mnode_t node) { int c, side, sidebit; cplane_t plane; msurface_t surf; msurface_t mark; mleaf_t pleaf; float dot = 0; image_t image; if (node.contents == Defines.CONTENTS_SOLID) return; // solid if (node.visframe != r_visframecount) return; if (R_CullBox(node.mins, node.maxs)) return; // if a leaf node, draw stuff if (node.contents != -1) { pleaf = (mleaf_t)node; // check for door connected areas if (r_newrefdef.areabits != null) { if ( ((r_newrefdef.areabits[pleaf.area >> 3] & 0xFF) & (1 << (pleaf.area & 7)) ) == 0 ) return; // not visible } int markp = 0; mark = pleaf.getMarkSurface(markp); // first marked surface c = pleaf.nummarksurfaces; if (c != 0) { do { mark.visframe = r_framecount; mark = pleaf.getMarkSurface(++markp); // next surface } while (--c != 0); } return; } // node is just a decision point, so go down the apropriate sides // find which side of the node we are on plane = node.plane; switch (plane.type) { case Defines.PLANE_X: dot = modelorg[0] - plane.dist; break; case Defines.PLANE_Y: dot = modelorg[1] - plane.dist; break; case Defines.PLANE_Z: dot = modelorg[2] - plane.dist; break; default: dot = Math3D.DotProduct(modelorg, plane.normal) - plane.dist; break; } if (dot >= 0.0f) { side = 0; sidebit = 0; } else { side = 1; sidebit = Defines.SURF_PLANEBACK; } // recurse down the children, front side first R_RecursiveWorldNode(node.children[side]); // draw stuff //for ( c = node.numsurfaces, surf = r_worldmodel.surfaces[node.firstsurface]; c != 0 ; c--, surf++) for ( c = 0; c < node.numsurfaces; c++) { surf = r_worldmodel.surfaces[node.firstsurface + c];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -