当前位置: 首页>>代码示例>>C#>>正文


C# Device.SetRenderState方法代码示例

本文整理汇总了C#中Device.SetRenderState方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetRenderState方法的具体用法?C# Device.SetRenderState怎么用?C# Device.SetRenderState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Device的用法示例。


在下文中一共展示了Device.SetRenderState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

 public void Init(Device d, TreeView tv)
 {
     Levels = new List<Levelfile>();
     device = d;
     Material material = new Material();
     material.Diffuse = Color.White;
     material.Specular = Color.LightGray;
     material.SpecularSharpness = 15.0F;
     device.Material = material;
     device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, 1000000.0f);
     device.SetRenderState(RenderStates.ShadeMode, 1);
     device.RenderState.Lighting = true;
     device.RenderState.Ambient = Color.Gray;
     device.SamplerState[0].MinFilter = TextureFilter.Linear;
     device.SamplerState[0].MagFilter = TextureFilter.Linear;
     device.Lights[0].Type = LightType.Directional;
     device.Lights[0].Diffuse = Color.White;
     device.Lights[0].Range = 100000;
     device.Lights[0].Enabled = true;
     device.RenderState.CullMode = Cull.None;
     device.SetRenderState(RenderStates.ZEnable, true);
     device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
     string loc = Path.GetDirectoryName(Application.ExecutablePath);
     DirectXGlobal.Tex_Default = TextureLoader.FromFile(device, loc + "\\exec\\Default.bmp");
     DirectXGlobal.Tex_Select = TextureLoader.FromFile(device, loc + "\\exec\\select.bmp");
     GlobalTree = tv;
     GlobalTree.Nodes.Clear();
 }
开发者ID:CreeperLava,项目名称:ME3Explorer,代码行数:28,代码来源:SceneManager.cs

示例2: OnRenderFrame

        public override void OnRenderFrame(Device device, float elapsedTime)
        {
            base.OnRenderFrame(device, elapsedTime);

            // Set render states
            device.SetRenderState(RenderStates.ZBufferWriteEnable, false);
            device.SetRenderState(RenderStates.ZEnable, false);
            device.SetRenderState(RenderStates.Lighting, false);
            device.SetRenderState(RenderStates.AlphaBlendEnable, true);

            device.SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha);
            device.SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha);

            device.VertexFormat = CustomVertex.TransformedColored.Format;
            device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, verts);
        }
开发者ID:kensniper,项目名称:castle-butcher,代码行数:16,代码来源:BeginGameLayer.cs

示例3: RunLoop

        public void RunLoop()
        {
            RunLoopCreated = true;
            mRunThread = new System.Threading.Thread(() =>
                {
                    ParentForm.Visible = true;
                    ParentForm.Visible = false;

                    var ctrl = mRenderWindow;
                    mDriver = new Direct3D();
                    mDevice = new Device(mDriver, 0, DeviceType.Hardware, ctrl.Handle, CreateFlags.HardwareVertexProcessing
                        | CreateFlags.Multithreaded,
                        new PresentParameters()
                        {
                            Windowed = true,
                            BackBufferFormat = Format.A8R8G8B8,
                            BackBufferHeight = ctrl.ClientSize.Height,
                            BackBufferWidth = ctrl.ClientSize.Width,
                            EnableAutoDepthStencil = true,
                            AutoDepthStencilFormat = Format.D24S8,
                            SwapEffect = SwapEffect.Discard,
                            DeviceWindowHandle = ctrl.Handle,
                        }
                        );

                    mDevice.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH((45.0f * (float)Math.PI) / 180.0f, ctrl.ClientSize.Width / (float)ctrl.ClientSize.Height, 0.1f, 100000.0f));
                    mDevice.SetRenderState(RenderState.Lighting, false);
                    mDevice.SetRenderState(RenderState.ZEnable, true);
                    mDevice.SetRenderState(RenderState.CullMode, Cull.None);
                    mDevice.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
                    mDevice.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
                    mDevice.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

                    InputManager = new Video.Input.InputManager();
                    InputManager.InputWindow = ctrl;
                    Camera = new ModelCamera(ctrl, this);
                    TextureManager = new Video.TextureManager(mDevice);

                    Application.Idle += (sender, args) =>
                        {
                            if (ParentForm.Visible == false)
                                return;

                            MSG msg = new MSG();
                            while (!PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0))
                                RenderFrame();
                        };

                    if (LoadDone != null)
                        LoadDone();

                    LoadEvent.Set();

                    ParentForm.Visible = true;
                    Application.Run(ParentForm);
                }
            );

            mRunThread.Start();
            Game.GameManager.GameTerminated += () =>
                {
                    if (ParentForm.IsDisposed == false)
                        ParentForm.Invoke(new Action(ParentForm.Dispose));
                };
        }
