示例#1
0
        public void OnLoad()
        {
            var dir = Directory.GetCurrentDirectory();

            ResourceGroupManager.Singleton.AddResourceLocation(dir, "FileSystem");
            MaterialManager.Singleton.Initialise();

            _scene = _root.CreateSceneManager("DefaultSceneManager", "SLSharpInstance");
            _scene.ClearScene();

            Bindings.MOGRE.SLSharp.Init();
            Shader.DebugMode = true;

            //Shader.DebugMode = true;

            _shader = Shader.CreateSharedShader <SimpleShader>();

            _patchEntity = _scene.CreateEntity("Box", "box.mesh");
            _scene.RootSceneNode.AttachObject(_patchEntity);

            var mat  = _shader.ToMaterial();
            var pass = mat.GetTechnique(0).GetPass(0);

            pass.SetAlphaRejectSettings(CompareFunction.CMPF_GREATER_EQUAL, 128);
            pass.CullingMode = CullingMode.CULL_NONE;

            // SL# on OGRE: bind auto semantic to a uniform!
            // (we might automate this via semantic attributes within the SL# shaders in future!)
            _shader.SetAuto(() => _shader.ModelviewProjection, GpuProgramParameters.AutoConstantType.ACT_WORLDVIEWPROJ_MATRIX);

            _shader.Begin();

            // Set a texture

            /*
             * var smp = _shader.Sampler(() => _shader.Texture);
             * smp.SetTextureName(TextureManager.Singleton.Load("test.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).Name);
             * smp.SetTextureName(_wang.AsTexture.Name);
             * smp.SetTextureFiltering(FilterOptions.FO_POINT, FilterOptions.FO_POINT, FilterOptions.FO_POINT);
             */

            _patchEntity.SetMaterial(mat);

            _camera          = _scene.CreateCamera("MainCamera");
            _camera.Position = new Vector3(0, 0, 5);
            _camera.LookAt(Vector3.ZERO);
            _camera.NearClipDistance = 0.0001f;
            _camera.FarClipDistance  = 4.0f;
            _camera.AutoAspectRatio  = true;

            var vp = _window.AddViewport(_camera);

            vp.BackgroundColour = ColourValue.Blue;
        }
示例#2
0
        public void OnLoad()
        {
            var dir = Directory.GetCurrentDirectory();

            ResourceGroupManager.Instance.AddResourceLocation(dir, "Folder");
            //MaterialManager.Instance.Initialize();

            _scene = _root.CreateSceneManager("DefaultSceneManager", "SLSharpInstance");
            _scene.ClearScene();

            Bindings.Axiom.SLSharp.Init();
            Shader.DebugMode = true;

            //Shader.DebugMode = true;

            _shader = Shader.CreateSharedShader <SimpleShader>();

            _patchEntity = _scene.CreateEntity("Box", "box.mesh");
            _scene.RootSceneNode.AttachObject(_patchEntity);

            var mat  = _shader.ToMaterial();
            var pass = mat.GetTechnique(0).GetPass(0);

            pass.SetAlphaRejectSettings(CompareFunction.GreaterEqual, 128);
            pass.CullingMode = CullingMode.None;

            // SL# on OGRE: bind auto semantic to a uniform!
            // (we might automate this via semantic attributes within the SL# shaders in future!)
            _shader.SetAuto(() => _shader.ModelviewProjection, GpuProgramParameters.AutoConstantType.WorldViewProjMatrix);

            _shader.Begin();

            _patchEntity.MaterialName = mat.Name;
            //_patchEntity.Material = mat;


            _camera          = _scene.CreateCamera("MainCamera");
            _camera.Position = new Vector3(0, 0, 5);
            _camera.LookAt(Vector3.Zero);
            _camera.Near            = 0.00001f;
            _camera.Far             = 4.0f;
            _camera.AutoAspectRatio = true;

            var vp = _root.AutoWindow.AddViewport(_camera);

            vp.BackgroundColor = ColorEx.CornflowerBlue;
        }
示例#3
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            var angle  = MathHelper.ToRadians((DateTime.Now.Millisecond / 1000.0f + DateTime.Now.Second) * 6 * 4);
            var cam    = new Vector3((float)Math.Sin(angle), 0.0f, (float)Math.Cos(angle));
            var aspect = ((float)Window.ClientBounds.Width) / Window.ClientBounds.Height;
            var world  = Matrix.CreateScale(0.005f);
            var view   = Matrix.CreateLookAt(cam, Vector3.Zero, Vector3.UnitY);
            var proj   = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(45.0f), aspect, 0.1f, 10.0f);



            _shader.Begin();
            foreach (var mesh in _model.Meshes)
            {
                var modelview = world * view * mesh.ParentBone.Transform;
                var mvp       = Matrix.Transpose(modelview * proj);

                _shader.Blue = (float)Math.Sin(angle * 8.0f);
                _shader.ModelviewProjection = mvp.ToMatrix4F();
                foreach (var part in mesh.MeshParts)
                {
                    GraphicsDevice.SetVertexBuffer(part.VertexBuffer, part.VertexOffset);
                    GraphicsDevice.Indices = part.IndexBuffer;
                    GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                         0, part.VertexOffset, part.NumVertices, part.StartIndex, part.PrimitiveCount);
                }
            }
            _shader.End();

            //_model.Draw(model, view, proj);

            base.Draw(gameTime);
        }