OpenBve.Renderer.RenderScene C# (CSharp) Méthode

RenderScene() static private méthode

static private RenderScene ( ) : void
Résultat void
        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();
        }

Same methods

Renderer::RenderScene ( double TimeElapsed ) : void

Usage Example

Exemple #1
0
        //This renders the frame
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            Program.MouseMovement();
            LibRender.Renderer.FrameRate = RenderFrequency;
            GL.ClearColor(0.75f, 0.75f, 0.75f, 1.0f);
            //Do not do anything whilst loading
            if (currentlyLoading)
            {
                return;
            }
            ProcessEvents();
            double TimeElapsed = CPreciseTimer.GetElapsedTime();

            if (Program.CpuReducedMode)
            {
                System.Threading.Thread.Sleep(250);
            }
            else
            {
                System.Threading.Thread.Sleep(1);
                if (ReducedModeEnteringTime == 0)
                {
                    ReducedModeEnteringTime = 2500;
                }
                if (Camera.AlignmentDirection.Position.X != 0.0 | Camera.AlignmentDirection.Position.Y != 0.0 | Camera.AlignmentDirection.Position.Z != 0.0 | Camera.AlignmentDirection.Pitch != 0.0 | Camera.AlignmentDirection.Yaw != 0.0 | Camera.AlignmentDirection.Roll != 0.0 | Camera.AlignmentDirection.TrackPosition != 0.0 | Camera.AlignmentDirection.Zoom != 0.0)
                {
                    ReducedModeEnteringTime = 2500;
                }
                //Automatically enter reduced CPU mode if appropriate
                if (Program.CpuAutomaticMode && Program.CpuReducedMode == false)
                {
                    ReducedModeEnteringTime -= TimeElapsed;
                    if (ReducedModeEnteringTime <= 0)
                    {
                        Program.CpuReducedMode  = true;
                        ReducedModeEnteringTime = 0;
                    }
                }
            }

            if (Program.CurrentRoute != null)
            {
                DateTime d = DateTime.Now;
                Game.SecondsSinceMidnight = (double)(3600 * d.Hour + 60 * d.Minute + d.Second) + 0.001 * (double)d.Millisecond;
                ObjectManager.UpdateAnimatedWorldObjects(TimeElapsed, false);
                World.UpdateAbsoluteCamera(TimeElapsed);
                ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + Camera.CurrentAlignment.Position.Z);
                Program.Sounds.Update(TimeElapsed, SoundModels.Linear);
            }
            Renderer.RenderScene(TimeElapsed);
            MessageManager.UpdateMessages();
            SwapBuffers();
        }
All Usage Examples Of OpenBve.Renderer::RenderScene