Esempio n. 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);
        }
Esempio n. 2
0
        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();
        }