예제 #1
0
        public static void Init(GameWindowSettings gws, NativeWindowSettings nws, GLRenderer renderer = null, Action initCallback = null)
        {
            _window = new GameWindow(gws, nws);

            //log basic info
            Logger.Log("Base Directory: " + AppContext.BaseDirectory, true);
            Logger.Log("Renderer: " + GL.GetString(StringName.Renderer), true);
            Logger.Log("Vendor: " + GL.GetString(StringName.Vendor), true);
            Logger.Log("Version: " + GL.GetString(StringName.Version), true);
            Logger.Log("Shading Language version: " + GL.GetString(StringName.ShadingLanguageVersion), true);

            //subscribe to window events
            MainWindow.UpdateFrame += UpdateFrame;
            MainWindow.RenderFrame += RenderFrame;

            //intialize engine
            Logger.Log("Initializing LeaderEngine...", true);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            //init debug callbacks
            GLFW.SetErrorCallback(LogGLFWError);

            DebugProc debugProcCallback       = DebugCallback;
            GCHandle  debugProcCallbackHandle = GCHandle.Alloc(debugProcCallback);

            GL.DebugMessageCallback(debugProcCallback, IntPtr.Zero);
            GL.Enable(EnableCap.DebugOutput);
            GL.Enable(EnableCap.DebugOutputSynchronous);

            //init modules
            AssetManager.Init();
            DefaultShaders.Init();
            SpriteRenderer.Init();
            SkyboxRenderer.Init();

            _renderer = renderer ?? new ForwardRenderer();
            Renderer.Init();

            AudioManager.Init();

            Input.Init(MainWindow.KeyboardState, MainWindow.MouseState);

            //init main application
            initCallback?.Invoke();

            stopwatch.Stop();
            //print init complete msg
            Logger.Log($"LeaderEngine initialized. ({stopwatch.ElapsedMilliseconds}ms)", true);

            //open window
            MainWindow.Run();
        }
예제 #2
0
        public virtual void CalculateViewProjection(out Matrix4 view, out Matrix4 projection)
        {
            GLRenderer renderer = Engine.Renderer;

            projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(FOV), renderer.ViewportSize.X / (float)renderer.ViewportSize.Y, 0.02f, 800.0f);

            Vector3 pos = BaseTransform.GlobalTransform.ExtractTranslation();

            view = Matrix4.LookAt(
                pos,
                pos + BaseTransform.Forward,
                BaseTransform.Up
                );
        }
예제 #3
0
        public void Render(Matrix4 view, Matrix4 projection)
        {
            if (!Enabled)
            {
                return;
            }

            GLRenderer renderer = Engine.Renderer;

            uniforms.SetUniform("model", new Uniform(UniformType.Matrix4,
                                                     BaseTransform.ModelMatrix));

            uniforms.SetUniform("view", new Uniform(UniformType.Matrix4, view));

            uniforms.SetUniform("projection", new Uniform(UniformType.Matrix4, projection));

            uniforms.SetUniform("mvp", new Uniform(UniformType.Matrix4,
                                                   BaseTransform.ModelMatrix
                                                   * view * projection));

            uniforms.SetUniform("camPos", new Uniform(UniformType.Vector3,
                                                      Camera.Main.BaseTransform.Position));

            if (DirectionalLight.Main != null)
            {
                uniforms.SetUniform("lightDir", new Uniform(UniformType.Vector3,
                                                            -DirectionalLight.Main.BaseTransform.Forward));
            }

            uniforms.SetUniform("lightSpaceMat", new Uniform(UniformType.Matrix4, LightingGlobals.LightView * LightingGlobals.LightProjection));

            uniforms.SetUniform("shadowMap", new Uniform(UniformType.Texture2D, new TextureData(TextureUnit.Texture1, LightingGlobals.ShadowMap)));

            renderer.PushDrawData(DrawType.Opaque, new GLDrawData
            {
                Mesh     = Mesh,
                Shader   = Shader,
                Material = Material,
                Uniforms = uniforms
            });
        }
예제 #4
0
        public virtual void CalculateViewProjection(out Matrix4 view, out Matrix4 projection)
        {
            GLRenderer renderer = Engine.Renderer;

            if (!OrthographicProjection)
            {
                projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(FOV), renderer.ViewportSize.X / (float)renderer.ViewportSize.Y, NearPlane, FarPlane);
            }
            else
            {
                float aspect = renderer.ViewportSize.X / (float)renderer.ViewportSize.Y;

                projection = Matrix4.CreateOrthographic(OrthographicScale * 2f * aspect, OrthographicScale * 2f, NearPlane, FarPlane);
            }

            Vector3 pos = BaseTransform.GlobalTransform.ExtractTranslation();

            view = Matrix4.LookAt(
                pos,
                pos + BaseTransform.Forward,
                BaseTransform.Up
                );
        }