internal static void RenderScene()
{
// initialize
GL.Enable(EnableCap.DepthTest);
GL.DepthMask(true);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.PushMatrix();
if (LoadTexturesImmediately == LoadTextureImmediatelyMode.NotYet)
{
LoadTexturesImmediately = LoadTextureImmediatelyMode.Yes;
ReAddObjects();
}
// setup camera
double cx = World.AbsoluteCameraPosition.X;
double cy = World.AbsoluteCameraPosition.Y;
double cz = World.AbsoluteCameraPosition.Z;
double dx = World.AbsoluteCameraDirection.X;
double dy = World.AbsoluteCameraDirection.Y;
double dz = World.AbsoluteCameraDirection.Z;
double ux = World.AbsoluteCameraUp.X;
double uy = World.AbsoluteCameraUp.Y;
double uz = World.AbsoluteCameraUp.Z;
var mat = Matrix4d.LookAt(0.0, 0.0, 0.0, dx, dy, dz, ux, uy, uz);
GL.MultMatrix(ref mat);
if (OptionLighting)
{
GL.Light(LightName.Light0, LightParameter.Position, new float[] { OptionLightPosition.X, OptionLightPosition.Y, OptionLightPosition.Z, 0.0f });
}
// render polygons
GL.Disable(EnableCap.DepthTest);
if (OptionLighting)
{
if (!LightingEnabled)
{
GL.Enable(EnableCap.Lighting);
LightingEnabled = true;
}
}
else if (LightingEnabled)
{
GL.Disable(EnableCap.Lighting);
LightingEnabled = false;
}
GL.AlphaFunc(AlphaFunction.Greater, 0.0f);
BlendEnabled = false; GL.Disable(EnableCap.Blend);
GL.Enable(EnableCap.DepthTest);
GL.DepthMask(true);
LastBoundTexture = 0;
// opaque list
if (OptionCoordinateSystem)
{
if (LightingEnabled)
{
GL.Disable(EnableCap.Lighting);
}
GL.Color3(1.0, 0.0, 0.0);
RenderBox(new World.Vector3D(0.0, 0.0, 0.0), new World.Vector3D(0.0, 0.0, 1.0), new World.Vector3D(0.0, 1.0, 0.0), new World.Vector3D(1.0, 0.0, 0.0), new World.Vector3D(100.0, 0.01, 0.01), cx, cy, cz);
GL.Color3(0.0, 1.0, 0.0);
RenderBox(new World.Vector3D(0.0, 0.0, 0.0), new World.Vector3D(0.0, 0.0, 1.0), new World.Vector3D(0.0, 1.0, 0.0), new World.Vector3D(1.0, 0.0, 0.0), new World.Vector3D(0.01, 100.0, 0.01), cx, cy, cz);
GL.Color3(0.0, 0.0, 1.0);
RenderBox(new World.Vector3D(0.0, 0.0, 0.0), new World.Vector3D(0.0, 0.0, 1.0), new World.Vector3D(0.0, 1.0, 0.0), new World.Vector3D(1.0, 0.0, 0.0), new World.Vector3D(0.01, 0.01, 100.0), cx, cy, cz);
if (LightingEnabled)
{
GL.Enable(EnableCap.Lighting);
}
}
for (int i = 0; i < OpaqueListCount; i++)
{
RenderFace(ref OpaqueList[i], cx, cy, cz);
}
// transparent color list
if (TransparentColorDepthSorting) {
SortPolygons(TransparentColorList, TransparentColorListCount, TransparentColorListDistance, 1, 0.0);
BlendEnabled = true; GL.Enable(EnableCap.Blend);
for (int i = 0; i < TransparentColorListCount; i++) {
GL.DepthMask(false);
SetAlphaFunc(AlphaFunction.Less, 1.0f);
RenderFace(ref TransparentColorList[i], cx, cy, cz);
GL.DepthMask(true);
SetAlphaFunc(AlphaFunction.Equal, 1.0f);
RenderFace(ref TransparentColorList[i], cx, cy, cz);
}
} else {
for (int i = 0; i < TransparentColorListCount; i++) {
RenderFace(ref TransparentColorList[i], cx, cy, cz);
}
}
// alpha list
SortPolygons(AlphaList, AlphaListCount, AlphaListDistance, 2, 0.0);
if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Smooth) {
BlendEnabled = true; GL.Enable(EnableCap.Blend);
bool depthMask = true;
for (int i = 0; i < AlphaListCount; i++) {
int r = (int)ObjectManager.Objects[AlphaList[i].ObjectIndex].Mesh.Faces[AlphaList[i].FaceIndex].Material;
if (ObjectManager.Objects[AlphaList[i].ObjectIndex].Mesh.Materials[r].BlendMode == World.MeshMaterialBlendMode.Additive) {
if (depthMask) {
GL.DepthMask(false);
depthMask = false;
}
SetAlphaFunc(AlphaFunction.Greater, 0.0f);
RenderFace(ref AlphaList[i], cx, cy, cz);
} else {
if (depthMask) {
GL.DepthMask(false);
depthMask = false;
}
SetAlphaFunc(AlphaFunction.Less, 1.0f);
RenderFace(ref AlphaList[i], cx, cy, cz);
GL.DepthMask(true);
depthMask = true;
SetAlphaFunc(AlphaFunction.Equal, 1.0f);
RenderFace(ref AlphaList[i], cx, cy, cz);
}
}
} else {
BlendEnabled = true; GL.Enable(EnableCap.Blend);
GL.DepthMask(false);
SetAlphaFunc(AlphaFunction.Greater, 0.0f);
for (int i = 0; i < AlphaListCount; i++) {
RenderFace(ref AlphaList[i], cx, cy, cz);
}
}
// overlay list
GL.Disable(EnableCap.DepthTest);
GL.DepthMask(false);
if (FogEnabled)
{
GL.Disable(EnableCap.Fog); FogEnabled = false;
}
SortPolygons(OverlayList, OverlayListCount, OverlayListDistance, 3, 0.0);
for (int i = 0; i < OverlayListCount; i++)
{
RenderFace(ref OverlayList[i], cx, cy, cz);
}
// render overlays
BlendEnabled = false; GL.Disable(EnableCap.Blend);
SetAlphaFunc(AlphaFunction.Greater, 0.9f);
AlphaTestEnabled = false; GL.Disable(EnableCap.AlphaTest);
GL.Disable(EnableCap.DepthTest);
if (LightingEnabled)
{
GL.Disable(EnableCap.Lighting);
LightingEnabled = false;
}
if (OptionCoordinateSystem)
{
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.Enable(EnableCap.Blend);
GL.Color4(1.0, 0.0, 0.0, 0.2);
RenderBox(new World.Vector3D(0.0, 0.0, 0.0), new World.Vector3D(0.0, 0.0, 1.0), new World.Vector3D(0.0, 1.0, 0.0), new World.Vector3D(1.0, 0.0, 0.0), new World.Vector3D(100.0, 0.01, 0.01), cx, cy, cz);
GL.Color4(0.0, 1.0, 0.0, 0.2);
RenderBox(new World.Vector3D(0.0, 0.0, 0.0), new World.Vector3D(0.0, 0.0, 1.0), new World.Vector3D(0.0, 1.0, 0.0), new World.Vector3D(1.0, 0.0, 0.0), new World.Vector3D(0.01, 100.0, 0.01), cx, cy, cz);
GL.Color4(0.0, 0.0, 1.0, 0.2);
RenderBox(new World.Vector3D(0.0, 0.0, 0.0), new World.Vector3D(0.0, 0.0, 1.0), new World.Vector3D(0.0, 1.0, 0.0), new World.Vector3D(1.0, 0.0, 0.0), new World.Vector3D(0.01, 0.01, 100.0), cx, cy, cz);
}
RenderOverlays();
// finalize rendering
GL.PopMatrix();
}