开发者ID:remixod,项目名称:sharpwow,代码行数:65,代码来源:ControlRender.cs

示例4: init

        public void init(StreamWriter st)
        {
            st.WriteLine("初期化開始");

            pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);

            st.WriteLine("デバイス作成の開始");
            device = new Device(new Direct3D(), 0, DeviceType.Hardware, this.pictureBox1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
            {
                BackBufferWidth = this.pictureBox1.ClientSize.Width,
                BackBufferHeight = this.pictureBox1.ClientSize.Height,
                Windowed = true,
            });
            st.WriteLine("デバイス作成の終了");
            Capabilities caps = device.Capabilities;
            st.WriteLine("adapterOrdinal:" + caps.AdapterOrdinal);
            st.WriteLine("DeviceType:" + caps.DeviceType);
            if (caps.VertexShaderVersion.Major < 3)
            {
                MessageBox.Show("VertexShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
                device.Dispose();
                Environment.Exit(0);
            }
            else if (caps.PixelShaderVersion.Major < 3)
            {
                MessageBox.Show("PixelShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
                device.Dispose();
                Environment.Exit(0);
            }

            st.WriteLine("DeviceContextの初期化");
            DeviceContext.init(device);

            st.WriteLine("ZEnableの初期化");
            device.SetRenderState(RenderState.ZEnable, true);

            st.WriteLine("cameraの初期化");
            camera = new Camera(device);

            st.WriteLine("Floorの初期化");
            floorMap = new FloorMap(device);

            //            teapot = Mesh.CreateTeapot(device);
            //            device.SetRenderState(RenderState.ShadeMode, ShadeMode.Flat);

            st.WriteLine("照明の初期化");
            device.SetRenderState(RenderState.Lighting, true);
            device.SetLight(0, new Light() {
                Type = LightType.Directional,
                Diffuse = Color.White,
                Ambient = Color.Gray,
                Direction = new Vector3(1.0f, 1.0f, 0.0f),
            });
            device.EnableLight(0,true);
            standardLine = new StandardLine(device);
            //射影変換
            device.SetTransform(TransformState.Projection,
                                 Matrix.PerspectiveFovLH((float)(Math.PI / 4),
                                                         (float)this.pictureBox1.ClientSize.Width / (float)this.pictureBox1.ClientSize.Height,
                                                         0.1f, 1500.0f));
            //ビュー
            device.SetTransform(TransformState.View,
                                 camera.getLookAtLh());

            device.SetTransform(TransformState.World, Matrix.Identity);

            st.WriteLine("FloorModelの初期化");
            floorModel = new FloorModel(new MqoParser(device).parse(".\\projects\\sample\\model\\floor.mqo", new MqoModel()));

            st.WriteLine("初期化終了");
        }
开发者ID:kistvan,项目名称:geditor,代码行数:71,代码来源:Form1.cs

示例5: Renderer

        public Renderer(Control control)
        {
            PresentParameters presentParams = new PresentParameters();
            presentParams.Windowed = true;
            presentParams.BackBufferCount = 0;
            presentParams.BackBufferWidth = Screen.PrimaryScreen.WorkingArea.Width;
            presentParams.BackBufferHeight = Screen.PrimaryScreen.WorkingArea.Height;
            Device = new Device(new Direct3D(), 0, DeviceType.Hardware, control.Handle, CreateFlags.SoftwareVertexProcessing, presentParams);
            if ((Device.Capabilities.VertexProcessingCaps & VertexProcessingCaps.Tweening) == 0)
            {
                Report.ReportLog("Vertex tweening is not supported!");
            }

            Device.SetRenderState(RenderState.Lighting, true);
            Device.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Material);
            Device.SetRenderState(RenderState.EmissiveMaterialSource, ColorSource.Material);
            Device.SetRenderState(RenderState.SpecularMaterialSource, ColorSource.Material);
            Device.SetRenderState(RenderState.SpecularEnable, true);
            Device.SetRenderState(RenderState.AlphaBlendEnable, true);
            Device.SetRenderState(RenderState.BlendOperationAlpha, BlendOperation.Add);
            Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
            Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);

            Device.SetSamplerState(0, SamplerState.MaxAnisotropy, 4);
            Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Anisotropic);
            Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Anisotropic);
            Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

            Light light = new Light();
            light.Type = LightType.Directional;
            light.Ambient = new Color4(int.Parse((string)Gui.Config["LightAmbientARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
            light.Diffuse = new Color4(int.Parse((string)Gui.Config["LightDiffuseARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
            light.Specular = new Color4(int.Parse((string)Gui.Config["LightSpecularARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
            Device.SetLight(0, light);
            Device.EnableLight(0, true);

            TextFont = new SlimDX.Direct3D9.Font(Device, new System.Drawing.Font("Arial", 8));
            TextColor = new Color4(Color.White);

            CursorMesh = Mesh.CreateSphere(Device, 1, 10, 10);
            CursorMaterial = new Material();
            CursorMaterial.Ambient = new Color4(1, 1f, 1f, 1f);
            CursorMaterial.Diffuse = new Color4(1, 0.6f, 1, 0.3f);

            showNormals = (bool)Gui.Config["ShowNormals"];
            showBones = (bool)Gui.Config["ShowBones"];
            string[] mode = Enum.GetNames(typeof(ShowBoneWeights));
            for (int i = 0; i < mode.Length; i++)
            {
                if (mode[i] == (string)Gui.Config["ShowBoneWeights"])
                {
                    showBoneWeights = (ShowBoneWeights)i;
                    break;
                }
            }
            wireframe = (bool)Gui.Config["Wireframe"];
            culling = (bool)Gui.Config["Culling"];
            Background = Color.FromArgb(int.Parse((string)Gui.Config["RendererBackgroundARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));

            isInitialized = true;
            camera = new Camera(control);
            RenderControl = control;
        }
开发者ID:hejob,项目名称:SB3Utility,代码行数:63,代码来源:Renderer.cs

示例6: _OnFrame

        void _OnFrame(Device device, TimeSpan deltaTime)
        {
            device.SetRenderState(RenderState.AlphaBlendEnable, true);
            device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
            device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);

            device.SetRenderState(RenderState.AlphaTestEnable, true);
            device.SetRenderState(RenderState.AlphaFunc, Compare.Greater);
            device.SetRenderState(RenderState.AlphaRef, 0.3f);

            RenderInstances(device);

            device.SetRenderState(RenderState.AlphaBlendEnable, false);
            device.SetRenderState(RenderState.AlphaTestEnable, false);
        }
开发者ID:remixod,项目名称:sharpwow,代码行数:15,代码来源:M2BatchRenderer.cs

示例7: Render

        // TODO: Consider returning IEnumerable<RenderInfo>
        private RenderInfo[] Render(Device dev, MatrixStack transform, EditorCamera cam)
        {
            List<RenderInfo> result = new List<RenderInfo>();

            if (!enabled)
                return result.ToArray();

            float dist = cam.Position.Distance(position) * 0.0825f;
            BoundingSphere gizmoSphere = new BoundingSphere() { Center = new Vertex(position.X, position.Y, position.Z), Radius = (1.0f * Math.Abs(dist)) };

            #region Setting Render States
            dev.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point); // no fancy filtering is required because no textures are even being used
            dev.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point);
            dev.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Point);
            dev.SetRenderState(RenderStates.Lighting, true);
            dev.SetRenderState(RenderStates.SpecularEnable, false);
            dev.SetRenderState(RenderStates.Ambient, Color.White.ToArgb());
            dev.SetRenderState(RenderStates.AlphaBlendEnable, false);
            dev.SetRenderState(RenderStates.ColorVertex, false);
            dev.Clear(ClearFlags.ZBuffer, 0, 1, 0);
            #endregion

            transform.Push();
            transform.TranslateLocal(position.X, position.Y, position.Z);
            transform.RotateXYZLocal(rotation.X, rotation.Y, rotation.Z);
            transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist));

            #region Handling Transform Modes
            switch (mode)
            {
                case TransformMode.TRANFORM_MOVE:
                    {
                        RenderInfo xRenderInfo = new RenderInfo(Gizmo.XMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(xRenderInfo);
                        RenderInfo yRenderInfo = new RenderInfo(Gizmo.YMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(yRenderInfo);
                        RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(zRenderInfo);

                        if (!isTransformLocal) // this is such a cop-out. I'll try to find a better solution.
                        {
                            RenderInfo xyRenderInfo = new RenderInfo(Gizmo.XYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
                            result.Add(xyRenderInfo);
                            RenderInfo zxRenderInfo = new RenderInfo(Gizmo.ZXMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XZ_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
                            result.Add(zxRenderInfo);
                            RenderInfo zyRenderInfo = new RenderInfo(Gizmo.ZYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.ZY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
                            result.Add(zyRenderInfo);
                        }
                    }
                    break;
                case TransformMode.TRANSFORM_ROTATE:
                    {
                        RenderInfo xRenderInfo = new RenderInfo(Gizmo.XRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(xRenderInfo);
                        RenderInfo yRenderInfo = new RenderInfo(Gizmo.YRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(yRenderInfo);
                        RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(zRenderInfo);
                    }
                    break;
                case TransformMode.NONE:
                    {
                        RenderInfo xRenderInfo = new RenderInfo(Gizmo.XNullMesh, 0, transform.Top, Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(xRenderInfo);
                        RenderInfo yRenderInfo = new RenderInfo(Gizmo.YNullMesh, 0, transform.Top, Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(yRenderInfo);
                        RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZNullMesh, 0, transform.Top, Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(zRenderInfo);
                    }
                    break;
                case TransformMode.TRANSFORM_SCALE:
                    {
                        RenderInfo xRenderInfo = new RenderInfo(Gizmo.XScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(xRenderInfo);
                        RenderInfo yRenderInfo = new RenderInfo(Gizmo.YScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(yRenderInfo);
                        RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(zRenderInfo);
                    }
                    break;
            }
            #endregion

            transform.Pop();
            return result.ToArray();
        }
开发者ID:Radfordhound,项目名称:sa_tools,代码行数:87,代码来源:TransformGizmo.cs

示例8: InitializeDirect3D

        private void InitializeDirect3D()
        {
            try
            {
                if (!_fullScreen)
                {
                    D3D = new Direct3D();
                    _presentParams = new PresentParameters
                    {
                        BackBufferWidth = _width,
                        BackBufferHeight = _height,
                        Windowed = true,
                        SwapEffect = SwapEffect.Discard,
                        Multisample = MultisampleType.None,
                        PresentationInterval = PresentInterval.Immediate
                    };
                    _displayDevice = new Device(D3D, 0, DeviceType.Hardware, _surface.Handle,
                                                CreateFlags.SoftwareVertexProcessing, new[] { _presentParams });
                    _displayRect = new Rectangle(0, 0, _width, _height);
                    _buffSize = (_width * _height) * 4;
                    _displayData = new byte[_buffSize];
                    CreateDisplayObjects(_displayDevice);
                    _initialized = true;
                    _disposed = false;
                    Debug.WriteLine(this, "SlimDX video mode (Windowed) Initialized ok.", DebugStatus.Cool);
                }
                else
                {
                    D3D = new Direct3D();
                    _mode = FindSupportedMode();
                    _presentParams = new PresentParameters
                    {
                        BackBufferFormat = _mode.Format,
                        BackBufferCount = 1,
                        BackBufferWidth = _mode.Width,
                        BackBufferHeight = _mode.Height,
                        Windowed = false,
                        FullScreenRefreshRateInHertz = _mode.RefreshRate,
                        SwapEffect = SwapEffect.Discard,
                        Multisample = MultisampleType.None,
                        PresentationInterval = PresentInterval.Immediate
                    };
                    _displayDevice = new Device(D3D, 0, DeviceType.Hardware, _surface.Parent.Handle,
                                                CreateFlags.SoftwareVertexProcessing, new[] { _presentParams })
                    {
                        ShowCursor = false,
                    };
                    _displayDevice.SetRenderState(RenderState.PointScaleEnable, true);
                    _displayDevice.SetRenderState(RenderState.PointSpriteEnable, true);
                    _displayRect = new Rectangle(0, 0, _width, _height);
                    _position = new Vector3((_mode.Width - _width) / 2, (_mode.Height - _height) / 2, 0);
                    _buffSize = (_width * _height) * 4;
                    _displayData = new byte[_buffSize];
                    CreateDisplayObjects(_displayDevice);
                    _initialized = true;
                    _disposed = false;

                    Debug.WriteLine(this, "SlimDX video mode (Fullscreen) Initialized ok.", DebugStatus.Cool);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(this, "Could not Initialize SlimDX mode because of : \n" + ex.Message, DebugStatus.Error);
                _initialized = false;
            }
        }
开发者ID:afonsof,项目名称:nes-hd,代码行数:66,代码来源:VideoSlimDx.cs

示例9: RenderWorld

        private void RenderWorld(Device device)
        {
            CharacterController sdev = player.CurrentCharacter.CharacterController;
            MyVector pos = player.CurrentCharacter.Position;
            //pos.X += player.PlayerControl.CameraShaker.Position.X;
            //pos.Y += /*player.PlayerControl.CameraShaker.Position.Y*/-player.CurrentCharacter.YMotionToCompensate;
            //pos.Y += 9;
            MyVector target = pos + sdev.LookVector;

            MyVector up = sdev.UpVector;
            device.RenderState.CullMode = Cull.Clockwise;

            renderer.SetUp(pos, sdev.LookVector, sdev.UpVector, player.CurrentCharacter.Velocity);
            ////stars
            renderer.RenderEnvironment(World.Instance.Environment);
            device.RenderState.ZBufferEnable = true;
            device.RenderState.ZBufferWriteEnable = true;

            renderer.ShaderConstants.SetCamera(pos, sdev.UpVector, sdev.LookVector);

            renderer.ShaderConstants.SetMatrices(Matrix.Identity, Matrix.LookAtRH((Vector3)pos, (Vector3)target, (Vector3)up),
                device.Transform.Projection);
            device.RenderState.ZBufferEnable = true;
            device.RenderState.ZBufferWriteEnable = true;
            device.SetRenderState(RenderStates.SourceBlend, (int)Blend.One);
            device.SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha);

            ////device.RenderState.Lighting = true;
            //device.RenderState.FillMode = FillMode.Point;
            device.RenderState.CullMode = Cull.Clockwise;

            //*******************************************************
            foreach (IGameObject obj in World.Instance.GameObjects)
            {
                if (obj.RenderingData != null /*&& !(obj is Rocket)*/)
                {
                    if (obj == player.CurrentCharacter) continue;
                    if (obj is Character)
                    {

                        renderer.RenderRD(obj.RenderingData, /*Matrix.Translation(0,-(obj as Character).YMotionToCompensate,0)*/obj.RenderingData.CustomTransform * obj.Transform);
                    }
                    else if(obj is WeaponPickup)
                    {
                        if((obj as WeaponPickup).Ready)
                            renderer.RenderRD(obj.RenderingData, obj.RenderingData.CustomTransform * obj.Transform);
                    }
                    else
                    {
                        renderer.RenderRD(obj.RenderingData, obj.RenderingData.CustomTransform * obj.Transform);
                    }
                }
            }

            ////effects
            renderer.RenderExplosions();
            //renderer.RenderParticles();

            device.Clear(ClearFlags.ZBuffer, Color.Black, 1, 0);
            device.RenderState.ZBufferEnable = true;
            device.RenderState.ZBufferWriteEnable = true;
            if (player.IsAlive && player.CurrentCharacter.Weapons.CurrentWeapon != null)
            {
                renderer.ShaderConstants.SetCamera(new MyVector(0, 0, 0), new MyVector(0, 1, 0), new MyVector(0, 0, -1));
                renderer.ShaderConstants.SetMatrices(Matrix.Identity, Matrix.Identity,
                device.Transform.Projection);
                renderer.RenderRD(player.CurrentCharacter.Weapons.CurrentWeapon.WeaponClass.CameraRenderingData, Matrix.Translation(player.PlayerControl.CameraShaker.Position.X,
                                                    player.PlayerControl.CameraShaker.Position.Y,
                                                    player.PlayerControl.CameraShaker.Position.Z));
            }
        }
开发者ID:kensniper,项目名称:castle-butcher,代码行数:71,代码来源:MainView.cs

示例10: Render

        /// <summary>Renders the quads with this style.</summary>
        /// <param name="device">D3D Device</param>
        /// <param name="quads">Quads to render</param>
        public void Render(Device device, List<Quad> quads)
        {
            if (quads.Count == 0)
                return;
            // Add vertices to the buffer
            GraphicsStream gb =
                m_vb.Lock(0, 6 * quads.Count * CustomVertex.TransformedColoredTextured.StrideSize, LockFlags.Discard);

            Quad q;
            for (int i = 0; i < quads.Count;i++ )
            {
                q = (Quad)quads[i].Clone();
                q.X -= 0.5f;
                q.Y -= 0.5f;
                gb.Write(q.Vertices);
            }

            m_vb.Unlock();

            // Set render states
            device.SetRenderState(RenderStates.Lighting, false);
            device.SetRenderState(RenderStates.ZBufferWriteEnable, false);
            device.SetRenderState(RenderStates.ZEnable, false);
            device.SetRenderState(RenderStates.AlphaBlendEnable, true);
            device.SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha);
            device.SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha);
            device.SetStreamSource(0, m_vb, 0, CustomVertex.TransformedColoredTextured.StrideSize);
            device.SetTexture(0, m_texture);
            device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2 * quads.Count);
        }
开发者ID:kensniper,项目名称:castle-butcher,代码行数:34,代码来源:GuiStyle.cs

示例11: CreateDevice

        public static void CreateDevice(Control window)
        {
            CloseDevice();

            device = new Device(d3d, adapter, DeviceType.Hardware, window.Handle, CreateFlags.FpuPreserve|CreateFlags.Multithreaded|CreateFlags.HardwareVertexProcessing, devParams);

            //BackBuffer=device.GetBackBuffer(0, 0, BackBufferType.Mono);
            BackBuffer=device.GetRenderTarget(0);

            device.SetRenderState(RenderState.Lighting, false);
            device.SetRenderState(RenderState.ZEnable, false);
            device.SetRenderState(RenderState.StencilEnable, false);
            device.SetRenderState(RenderState.Ambient, int.MinValue);
        }
开发者ID:europop,项目名称:MGE-XE,代码行数:14,代码来源:DXMain.cs

示例12: MainWindow

        /// <summary>
        /// 最上位ウインドウを作成
        /// </summary>
        public MainWindow()
        {
            // コンポーネント初期化
            InitializeComponent();

            // ウインドウが読み込まれたら
            this.Loaded += (sender, e) =>
            {
                // Direct3D作成
                var direct3D = new SlimDX.Direct3D9.Direct3D();

                // デバイスを初期化
                Device device = null;

                // ティーポッドと文字列を初期化
                Mesh teapod = null;
                Mesh helloWorld = null;

                // バッファーウインドウ作成
                IntPtr handle = new HwndSource(0, 0, 0, 0, 0, "buffer", IntPtr.Zero).Handle;

                // デバイスを作成
                device = new Device(direct3D, 0,
                    DeviceType.Hardware,
                    handle,
                    CreateFlags.HardwareVertexProcessing,
                    new PresentParameters()
                    {
                        BackBufferFormat = Format.X8R8G8B8,
                        BackBufferCount = 1,
                        BackBufferWidth = (int)this.Width,
                        BackBufferHeight = (int)this.Height,
                        Multisample = MultisampleType.None,
                        SwapEffect = SwapEffect.Discard,
                        EnableAutoDepthStencil = true,
                        AutoDepthStencilFormat = Format.D16,
                        PresentFlags = PresentFlags.DiscardDepthStencil,
                        PresentationInterval = PresentInterval.Default,
                        Windowed = true,
                        DeviceWindowHandle = handle
                    });

                // ティーポッドと文字列を作成
                teapod = Mesh.CreateTeapot(device);
                helloWorld = Mesh.CreateText(device, new System.Drawing.Font("Arial", 10), "Hello, world!", 0.001f, 0.001f);

                // 光源描画を有効化
                device.SetRenderState(RenderState.Lighting, true);

                // 光源を設定
                device.SetLight(0, new Light()
                {
                    Type = LightType.Directional,
                    Diffuse = Color.White,
                    Ambient = Color.GhostWhite,
                    Direction = new Vector3(0.0f, -1.0f, 0.0f)
                });

                // 光源を有効化
                device.EnableLight(0, true);

                //射影変換を設定
                device.SetTransform(TransformState.Projection,
                    Matrix.PerspectiveFovLH((float)(Math.PI / 4),
                    (float)(this.Width / this.Height),
                    0.1f, 20.0f));

                //ビューを設定
                device.SetTransform(TransformState.View,
                    Matrix.LookAtLH(new Vector3(3.0f, 2.0f, -3.0f),
                    Vector3.Zero,
                    new Vector3(0.0f, 1.0f, 0.0f)));

                //マテリアル設定
                device.Material = new Material()
                {
                    Diffuse = new Color4(Color.GhostWhite)
                };

                // 描画される時に描画処理を実行
                CompositionTarget.Rendering += (sender2, e2) =>
                {
                    // 画像をロックしてバックバッファーに設定
                    this.directXImage.Lock();
                    this.directXImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, device.GetBackBuffer(0, 0).ComPointer);

                    // フロントバッファーがあれば
                    if (directXImage.IsFrontBufferAvailable)
                    {
                        // デバイスの現在の状態を確かめて失敗したら
                        if (device.TestCooperativeLevel().IsFailure)
                        {
                            // 例外
                            throw new Direct3D9Exception("デバイスが無効です");
                        }

                        // 全面灰色でクリア
//.........这里部分代码省略.........
开发者ID:aokomoriuta,项目名称:StudiesOfOpenTK,代码行数:101,代码来源:MainWindow.cs

示例13: Initialize

        public void Initialize(WindowSurface window)
        {
            if (Initialized) return;

            Window = window;

            try
            {
                _presentParameters = new PresentParameters();
                _presentParameters.Windowed = true;
                _presentParameters.SwapEffect = SwapEffect.Discard;
                _presentParameters.BackBufferCount = 1;
                _presentParameters.BackBufferWidth = window.Width;
                _presentParameters.BackBufferHeight = window.Height;
                _presentParameters.BackBufferFormat = Format.X8R8G8B8;
                _presentParameters.DeviceWindowHandle = window.Handle;

                _device = new Device(Manager.Adapters.Default.Adapter,
                    DeviceType.Hardware,
                    Window.Handle,
                    CreateFlags.HardwareVertexProcessing,
                    _presentParameters);

                //_device.RenderState.AlphaBlendEnable = true;
                //_device.RenderState.IndexedVertexBlendEnable = true;
                //_device.RenderState.AlphaSourceBlend = Blend.SourceAlpha;
                //_device.RenderState.SourceBlend = Blend.SourceAlpha;
                //_device.RenderState.AlphaFunction = Compare.Always;
                //_device.RenderState.DestinationBlend = Blend.SourceAlpha;
                //_device.RenderState.AlphaFunction = BlendFunction.Add;

                _device.RenderState.AlphaBlendEnable = true;
                _device.RenderState.AlphaTestEnable = true;
                _device.RenderState.SourceBlend = Blend.SourceAlpha;
                _device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
                _device.RenderState.BlendOperation = BlendOperation.Add;
                _device.RenderState.AlphaSourceBlend = Blend.Zero;
                _device.RenderState.AlphaDestinationBlend = Blend.Zero;
                _device.RenderState.AlphaBlendOperation = BlendOperation.Add;

                _device.RenderState.AlphaFunction = Compare.Always;
                _device.RenderState.VertexBlend = VertexBlend.ZeroWeights;

                _device.SetRenderState(RenderStates.ZEnable, false);
                _device.SetRenderState(RenderStates.Lighting, false);
                _device.VertexFormat = CustomVertex.TransformedColored.Format;

                _device.DeviceLost += new EventHandler(OnDeviceLost);
                _device.DeviceReset += new EventHandler(OnResetDevice);

                Gemoetry = new GemoetryRenderer(this);

                Core.Components.Require<GameLoop>().Subscribe(this);

                Initialized = true;
            }
            catch (Direct3DXException ex)
            {
                MessageBox.Show(string.Format("{0}{1} (0x{2:X})", ERR_D3D_INITIALIZE, ex.ErrorString, ex.ErrorCode),
                    "GraphicsDevice::Initialize", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (DirectXException ex)
            {
                MessageBox.Show(string.Format("{0}{1} (0x{2:X})", ERR_D3D_INITIALIZE, ex.ErrorString, ex.ErrorCode),
                    "GraphicsDevice::Initialize", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ERR_D3D_INITIALIZE + ex.Message,
                    "GraphicsDevice::Initialize", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:Rewtek,项目名称:GameLibrary,代码行数:72,代码来源:GraphicsDevice.cs

示例14: Render

        /// <summary>Renders the view.</summary>
        public void Render(Device device)
        {
            device.SetRenderState(RenderState.CullMode, Cull.None);
            device.SetRenderState(RenderState.ZEnable, ZBufferType.DontUseZBuffer);
            device.SetRenderState(RenderState.ZWriteEnable, false);

            device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point);
            device.SetSamplerState(0, SamplerState.MagFilter, _useLinearFiltering ? TextureFilter.Linear : TextureFilter.Point);
            device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Point);

            device.SetRenderState(RenderState.ShadeMode, ShadeMode.Flat);
            device.SetRenderState(RenderState.FillMode, FillMode.Solid);

            device.SetRenderState(RenderState.Lighting, false);
            device.SetTexture(0, _viewTexture);

            device.SetStreamSource(0, _vertexBuffer, 0, Marshal.SizeOf(typeof(DX9TransformedColorTexture)));
            device.VertexDeclaration = _vertexDeclaration;
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
        }
开发者ID:retrozombie,项目名称:Hovertank3DdotNet,代码行数:21,代码来源:DX9SoftwareRenderer.cs

示例15: RenderBezier

        public void RenderBezier(ViewportInfo viewportInfo)
        {
            pp = new PresentParameters();
            pp.SwapEffect = SwapEffect.Discard;
            pp.Windowed = true;
            pp.BackBufferWidth = viewportInfo.resX;
            pp.BackBufferHeight = viewportInfo.resY;
            pp.BackBufferFormat = Format.A8R8G8B8;

            d3dBezier = new Direct3D();

            deviceBezier = new Device(d3dBezier, 0, DeviceType.Hardware, handleBezier, CreateFlags.HardwareVertexProcessing, pp);

            deviceBezier.SetRenderState(RenderState.Lighting, true);

            deviceBezier.SetLight(0, defLight);
            deviceBezier.EnableLight(0, true);

            deviceBezier.SetRenderState(RenderState.FillMode, wireframe ? 2 : 0);
            deviceBezier.SetRenderState(RenderState.CullMode, 1);

            deviceBezier.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(230, 230, 230), 1.0f, 0);

            deviceBezier.Present();

            d3dBezier.Dispose();
            deviceBezier.Dispose();
        }
开发者ID:BGCX261,项目名称:zpi-modeler-svn-to-git,代码行数:28,代码来源:Renderer.cs


注:本文中的Device.SetRenderState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。