Beispiel #1
0
        public void Draw(ref GameWorldTime worldTime, ref Shader shader, ref Camera camera, ref Matrix4 transform, Vector3 scale, bool fixedModel = false)
        {
            var viewMatrix = camera.ViewMatrix;

            if (fixedModel)
            {
                viewMatrix.Row3 = new Vector4(0, 0, 0, viewMatrix.Row3.W);
            }

            var projMatrix = camera.ProjectionMatrix;

            Draw(ref worldTime, ref shader, ref viewMatrix, ref projMatrix, ref transform, scale);
        }
Beispiel #2
0
        public void Initialize(int width, int height)
        {
            WorldTime = new GameWorldTime();
            camera    = new Camera(new Vector3(0.0f, 0.0f, 1.0f));
            camera.Create(width, height);
            camera.Update(0.0);

            PreloadModels();

            Models.Add(new Models.Terrain(512, 512), Functions.CreateTransformationMatrix(
                           new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f), new Vector3(1.0f)));

            skyBox = new Models.SkyBox(256);
        }
Beispiel #3
0
        public void Draw(ref GameWorldTime worldTime, ref Camera camera)
        {
            foreach (var instance in Instances)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

                if (instance.Value.Count > 1)
                {
                    instance.Key.VertexArray.Bind();

                    instance.Key.Texture.Bind();
                    instance.Key.Shader.Use();
                    instance.Key.Shader.Set_Mat4("projMatrix", camera.ProjectionMatrix);
                    instance.Key.Shader.Set_Mat4("viewMatrix", camera.ViewMatrix);

                    instance.Key.VertexArray.Instanced = instance.Value.Count > 1;

                    for (var i = 0; i < instance.Value.Count; i++)
                    {
                        if (instance.Key.VertexArray.Instanced)
                        {
                            instance.Key.Shader.Set_Mat4(string.Format("modelMatrix[{0}]", i), instance.Value[i]);
                        }
                    }

                    GL.DrawElementsInstanced(PrimitiveType.Triangles, instance.Key.VertexArray.IndexBuffer.Elements,
                                             DrawElementsType.UnsignedInt, IntPtr.Zero, instance.Value.Count);

                    instance.Key.Shader.Unuse();
                    instance.Key.Texture.UnBind();
                    instance.Key.VertexArray.UnBind();
                }
                else
                {
                    instance.Key.Draw(ref worldTime, ref camera);
                }

                GL.Disable(EnableCap.Blend);
            }
        }
Beispiel #4
0
        private void Draw(ref GameWorldTime worldTime, ref Shader shader, ref Matrix4 viewMatrix, ref Matrix4 projectionMatrix, ref Matrix4 transform, Vector3 scale)
        {
            var indicesCount = 0;

            if (IndexBuffer != null)
            {
                indicesCount = IndexBuffer.Elements;
            }

            if (VerticeCount == 0)
            {
                return;
            }

            Bind();

            shader.Use();
            shader.Set_Vec3("Scale", ref scale);
            shader.Set_Vec1("AmbientStrength", ref worldTime.AmbientStrength);
            shader.Set_Vec3("LightColor", ref worldTime.LightColor);
            shader.Set_Mat4("projMatrix", projectionMatrix);
            shader.Set_Mat4("viewMatrix", viewMatrix);
            shader.Set_Mat4("modelMatrix", transform);

            if (indicesCount == 0)
            {
                GL.DrawArrays(PrimitiveType.Triangles, 0, VerticeCount);
            }
            else
            {
                GL.DrawElements(PrimitiveType.Triangles, indicesCount, DrawElementsType.UnsignedInt, 0);
            }

            shader.Unuse();

            UnBind();
        }
Beispiel #5
0
 public virtual void Draw(ref GameWorldTime worldTime, ref Camera camera, bool staticObject = false)
 {
     Texture.Bind();
     VertexArray.Draw(ref worldTime, ref Shader, ref camera, ref ModelMatrix, Scale, staticObject);
     Texture.UnBind();
 }