⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gl_rsurf.pas

📁 雷神之锤2(Quake2)Delphi源码
💻 PAS
📖 第 1 页 / 共 4 页
字号:
(*Y                v := p.verts[0];
                qglBegin (GL_POLYGON);
{Y}                  for (i=0 ; i< nv; i++, v+= VERTEXSIZE)
                  begin
                        qglMTexCoord2fSGIS (GL_TEXTURE0_SGIS, (v[3]+scroll), v[4]);
                        qglMTexCoord2fSGIS (GL_TEXTURE1_SGIS, v[5], v[6]);
                        qglVertex3fv (v);
                  end;//for???*)
                qglEnd ();

          p := p.chain;
        end;//for???
      end
      else begin
//PGM
//==========
//{Y}        for ( p = surf->polys; p; p = p->chain )
        p := surf.polys;
        while p <> Nil do
        begin
(*Y                v := p.verts[0];
                qglBegin (GL_POLYGON);
{Y}                  for (i=0 ; i< nv; i++, v+= VERTEXSIZE)
                  begin
                        qglMTexCoord2fSGIS (GL_TEXTURE0_SGIS, v[3], v[4]);
                        qglMTexCoord2fSGIS (GL_TEXTURE1_SGIS, v[5], v[6]);
                        qglVertex3fv (v);

                  end;//for???*)
                qglEnd ();

          p := p.chain;
        end;//for???
//==========
//PGM
      end;//else
//PGM
//==========
   end;//else
end;//procedure

{*
=================
R_DrawInlineBModel
=================
*}
procedure R_DrawInlineBModel;
var
  i, k   : integer;
  pplane : cplane_p;
  dot    : float;
  psurf  : msurface_p;
  lt     : dlight_p;
begin
  // calculate dynamic lighting for bmodel
  if (gl_flashblend.value = 0) then
  begin
    lt := r_newrefdef.dlights;
(*Y{Y}    for (k=0 ; k<r_newrefdef.num_dlights ; k++, lt++)
     begin
          R_MarkLights (lt, 1 SHL k, currentmodel.nodes + currentmodel.firstnode);
     end;//for???*)
  end;

  psurf := currentmodel.surfaces[currentmodel.firstmodelsurface];

  if (currententity.flags AND RF_TRANSLUCENT) <> 0 then
  begin
    qglEnable (GL_BLEND);
    qglColor4f (1,1,1,0.25);
    GL_TexEnv (GL_MODULATE);
  end;

  //
  // draw texture
  //
//Y{Y}  for (i=0 ; i<currentmodel->nummodelsurfaces ; i++, psurf++)
  begin
  // find which side of the node we are on
        pplane := psurf.plane;

        dot := DotProduct (modelorg, pplane.normal) - pplane.dist;

// draw the polygon
{        if ((   (psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
              (!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) then}
        if ( ( ((psurf.flags AND SURF_PLANEBACK) <> 0) AND (dot < -BACKFACE_EPSILON)) OR
             ( ((psurf.flags AND SURF_PLANEBACK) = 0)  AND (dot >  BACKFACE_EPSILON)) ) then
        begin
//              if (psurf.texinfo.flags & (SURF_TRANS33|SURF_TRANS66) )
              if (psurf.texinfo.flags AND (SURF_TRANS33 OR SURF_TRANS66) <> 0)
              then begin
                // add to the translucent chain
                psurf.texturechain := r_alpha_surfaces;
                r_alpha_surfaces := psurf;
              end
              else
//                if ( qglMTexCoord2fSGIS && !( psurf.flags & SURF_DRAWTURB ) )
                if ( (*Y Assigned(qglMTexCoord2fSGIS) AND*) ((psurf.flags AND SURF_DRAWTURB) = 0) )
                then GL_RenderLightmappedPoly (psurf)
                else begin
                  GL_EnableMultitexture (false);
                  R_RenderBrushPoly (psurf);
                  GL_EnableMultitexture (true);
                end;
        end;//if
  end;//for???*)

//  if ( !(currententity.flags & RF_TRANSLUCENT) )
  if ((currententity.flags AND RF_TRANSLUCENT) = 0)
  then begin
(*Y    if NOT Assigned(qglMTexCoord2fSGIS) then
      R_BlendLightmaps ();*)
  end
  else begin
    qglDisable (GL_BLEND);
    qglColor4f (1,1,1,1);
    GL_TexEnv (GL_REPLACE);
  end;
end;//procedure

{*
=================
R_DrawBrushModel
=================
*}
procedure R_DrawBrushModel (e : entity_p); //for gl_rmain
var
  i          : integer;
  rotated    : qboolean;
  mins, maxs,
  temp,
  forward_,
  right, up  : vec3_t;
begin
  if (currentmodel.nummodelsurfaces = 0) then
    Exit;

  currententity := e;
  gl_state.currenttextures[0] := -1;
  gl_state.currenttextures[1] := -1;

//  if (e.angles[0] || e.angles[1] || e->angles[2])
  if (e.angles[0] <> 0) OR (e.angles[1] <> 0) OR (e.angles[2] <> 0) //"e.angles" -OR- "e.angles <> 0"
  then begin
    rotated := true;
    for i:=0 to 2 do
    begin
      mins[i] := e.origin[i] - currentmodel.radius;
      maxs[i] := e.origin[i] + currentmodel.radius;
    end;
  end
  else begin
    rotated := false;
    VectorAdd (@e.origin, currentmodel.mins, mins);
    VectorAdd (@e.origin, currentmodel.maxs, maxs);
  end;

  if (R_CullBox (mins, maxs)) then
    Exit;

  qglColor3f (1,1,1);
//Y  memset (gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces));

  VectorSubtract (@r_newrefdef.vieworg, @e.origin, modelorg);
  if (rotated) then
  begin
    VectorCopy (modelorg, temp);
//Y    AngleVectors (e.angles, forward_, right, up);
    modelorg[0] := DotProduct (temp, forward_);
    modelorg[1] := -DotProduct (temp, right);
    modelorg[2] := DotProduct (temp, up);
  end;

  qglPushMatrix ();
    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);
//Y    GL_SelectTexture (GL_TEXTURE0_SGIS);
    GL_TexEnv (GL_REPLACE);
//Y    GL_SelectTexture (GL_TEXTURE1_SGIS);
    GL_TexEnv (GL_MODULATE);

    R_DrawInlineBModel ();
    GL_EnableMultitexture (false);
  qglPopMatrix ();
end;//procedure

{*
=============================================================

	WORLD MODEL

=============================================================
*}

{*
================
R_RecursiveWorldNode
================
*}
procedure R_RecursiveWorldNode (node : mnode_p);
var
  c, side, sidebit : integer;
  plane : cplane_p;

//	msurface_t	*surf, **mark;
  surf  : msurface_p;//, **mark;

  pleaf : mleaf_p;
  dot   : float;
  image : image_p;
begin
  if (node.contents = CONTENTS_SOLID) then
    Exit;   // solid

  if (node.visframe <> r_visframecount) then
    Exit;
(*Y  if (R_CullBox (node.minmaxs, node.minmaxs+3)) then
    Exit;*)

// if a leaf node, draw stuff
  if (node.contents <> -1) then
  begin
    pleaf := mleaf_p(node);

    // check for door connected areas
    if (r_newrefdef.areabits <> Nil) then
//Y      if (! (r_newrefdef.areabits[pleaf.area shr 3] and (1 shl (pleaf.area & 7)) ) ) then
(*      if NOT ( (r_newrefdef.areabits[pleaf.area SHR 3]) AND (1 SHL (pleaf.area AND 7)) ) then
        Exit;	  // not visible*)

//Y    mark := pleaf.firstmarksurface;
    c := pleaf.nummarksurfaces;

(*    if (c)
    {
        do
        {
            (*mark)->visframe = r_framecount;
            mark++;
        } while (--c);
    }*)
    if (c<>0) then
      repeat
(*Y            ( *mark)->visframe := r_framecount;
            mark++;*)
        Dec(c);
      until c=0;

    Exit;
  end;//if

// node is just a decision point, so go down the apropriate sides

// find which side of the node we are on
  plane := node.plane;

(*Y  Case plane._type of
    PLANE_X: dot := modelorg[0] - plane.dist;
    PLANE_Y: dot := modelorg[1] - plane.dist;
    PLANE_Z: dot := modelorg[2] - plane.dist;

//    default:
    else     dot := DotProduct (modelorg, plane.normal) - plane.dist;

  end;*)

  if (dot >= 0)
  then begin
    side := 0;
    sidebit := 0;
  end
  else begin
    side := 1;
    sidebit := SURF_PLANEBACK;
  end;

// recurse down the children, front side first
  R_RecursiveWorldNode (node.children[side]);

  // draw stuff
//Y{Y}  for ( c = node->numsurfaces, surf = r_worldmodel->surfaces + node->firstsurface; c ; c--, surf++)
  begin
(*Y      if (surf.visframe <> r_framecount) then
        Continue;

//      if ( (surf.flags & SURF_PLANEBACK) != sidebit ) then
      if ( (surf.flags AND SURF_PLANEBACK) <> sidebit ) then
        Continue;   // wrong side*)

//      if (surf.texinfo.flags & SURF_SKY)
      if (surf.texinfo.flags AND SURF_SKY) <> 0
      then begin
      	// just adds to visible sky bounds
//Y        R_AddSkySurface (surf);
      end
      else
//        if (surf.texinfo.flags & (SURF_TRANS33|SURF_TRANS66))
        if (surf.texinfo.flags AND (SURF_TRANS33 OR SURF_TRANS66) <> 0)
        then begin
          // add to the translucent chain
          surf.texturechain := r_alpha_surfaces;
          r_alpha_surfaces := surf;
        end
        else begin
//          if ( qglMTexCoord2fSGIS && !( surf.flags & SURF_DRAWTURB ) )
(*Y          if ( Assigned(qglMTexCoord2fSGIS) AND ((surf.flags AND SURF_DRAWTURB) = 0) )
          then GL_RenderLightmappedPoly ( surf )
          else*) begin
            // the polygon is visible, so add it to the texture
            // sorted chain
            // FIXME: this is a hack for animation
            image := R_TextureAnimation (surf.texinfo);
            surf.texturechain := image.texturechain;
            image.texturechain := surf;
          end;
        end;
  end;//for???

  // recurse down the back side
//Y  R_RecursiveWorldNode (node.children[!side]);
(*Id Software /*
	for ( ; c ; c--, surf++)
	{
		if (surf->visframe != r_framecount)
			continue;

		if ( (surf->flags & SURF_PLANEBACK) != sidebit )
			continue;		// wrong side

		if (surf->texinfo->flags & SURF_SKY)
		{	// just adds to visible sky bounds
			R_AddSkySurface (surf);
		}
		else if (surf->texinfo->flags & (SURF_TRANS33|SURF_TRANS66))
		{	// add to the translucent chain
//			surf->texturechain = alpha_surfaces;
//			alpha_surfaces = surf;
		}
		else
		{
			if ( qglMTexCoord2fSGIS && !( surf->flags & SURF_DRAWTURB ) )
			{
				GL_RenderLightmappedPoly( surf );
			}
			else
			{
				// the polygon is visible, so add it to the texture
				// sorted chain
				// FIXME: this is a hack for animation
				image = R_TextureAnimation (surf->texinfo);
				surf->texturechain = image->texturechain;
				image->texturechain = surf;
			}
		}
	}
*/*)
end;//procedure

{*
=============
R_DrawWorld
=============
*}
procedure R_DrawWorld; //for gl_rmain
var
  ent :	entity_t;
begin
  if (_r_drawworld.value = 0) then
    Exit;

//  if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
  if (r_newrefdef.rdflags AND RDF_NOWORLDMODEL) <> 0 then
    Exit;

  currentmodel := r_worldmodel;

(*Y  VectorCopy (r_newrefdef.vieworg, modelorg);

  // auto cycle the world frame for texture animation
  memset (&ent, 0, sizeof(ent));*)
//  ent.frame := (int)(r_newrefdef.time*2);
  ent.frame := Trunc(r_newrefdef.time*2);
  currententity := @ent;

  gl_state.currenttextures[0] := -1;
  gl_state.currenttextures[1] := -1;

  qglColor3f (1,1,1);
(*Y  memset (gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces));
  R_ClearSkyBox ();*)

  if TRUE//Y Assigned(qglMTexCoord2fSGIS)
  then begin
    GL_EnableMultitexture (true);

//Y    GL_SelectTexture (GL_TEXTURE0_SGIS);
    GL_TexEnv (GL_REPLACE);
//Y    GL_SelectTexture (GL_TEXTURE1_SGIS);

    if (gl_lightmap.value <> 0)
    then GL_TexEnv (GL_REPLACE)
    else GL_TexEnv (GL_MODULATE);

//Y    R_RecursiveWorldNode (r_worldmodel.nodes);

    GL_EnableMultitexture (false);
  end
  else (*Y R_RecursiveWorldNode (r_worldmodel.nodes)*);

  {*
  ** theoretically nothing should happen in the next two functions
  ** if multitexture is enabled
  *}
  DrawTextureChains ();
  R_BlendLightmaps ();

//Y  R_DrawSkyBox ();

  R_DrawTriangleOutlines ();
end;//procedure

{*
===============
R_MarkLeaves

Mark the leaves and nodes that are in the PVS for the current
cluster
===============
*}
procedure R_MarkLeaves;  //for gl_rmain
var
  vis : PByte;
//	byte	fatvis[MAX_MAP_LEAFS/8];
  fatvis : array [0..MAX_MAP_LEAFS DIV 8] of byte;

  node : mnode_p;
  i, c,
  cluster : integer;
  leaf : mleaf_p;
begin
  if (r_oldviewcluster = r_viewcluster) AND (r_oldviewcluster2 = r_viewcluster2) AND
     (r_novis.value=0) AND (r_viewcluster <> -1) then
    Exit;

  // development aid to let you run around and see exactly where
  // the pvs ends
  if (gl_lockpvs.value <> 0) then
    Exit;

  Inc(r_visframecount);
  r_oldviewcluster  := r_viewcluster;
  r_oldviewcluster2 := r_viewcluster2;

  if (r_novis.value <> 0) OR (r_viewcluster = -1) (*Y OR (!r_worldmodel.vis)*) then
  begin
    // mark everything
    for i:=0 to r_worldmodel.numleafs-1 do
      r_worldmodel.leafs[i].visframe := r_visframecount;
    for i:=0 to r_worldmodel.numnodes-1 do
      r_worldmodel.nodes[i].visframe := r_visframecount;
    Exit;
  end;

  vis := Mod_ClusterPVS (r_viewcluster, r_worldmodel);
  // may have to combine two clusters because of solid water boundaries
  if (r_viewcluster2 <> r_viewcluster) then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -