示例#1
0
        public void Render(Viewport viewport, Camera camera, Scene scene)
        {
            gl.Viewport(viewport.Left, viewport.Top, viewport.Width, viewport.Height);
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            foreach (var entities in scene.OfType<PhysicalEntity>().GroupBy(e => e.Material))
            {
                gl.UseProgram(entities.Key.ID);
                entities.Key.SetUniform("projectionMatrix", camera.GetProjectionMatrix(viewport));

                foreach (var entity in entities)
                {
                    gl.BindVertexArray(entity.Mesh.ID);
                    entity.Material.SetUniform("modelViewMatrix", camera.CoordinateSystem.ViewMatrix * entity.CoordinateSystem.ModelMatrix);
                    gl.DrawArrays((uint)entity.Mesh.Type, 0, entity.Mesh.Length);
                }
            }

            gl.Flush();
            gl.Blit(IntPtr.Zero);
        }
示例#2
0
文件: Game.cs 项目: jtdubs/VoxelLand
        public void Initialize(IntPtr handle, Viewport viewport)
        {
            this.viewport = viewport;

            gl = new OpenGL();
            gl.Create(RenderContextType.NativeWindow, viewport.Width, viewport.Height, 32, handle);
            gl.MakeCurrent();

            ShaderManager.Initialize(gl);
            MaterialManager.Initialize(gl);

            renderer = new Renderer();
            renderer.Initialize(gl);

            camera = new PerspectiveCamera();
            camera.LocalTranslate(new Vector(0, 0, 3));

            var mesh = new Mesh(gl, MeshType.Points);
            mesh.AddBuffer(
                new Buffer<Point>(gl,
                    new Point(-2, -2, 0),
                    new Point(-1, -1, 0),
                    new Point( 0,  0, 0),
                    new Point( 1, -1, 0),
                    new Point( 2, -2, 0)));

            scene = new Scene();
            scene.Add(camera);

            for (int j = -10; j < 10; j++)
            for (int i = -10; i < 10; i++)
            {
                var e = new PhysicalEntity(mesh, MaterialManager.GetMaterial("Voxels"));
                e.GlobalTranslate(Vector.UnitZ * -5 * i);
                e.GlobalTranslate(Vector.UnitX * -5 * j);
                scene.Add(e);
            }

            gl.MakeNothingCurrent();
        }
示例#3
0
 public override Matrix GetProjectionMatrix(Viewport viewport)
 {
     float aspect = viewport.Width / (float)viewport.Height;
     return Transform.Perspective(VerticalFieldOfView, aspect, 0.1f, 100.0f);
 }
示例#4
0
 public override Matrix GetProjectionMatrix(Viewport viewport)
 {
     float aspect = viewport.Width / (float)viewport.Height;
     float halfWidth = HalfHeight * aspect;
     return Transform.Ortho(-halfWidth, halfWidth, -HalfHeight, HalfHeight, 0.1f, 100.0f);
 }
示例#5
0
 public abstract Matrix GetProjectionMatrix(Viewport viewport);
示例#6
0
文件: Game.cs 项目: jtdubs/VoxelLand
 public void OnViewportChanged(Viewport viewport)
 {
     this.viewport = viewport;
 }
示例#7
0
 public void OnViewportChanged(Viewport viewport)
 {
     this.viewport = viewport;
 }