示例#1
0
        static void RescaleToWindowSize()
        {
            int FB_Width, FB_Height;

            Glfw.GetFramebufferSize(Window, out FB_Width, out FB_Height);

            if (FB_Width > 0 && FB_Height > 0)
            {
                FBO.Init(FB_Width, FB_Height);
                MainCamera.SetProjectionMatrix(ProjectionTypes.Perspective, FB_Width, FB_Height, MainCamera.zNear, MainCamera.zFar, MainCamera.FOV);
                GL.Viewport(0, 0, FB_Width, FB_Height);
                FPS.Font_Init();
                FPS.FPS_Font_ProjectionMatrix = Matrix4.CreateOrthographicOffCenter(0, FB_Width, 0, FB_Height, -1.0f, 1.0f);
            }
        }
示例#2
0
        static void OnRenderFrame()
        {
            // G-Buffer
            GL.BindFramebuffer(FramebufferTarget.FramebufferExt, FBO.FBO_P1);
            GL.Enable(EnableCap.DepthTest); // Включаем тест глубины
            GL.DepthFunc(DepthFunction.Lequal);
            GL.ClearColor(Color4.Gray);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // Copy All Meshes to DrawableObjects
            List <Mesh> DrawableMeshes = new List <Mesh>();

            for (int i = 0; i < Models.MODELS.Count; i++)
            {
                if (Models.MODELS[i].Visible)
                {
                    DrawableMeshes.AddRange(Models.MODELS[i].Meshes);
                }
            }

            foreach (Mesh v in DrawableMeshes) //Draw All
            {
                Draw(v);
            }

            // Draw All Geometry to PostProcess FBO
            FBO.Draw_P1();

            // Draw SkyBox to PostProcess FBO
            if (SkyBox != null)
            {
                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, FBO.FBO_PP);
                GL.ClearColor(Color4.Gray);
                GL.Enable(EnableCap.CullFace);
                GL.Enable(EnableCap.DepthTest);
                Draw(SkyBox);
            }

            // Draw PostProcessed Result to Screen (FBO = 0)
            FBO.Draw_PostPocess();
        }
示例#3
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; //For fix parsing values like "0.5" and "0,5"

            Glfw.SetErrorCallback(OnError);

            if (!Glfw.Init())
            {
                Log.WriteLineRed("ERROR: Could not initialize GLFW, shutting down.");
                Console.ReadKey();
                Environment.Exit(1);
            }

            Engine.LoadConfig();
            Engine.ApplyConfig();

            while (Settings.Window.NeedReinitWindow)
            {
                ApplySettingsAndCreateWindow();
                Engine.GetGLSettings();
                Engine.LoadContentLists();

                int FB_Width, FB_Height;
                Glfw.GetFramebufferSize(Window, out FB_Width, out FB_Height);
                FBO.Init(FB_Width, FB_Height);
                RescaleToWindowSize(); // This function call FBO.Init()!!! That's is needed! (mb GLFW bug...)

                Settings.Window.NeedReinitWindow = false;

                if (!ContextIsLoaded)
                {
                    Engine.LoadEngineContent();

                    //Load Map
                    if (args.Length > 0)
                    {
                        Maps.LoadMap(args[0]);
                    }
                    else
                    {
                        Maps.LoadMap("Materials_Test_Map"); //Sponza //SampleMap //Materials_Test_Map
                    }
                    ContextIsLoaded = true;
                }

                // On...DoSomething functions
                Glfw.SetCursorPosCallback(Window, OnMouseMove);
                Glfw.SetMouseButtonCallback(Window, OnMouseClick);
                Glfw.SetFramebufferSizeCallback(Window, OnFramebufferResize);
                Glfw.SetKeyCallback(Window, OnKeyPress);
                Glfw.SetWindowFocusCallback(Window, OnFocusChanged);
                Glfw.SetWindowPosCallback(Window, OnWindowPositionChange);
                Glfw.SetWindowSizeCallback(Window, OnWindowResize);

                #region Main Loop
                while (!(Glfw.WindowShouldClose(Window) || Settings.Window.NeedReinitWindow))
                {
                    OnUpdateFrame();
                    OnRenderFrame();

                    if (FPS.ShowFPS)
                    {
                        FPS.CalcFPS();        //FPS Counter, must be at the END of the Render LOOP!
                    }
                    Glfw.SwapBuffers(Window); // Swap the front and back buffer, displaying the scene
                    Glfw.PollEvents();        // Poll GLFW window events
                }
                #endregion
            }
            Maps.Free(true); // Free all: Map -> Meshes, Shaders, Textures...
            FBO.Free();
            FPS.Font_Free();
            Engine.ClearLists();
            try
            {
                Game.EditorMainForm.Close(); // Editor
            }
            catch
            {
            }
            Glfw.DestroyWindow(Window);
            Glfw.Terminate();

            if (Settings.Debug.Enabled)
            {
                //Console.ReadKey();
                string log = Log.GetLog();
                if (log.Length > 256)
                {
                    System.Windows.Forms.Clipboard.SetText(log);
                }
            }
        }