ofs := ScaleVector(move.extents, -1);
      //ofs := InvertVector(move.BBsize);
      if (plane.normal.x < 0) then
        ofs.x := -ofs.x;

      if (plane.normal.y < 0) then
        ofs.y := -ofs.y;

      if (plane.normal.z < 0) then
        ofs.z := -ofs.z;

      dist := plane.d - DotProduct(ofs, plane.normal);
      d1 := DotProduct(move.startPoint, plane.normal) - dist;
      d2 := DotProduct(move.endPoint, plane.normal) - dist;

      if (d1 >= -DIST_EPSILON) then
        startOut := true;
      if (d2 >= -DIST_EPSILON) then
        endOut := true;

      if (d2 > 0) then
        endOut := true;
      if (d1 > 0) then
        startOut := true;

      // Both in front of face : outside this brush
      if ((d1 > 0) AND (d2 >= d1)) then begin
        fullOut := true;
        break;
      end;

      // Both behind the face : will get clipped by another plane
      if ((d1 <= 0) AND (d2 <= 0)) then
        continue;

      //float f;
      if (d1 > d2) then begin // Entering the brush
        f := (d1 - DIST_EPSILON) / (d1 - d2);
        if (f > enterf) then begin
          enterf := f;
          hitNormal := plane.normal;
        end;
      end
      else begin
        f := (d1 + DIST_EPSILON) / (d1 - d2);
        if (f < exitf) then
          exitf := f;
      end;
    end; // while sc


    if (not fullOut) then begin
      if ((not startOut) and (not endOut)) then begin
        move.fraction := 0;
        //move.leafIndex := leafIndex;
        nextLeaf := leafIndex;
        move.allSolid := true;
        move.brush := bi;
        move.normal := hitNormal;
        exit;
      end;

      if (enterf < exitf) then begin
        if (enterf > -1) and (enterf < move.fraction) then begin
          if (enterf < 0) then
            enterf := 0;
          move.fraction := enterf;
          move.normal := hitNormal;
          move.brush := bi;
        end;
      end;
    end;

    // Already fully blocked
    if (move.fraction = 0) then
      exit;

  end; // while bc
end;
(*
// Walk through the leaf and sort the faces
procedure TQuake3BSP.WalkLeaf(leafIndex : integer;  sort : boolean);
var faceCount, faceIndex, shaderId, FogShader : integer;
    distance : single;
    facePoint : TVector3f;
    texInfo : TBSPTextureInfo;
    i : integer;
    y1, y2 : single;
begin
  fogShader := -1;
  for faceCount := 0 to Leafs[leafIndex].numOfLeafFaces - 1 do begin
    faceIndex := LeafFaces[Leafs[leafIndex].leafface + FaceCount];
    if IsModelFace[faceIndex] then
      continue;

    if sort then begin
      facePoint.x := CenterPoints[faceIndex].x  - Camera.Position.x;
      facePoint.y := CenterPoints[faceIndex].y  - Camera.Position.y;
      facePoint.z := CenterPoints[faceIndex].z  - Camera.Position.z;
      distance := sqrt(facePoint.x*facePoint.x + facePoint.y*facePoint.y + facePoint.z*facePoint.z);
      if distance < 0 then
        distance := abs(distance);
    end
    else
      distance := 0;

    if not FacesDrawn[faceIndex] then begin

      shaderId :=TextureInfo[Faces[FaceIndex].textureID].ShaderId;
      if  shaderId > -1 then begin
{        if shaderManager[shaderId].hasFog then begin
          //currentFog := shaderId;  // remember fog
          continue; // fog faces are invisible
        end;
}
        if (ShaderManager[shaderId].Surface and 2048) =  2048 then continue; // nodraw

        if ShaderManager[shaderId].IsSkyBox then begin
          skyboxRequired := true;
          continue;
        end;

        if (ShaderManager[shaderId].Cull = GL_NONE) or (ShaderManager[shaderId].TotallyTrans) or (shaderManager[shaderId].hasFog) then begin
          TransparentFaces[numTransparent].FaceIndex := faceIndex;
          TransparentFaces[numTransparent].distance  := distance;
          inc(numTransparent);
        end
        else begin
          AdditiveFaces[numAdditive].FaceIndex := faceIndex;
          AdditiveFaces[numAdditive].distance := distance;
          inc(numAdditive);
        end;
      end
      else begin
{        id := Faces[faceIndex].textureID;
        if id > 0 then begin
          texInfo := TextureInfo[Faces[faceIndex].textureID];
          if (texInfo.contents and CONTENTS_FOG) = CONTENTS_FOG then begin
            currentFog := currentFog;
          end;
        end;}
        SolidFaces[numSolid].FaceIndex := faceIndex;
        SolidFaces[numSolid].distance := distance;
        inc(numSolid);
      end;

    FacesDrawn[FaceIndex] := true;
    inc(VisibleTriangles, Faces[faceIndex].numMeshVerts div 3);
    end;
  end; // faceCount
end;
*)
{
procedure TQuake3BSP.SetDefaults;
begin
  glDepthFunc(GL_LEQUAL);
  glEnable(GL_DEPTH_TEST);
  glDisable(GL_ALPHA_TEST);
  glDepthMask(true);
  glDisable(GL_BLEND);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

  //  glDisable(GL_COLOR);
  if MultiTexture then begin
    glActiveTextureARB(GL_TEXTURE1_ARB);
    glDisableClientState(GL_COLOR_ARRAY);
    glActiveTextureARB(GL_TEXTURE0_ARB);
  end;
  glDisableClientState(GL_COLOR_ARRAY);
  glColor3ub(255,255,255);
  glCullFace(GL_FRONT);
  glEnable(GL_CULL_FACE);
end;
}
(*
procedure TQuake3BSP.SetVertexCoords(shaderId, numOfVerts : integer);
var shader : TShader;
    i, j, nv : integer;
    args : TWaveFunc;
    startoff, off, wavesize, inc : single;
    p, v, middle, d, h : TVector3f;
    st : TVector2f;
const speed = 2.0;
begin
  shader := FShaderManager[shaderId];
  if shader.numOfDeformVertexes > 0 then begin
    startoff := 0;
    wavesize := 1;
    for i := 0 to shader.numOfDeformVertexes-1 do begin
      case shader.DeformVertexes[i].deformType of
        DEFORMVERTEXES_WAVE :
          begin
            args.func := enWave(trunc(shader.DeformVertexes[i].values[1]));
            args.base := shader.DeformVertexes[i].values[2];
            args.amp  := shader.DeformVertexes[i].values[3];
            wavesize := shader.DeformVertexes[i].values[0];
            startoff := shader.DeformVertexes[i].values[4];
            args.freq := shader.DeformVertexes[i].values[5];
            nv := numOfVerts;
            for j := 0 to numOfVerts-1 do begin
              v := inputBuffer[j].normal;
