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


C# Device.BeginScene方法代码示例

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


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

示例1: loop

 public override void loop(Device i_d3d)
 {
     lock (this._ss)
     {
         this._ms.update(this._ss);
         this._rs.drawBackground(i_d3d, this._ss.getSourceImage());
         i_d3d.BeginScene();
         i_d3d.Clear(ClearFlags.ZBuffer, Color.DarkBlue, 1.0f, 0);
         if (this._ms.isExistMarker(this.mid))
         {
             //get marker plane pos from Mouse X,Y
             Point p=this.form.PointToClient(Cursor.Position);
             Vector3 mp = new Vector3();
             this._ms.getMarkerPlanePos(this.mid, p.X,p.Y,ref mp);
             mp.Z = 20.0f;
             //立方体の平面状の位置を計算
             Matrix transform_mat2 = Matrix.Translation(mp);
             //変換行列を掛ける
             transform_mat2 *= this._ms.getD3dMarkerMatrix(this.mid);
             // 計算したマトリックスで座標変換
             i_d3d.SetTransform(TransformType.World, transform_mat2);
             // レンダリング(描画)
             this._rs.colorCube(i_d3d, 40);
         }
         i_d3d.EndScene();
     }
     i_d3d.Present();
 }
开发者ID:whztt07,项目名称:NyARToolkitCS,代码行数:28,代码来源:Program.cs

示例2: Main

        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new Form1();

            var panel = form.SplitContainer.Panel1;

            var device = new Device(new Direct3D(), 0, DeviceType.Hardware, panel.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
            {
                BackBufferWidth = panel.ClientSize.Width,
                BackBufferHeight = panel.ClientSize.Height

            });

            var vertices = new VertexBuffer(device, 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
            vertices.Lock(0, 0, LockFlags.None).WriteRange(new[] {
                new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector4(400.0f, 100.0f, 0.5f, 1.0f) },
                new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector4(650.0f, 500.0f, 0.5f, 1.0f) },
                new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(150.0f, 500.0f, 0.5f, 1.0f) }
            });
            vertices.Unlock();

            var vertices2 = new VertexBuffer(device, 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
            vertices2.Lock(0, 0, LockFlags.None).WriteRange(new[] {
                new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector4(300.0f, 100.0f, 0.5f, 1.0f) },
                new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector4(550.0f, 500.0f, 0.5f, 1.0f) },
                new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(050.0f, 500.0f, 0.5f, 1.0f) }
            });
            vertices2.Unlock();

            var vertexElems = new[] {
                new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
                new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                VertexElement.VertexDeclarationEnd
            };

            var vertexDecl = new VertexDeclaration(device, vertexElems);

            MessagePump.Run(form, () =>
            {
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                device.BeginScene();

                device.SetStreamSource(0, vertices, 0, 20);
                device.VertexDeclaration = vertexDecl;
                device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

                device.SetStreamSource(0, vertices2, 0, 20);
                device.VertexDeclaration = vertexDecl;
                device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

                device.EndScene();
                device.Present();
            });

            foreach (var item in ObjectTable.Objects)
                item.Dispose();
        }
开发者ID:duk3luk3,项目名称:KSPEdit,代码行数:60,代码来源:Program.cs

示例3: TextureViewer_Load

        void TextureViewer_Load(object sender, EventArgs e)
        {
            this.Show();
            Application.DoEvents();
            pp = new PresentParameters();
            pp.BackBufferCount = 2;
            pp.SwapEffect = SwapEffect.Discard;
            pp.Windowed = true;

            Direct3D d3d = new Direct3D();
            d3d_device = new Device(d3d, 0, DeviceType.Hardware, d3dPanel.Handle, CreateFlags.HardwareVertexProcessing, pp);
            texture = Texture.FromFile(d3d_device, texturePath);

            int texWidth = texture.GetLevelDescription(0).Width;
            int texHeight = texture.GetLevelDescription(0).Height;
            d3dPanel.Top = menuStrip1.Height;
            d3dPanel.Left = 0;
            d3dPanel.ClientSize = new Size(texWidth, texHeight);
            this.ClientSize = new System.Drawing.Size(
                d3dPanel.Width,
                d3dPanel.Height + menuStrip1.Height
            );
            pp.BackBufferWidth = texWidth;
            pp.BackBufferHeight = texHeight;

            d3d_device.Reset(pp);
            sprite = new Sprite(d3d_device);

            while (this.Visible)
            {
                d3d_device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, new Color4(Color.Black), 1.0f, 0);
                d3d_device.BeginScene();
                sprite.Begin(SpriteFlags.AlphaBlend);
                Rectangle rect = new Rectangle()
                {
                    X = 0,
                    Y = 0,
                    Width = texture.GetLevelDescription(0).Width,
                    Height = texture.GetLevelDescription(0).Height
                };
                sprite.Draw(texture, rect, new Color4(Color.White));
                sprite.End();
                d3d_device.EndScene();
                d3d_device.Present();
                Application.DoEvents();
            }
        }
开发者ID:anirnet,项目名称:raf-manager,代码行数:47,代码来源:TextureViewer.cs

示例4: DrawBox

        /*
        private void DrawBox(float yaw, float pitch, float roll, float x, float y, float z)
        {
            angle += 0.01f;

            device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z);
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, verts.Length, 0, indices.Length / 3);
        }
        */

        /// <summary>
        /// render 3D objects
        /// </summary>
        /// <param name="d3d"></param>
        /// <param name="dx"></param>
        private void render3D(Device dx)
        {
            if ((initialised_3D) && (selected_display == MonoSLAM.DISPLAY_AUGMENTED_REALITY))
            {
                if ((test.enable_mapping) && (!test.calibrating))
                {
                    // Set the position of the camera
                    Vector3D camera_position = null;
                    SceneLibrary.Quaternion camera_orientation = null;
                    test.getCameraPositionOrientation(ref camera_position, ref camera_orientation);

                    dx.Transform.View = QuaternionToMatrixLookAt(camera_position, camera_orientation);

                    /*
                    Microsoft.DirectX.Quaternion q_orientation =
                        new Microsoft.DirectX.Quaternion((float)camera_orientation.GetX(),
                                     (float)camera_orientation.GetY(),
                                     (float)camera_orientation.GetZ(),
                                     (float)camera_orientation.GetR());
                    Matrix _matrixRotation = Matrix.RotationQuaternion(q_orientation);
                    float yaw = 0, pitch = 0, roll = 0;
                    camera_orientation.GetZYXEuler(ref pitch, ref yaw, ref roll);

                    dx.Transform.View = QuaternionToMatrixLookAt(camera_position, camera_orientation) *
                        Matrix.RotationYawPitchRoll(0,0,(float)(roll));
                    */


                    //dx.Material = InitMaterial(Color.White);

                    dx.Clear(ClearFlags.ZBuffer, Color.FromArgb(255, 0, 0, 0), 1.0f, 0);
                    //dx.Clear(ClearFlags.Target | ClearFlags.ZBuffer,Color.FromArgb(255, 0, 0, 0), 1.0f, 0);
                    //dx.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Transparent, 1.0f, 0);

                    if (background_image == null)
                        background_image = new D3D_background(dx, background_bitmap);
                    else
                        background_image.update(dx, background_bitmap);

                    background_image.Draw();


                    /*
                    dx.BeginScene();

                    dx.Transform.World = Matrix.Identity;
                    ScaleMatrices(dx, 1000, 0.1f, 0.1f);

                    dx.VertexFormat = Vertex.FVF_Flags;
                    dx.SetStreamSource(0, lineVertexBuffer, 0);

                    //dx.SetTexture(0, texture);

                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 4, 2);

                    dx.EndScene();

                    // this try/catch prevents an error if the scene is being rendered 
                    // whilst the window is being closed
                    try
                    {
                        dx.Present();
                    }
                    catch
                    {
                    }


                    dx.BeginScene();

                    dx.Transform.World = Matrix.Identity;
                    ScaleMatrices(dx, 0.1f, 1000, 0.1f);

                    dx.VertexFormat = Vertex.FVF_Flags;
                    dx.SetStreamSource(0, lineVertexBuffer, 0);

                    //dx.SetTexture(0, texture);

                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 4, 2);

                    dx.EndScene();

                    // this try/catch prevents an error if the scene is being rendered 
//.........这里部分代码省略.........
开发者ID:iManbot,项目名称:monoslam,代码行数:101,代码来源:frmMain.cs

示例5: Draw

        /// <summary>
        /// Draws the gizmo onscreen.
        /// </summary>
        /// <param name="d3ddevice"></param>
        /// <param name="cam"></param>
        public void Draw(Device d3ddevice, EditorCamera cam)
        {
            if ((affectedPoint == null) || (!enabled))
                return;

            d3ddevice.RenderState.ZBufferEnable = true;
            d3ddevice.BeginScene();

            RenderInfo.Draw(Render(d3ddevice, new MatrixStack(), cam), d3ddevice, cam);

            d3ddevice.EndScene(); //all drawings before this line
        }
开发者ID:Radfordhound,项目名称:sa_tools,代码行数:17,代码来源:PointHelper.cs

示例6: Start

        public override void Start()
        {
            base.Start();
            var form = new RenderForm("02_vertex_and_fragment_program");
            this.device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters
                                                                                                                                {
                                                                                                                                    BackBufferWidth = form.ClientSize.Width,
                                                                                                                                    BackBufferHeight = form.ClientSize.Height
                                                                                                                                });
            int vertexCount = 0;

            for (int i = 0; i < MyStarCount; i++)
            {
                vertexCount += myStarList[i].Points * 2 + 2;
            }

            vertexBuffer = new VertexBuffer(device, vertexCount * 12, Usage.WriteOnly, VertexFormat.Position, Pool.Default);

            Vector3[] starVertices = new Vector3[vertexCount];
            var dataStream = vertexBuffer.Lock(0, 0, LockFlags.Discard);
            for (int i = 0, n = 0; i < myStarList.Length; i++)
            {
                double piOverStarPoints = 3.14159 / myStarList[i].Points;
                float x = myStarList[i].X,
                      y = myStarList[i].Y,
                      outerRadius = myStarList[i].OuterRadius,
                      r = myStarList[i].InnerRadius;
                double angle = 0.0;

                /* Center of star */
                starVertices[n++] = new Vector3(x, y, 0);
                /* Emit exterior vertices for star's points. */
                for (int j = 0; j < myStarList[i].Points; j++)
                {
                    starVertices[n++] = new Vector3(x + outerRadius * (float)Math.Cos(angle), y + outerRadius * (float)Math.Sin(angle), 0);
                    angle -= piOverStarPoints;
                    starVertices[n++] = new Vector3(x + r * (float)Math.Cos(angle), y + r * (float)Math.Sin(angle), 0);
                    angle -= piOverStarPoints;
                }
                /* End by repeating first exterior vertex of star. */
                angle = 0;
                starVertices[n++] = new Vector3(x + outerRadius * (float)Math.Cos(angle), y + outerRadius * (float)Math.Sin(angle), 0);
            }
            dataStream.WriteRange(starVertices);
            dataStream.Position = 0;
            vertexBuffer.Unlock();

            this.CgContext = Context.Create();
            this.CgContext.ParameterSettingMode = ParameterSettingMode.Deferred;
            this.CreateCgPrograms();

            form.Show();
            while (form.Visible)
            {
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0.1f, 0.3f, 0.6f), 1.0f, 0);
                device.BeginScene();

                vertexProgram.Bind();
                fragmentProgram.Bind();

                /* Render the triangle. */
                device.SetStreamSource(0, vertexBuffer, 0, 12);
                device.VertexFormat = VertexFormat.Position;
                for (int i = 0; i < MyStarCount; i++)
                {
                    device.DrawPrimitives(PrimitiveType.TriangleFan, i * 12, 10);
                }
                device.EndScene();
                device.Present();
                Application.DoEvents();
            }

            fragmentProgram.Dispose();
            vertexProgram.Dispose();
            this.CgContext.Dispose();
            foreach (var item in ObjectTable.Objects)
            {
                item.Dispose();
            }
        }
开发者ID:himanshugoel2797,项目名称:CrossEngine,代码行数:80,代码来源:VertexFragmentProgram.cs

示例7: Main


//.........这里部分代码省略.........
                if (!GameEngine.Instance.PauseRendering)
                {
                    int score = GameEngine.Instance.PlayerScore;
                    int life = GameEngine.Instance.PlayerLife;
                    int hiscore = GameEngine.Instance.HiScore;

                    //Time to spawn?
                    GameEngine.Instance.SpawnTimer.Stop();
                    if ((float)GameEngine.Instance.SpawnTimer.Elapsed >= GameEngine.Instance.SpawnFrequency)
                    {
                        GameEngine.Instance.SpawnEnemy(GameEngine.Instance.PlayerLevel);
                        if((GameEngine.Instance.SpawnFrequency - GameTypes.GAME_SPAWN_SPEEDUP_RATE >= GameTypes.GAME_SPAWN_MIN_FREQ))
                            GameEngine.Instance.SpawnFrequency -= GameTypes.GAME_SPAWN_SPEEDUP_RATE;

                        for(int i =0;i<GameTypes.GAME_LEVEL_FREQ.Length;i++)
                            if(GameEngine.Instance.SpawnFrequency <= GameTypes.GAME_LEVEL_FREQ[i])
                                GameEngine.Instance.PlayerLevel = i;

                        GameEngine.Instance.SpawnTimer.Start();
                    }
                    else
                    {
                        //if (GameEngine.Instance.Enemies.Count == 1)
                          //  GameEngine.Instance.SpawnEnemy(GameEngine.Instance.PlayerLevel);
                    }

                    GameEngine.Instance.LifeTimer.Stop();
                    float time = (float)GameEngine.Instance.LifeTimer.Elapsed;
                    float fps = (float)GameEngine.Instance.FPSTimer.FPS;
                    float ticks = (float)GameEngine.Instance.LifeTimer.GetTicks(0.017f);
                    WindowManager.Instance.Main.showelapsed(time, fps, ticks);

                    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                    device.BeginScene();

                    //draw maze

                    TextureManager.Instance.spritey.Begin(SpriteFlags.AlphaBlend | SpriteFlags.DoNotAddRefTexture);
                    for (int y = 0; y < GameTypes.MAP_HEIGHT; y++)
                    {
                        for (int x = 0; x < GameTypes.MAP_WIDTH; x++)
                        {
                            if (PathFinding.Instance.GetNode(x, y).Walkable)
                                TextureManager.Instance.spritey.Draw(TextureManager.Instance.ddsTestTile, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0), new Vector3(x * 32, y * 32, 0), new Color4(Color.White));
                            else
                                TextureManager.Instance.spritey.Draw(TextureManager.Instance.ddsTestTileOut, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0), new Vector3(x * 32, y * 32, 0), new Color4(Color.White));
                        }
                    }

                    //draw shiny
                    TextureManager.Instance.spritey.Draw(TextureManager.Instance.pngShiny, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0), new Vector3(GameEngine.Instance.ShinyLocation.X*32,GameEngine.Instance.ShinyLocation.Y*32,0), new Color4(Color.White));

                    //sprite update
                    GameEngine.Instance.TestSpriteTimer.Stop();
                    if (GameEngine.Instance.TestSpriteTimer.Elapsed > 0.017)
                    {
                        GameEngine.Instance.ThePlayer.Update();
                        //GameEngine.Instance.testvec.X += 0.5f;
                        //GameEngine.Instance.testEnemy.UpdateMove();

                        // move enemies
                        foreach (Enemy enemy in GameEngine.Instance.Enemies)
                        {
                            if (enemy.Active)
                                enemy.UpdateMove();
                            else
开发者ID:JamesPersaud,项目名称:EnemyMaze,代码行数:67,代码来源:Program.cs

示例8: drawPostProcess

        /// <summary>
        /// Se toma todo lo dibujado antes, que se guardo en una textura, y se le aplica un shader para borronear la imagen
        /// </summary>
        private void drawPostProcess(Device d3dDevice)
        {
            //Arrancamos la escena
            d3dDevice.BeginScene();

            //Cargamos para renderizar el unico modelo que tenemos, un Quad que ocupa toda la pantalla, con la textura de todo lo dibujado antes
            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            d3dDevice.SetStreamSource(0, screenQuadVB, 0);

            //Ver si el efecto de oscurecer esta activado, configurar Technique del shader segun corresponda
            if (activar_efecto)
            {
                effect.Technique = "BlurTechnique";
            }
            else
            {
                effect.Technique = "DefaultTechnique";
            }

            //Cargamos parametros en el shader de Post-Procesado
            effect.SetValue("render_target2D", renderTarget2D);
            effect.SetValue("blur_intensity", blur_intensity);

            //Limiamos la pantalla y ejecutamos el render del shader
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            effect.Begin(FX.None);
            effect.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            effect.EndPass();
            effect.End();

            //Terminamos el renderizado de la escena
            d3dDevice.EndScene();
        }
开发者ID:JSorella,项目名称:AlumnoEjemplos,代码行数:37,代码来源:EjemploAlumno.cs

示例9: drawPostProcess

        /// <summary>
        /// Se toma todo lo dibujado antes, que se guardo en una textura, y se combina con otra textura, que en este ejemplo
        /// es para generar un efecto de alarma.
        /// Se usa un shader para combinar ambas texturas y lograr el efecto de alarma.
        /// </summary>
        private void drawPostProcess(Device d3dDevice)
        {
            //Arrancamos la escena
            d3dDevice.BeginScene();

            //Cargamos para renderizar el unico modelo que tenemos, un Quad que ocupa toda la pantalla, con la textura de todo lo dibujado antes
            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            d3dDevice.SetStreamSource(0, screenQuadVB, 0);

            //Ver si el efecto de alarma esta activado, configurar Technique del shader segun corresponda
            bool activar_efecto = (bool)GuiController.Instance.Modifiers["activar_efecto"];
            if (activar_efecto)
            {
                effect.Technique = "AlarmaTechnique";
            }
            else
            {
                effect.Technique = "DefaultTechnique";
            }

            //Cargamos parametros en el shader de Post-Procesado
            effect.SetValue("render_target2D", renderTarget2D);
            effect.SetValue("textura_alarma", alarmTexture.D3dTexture);
            effect.SetValue("alarmaScaleFactor", intVaivenAlarm.update());

            //Limiamos la pantalla y ejecutamos el render del shader
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            effect.Begin(FX.None);
            effect.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            effect.EndPass();
            effect.End();

            //Terminamos el renderizado de la escena
            d3dDevice.EndScene();
        }
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:41,代码来源:EfectoAlarma.cs

示例10: PostProcess

        /// <summary>
        /// Aplica efectos de post-procesamiento
        /// </summary>
        /// <param name="d3dDevice"></param>
        private void PostProcess(Device d3dDevice)
        {
            d3dDevice.BeginScene();

            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            d3dDevice.SetStreamSource(0, vbPostProcessMesh, 0);

            // \TODO JJ: multiples efectos en multiples render targets
            if (PostProcessing.LensDistortion)
            {
                postProcessEffect.Technique = "LensDistortion";
                postProcessEffect.SetValue("lens_radius", PostProcessing.LensRadius);

                postProcessEffect.SetValue("chromatic_aberrance_factor",
                    (float)GuiController.Instance.Modifiers.getValue(CHROMATIC_ABERRANCE_FACTOR_MOD));

                postProcessEffect.SetValue("blue_tint_factor",
                    (float)GuiController.Instance.Modifiers.getValue(BLUE_TINT_FACTOR_MOD));

                postProcessEffect.SetValue("k",
                    (float)GuiController.Instance.Modifiers.getValue(LENS_DISTORTION_K_MOD));

                postProcessEffect.SetValue("kcube",
                    (float)GuiController.Instance.Modifiers.getValue(LENS_DISTORTION_KCUBE_MOD));

                Size screen = GuiController.Instance.Panel3d.Size;

                postProcessEffect.SetValue("screen_w", screen.Width);
                postProcessEffect.SetValue("screen_h", screen.Height);
                postProcessEffect.SetValue("screen_center_x", screen.Width / 2);
                postProcessEffect.SetValue("screen_center_y", screen.Height / 2);
            }
            else
                postProcessEffect.Technique = "NoEffect";

            postProcessEffect.SetValue("pre_render", preTargetTexture);

            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            postProcessEffect.Begin(FX.None);
            postProcessEffect.BeginPass(0);

            d3dDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

            postProcessEffect.EndPass();
            postProcessEffect.End();

            d3dDevice.EndScene();
        }
开发者ID:javs,项目名称:Snipers-CEGA,代码行数:53,代码来源:Snipers.cs

示例11: drawPostProcess

        /// <summary>
        /// Se toma todo lo dibujado antes, que se guardo en una textura, y se le aplica un shader para borronear la imagen
        /// </summary>
        private void drawPostProcess(Device d3dDevice, float elapsedTime)
        {
            //Arrancamos la escena
            d3dDevice.BeginScene();

            //Cargamos para renderizar el unico modelo que tenemos, un Quad que ocupa toda la pantalla, con la textura de todo lo dibujado antes
            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            d3dDevice.SetStreamSource(0, screenQuadVB, 0);

            effect.Technique = "AlarmaTechnique";

            //Cargamos parametros en el shader de Post-Procesado
            effect.SetValue("render_target2D", renderTarget2D);
            effect.SetValue("textura_alarma", alarmTexture.D3dTexture);
            effect.SetValue("alarmaScaleFactor", intVaivenAlarm.update());

            //Limiamos la pantalla y ejecutamos el render del shader
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            effect.Begin(FX.None);
            effect.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            effect.EndPass();
            effect.End();

            //Terminamos el renderizado de la escena
            d3dDevice.EndScene();
        }
开发者ID:nicolasazrak,项目名称:RenderMan,代码行数:30,代码来源:PostProcesadoManager.cs

示例12: GetSceneImage


//.........这里部分代码省略.........
            {
                device.EnableLight(i, false);
            }
            maxLights = scene.lights.Count;

            Modeler.Transformations.BoundingBox bb = new Modeler.Transformations.BoundingBox(scene);
            Camera cam = new Camera();
            Vector3 dir = Vector3.Normalize(bb.minBB - bb.maxBB);
            cam.position = bb.maxBB - 1 * (float)Math.Sqrt((bb.minBB.x - bb.maxBB.x) * (bb.minBB.x - bb.maxBB.x) +
                (bb.minBB.y - bb.maxBB.y) * (bb.minBB.y - bb.maxBB.y) + (bb.minBB.z - bb.maxBB.z) * (bb.minBB.z - bb.maxBB.z)) * dir;
            cam.lookAt = bb.maxBB;
            cam.fovAngle = 40;
            cam.rotateAngle = 0;

            Vector3 oldDir = defLight.Direction;

            Vector3 dirLight = new Vector3();
            dirLight.X = dir.X * (float)Math.Cos(-Math.PI / 4) + dir.Z * (float)Math.Sin(-Math.PI / 4);
            dirLight.Y = dir.Y;
            dirLight.Z = dir.Z * (float)Math.Cos(-Math.PI / 4) - dir.X * (float)Math.Sin(-Math.PI / 4);
            dir.Normalize();
            defLight.Direction = dirLight;
            device.SetLight(0, defLight);
            device.EnableLight(0, true);

            device.SetRenderState(RenderState.FillMode, FillMode.Solid);
            device.SetRenderState(RenderState.CullMode, Cull.None);
            device.SetRenderState(RenderState.ShadeMode, ShadeMode.Gouraud);

            Mesh mesh = numIndices >= 3 ? new Mesh(device, (int)numIndices / 3, scene.points.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vertexElems) : null;
            VertexBuffer vb = mesh != null ? mesh.VertexBuffer : null;
            IndexBuffer ib = mesh != null ? mesh.IndexBuffer : null;

            if(mesh != null)
            {
                vb.Lock(0, 0, LockFlags.None).WriteRange(vertices);
                vb.Unlock();

                ib.Lock(0, 0, LockFlags.None).WriteRange(indices, 0, (int)numIndices);
                ib.Unlock();
            }

            Mesh selMesh = numSelIndices >= 3 ? new Mesh(device, (int)numSelIndices / 3, scene.points.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vertexElems) : null;
            VertexBuffer selvb = selMesh != null ? selMesh.VertexBuffer : null;
            IndexBuffer selib = selMesh != null ? selMesh.IndexBuffer : null;

            if(selMesh != null)
            {
                selvb.Lock(0, 0, LockFlags.None).WriteRange(vertices);
                selvb.Unlock();

                selib.Lock(0, 0, LockFlags.None).WriteRange(selIndices, 0, (int)numSelIndices);
                selib.Unlock();
            }

            Viewport viewport = new Viewport(0, 0, 512, 512, 0, 1);

            Texture texture = new Texture(device, 64, 64, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            device.SetRenderTarget(0, texture.GetSurfaceLevel(0));

            float camRotAngle = cam.rotateAngle;
            float aspect = 1;
            float camAngle = 2.0f * (float)Math.Atan(Math.Tan(Utilities.DegToRad(cam.fovAngle) / 2.0f) / aspect);

            device.SetTransform(TransformState.View, Matrix.LookAtRH(
                cam.position,
                cam.lookAt,
                Utilities.RotatePointAroundVector(new Vector3(0, 1, 0),
                Vector3.Normalize(cam.lookAt - cam.position), camRotAngle)));

            device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovRH(
                camAngle,
                aspect,
                0.01f,
                110000));

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1.0f, 0);
            device.BeginScene();

            if(mesh != null)
            {
                mesh.DrawSubset(0);
            }

            if(selMesh != null)
            {
                selMesh.DrawSubset(0);
            }

            device.EndScene();

            Image image = Bitmap.FromStream(Texture.ToStream(texture, ImageFileFormat.Png));

            texture.Dispose();

            RecalculateData(currScene);
            defLight.Direction = oldDir;

            return image;
        }
开发者ID:BGCX261,项目名称:zpi-modeler-svn-to-git,代码行数:101,代码来源:Renderer.cs

示例13: RenderDatabaseTree

        public static TextureMatrixLayer[] RenderDatabaseTree(RasterDatabase.RasterDatabase db, Device device)
        {
            // setup device
            device.RenderState.ZBufferEnable = false;
            device.Indices = null;
            device.VertexFormat = CustomVertex.TransformedTextured.Format;
            //device.Transform.World = Matrix.Identity;
            Surface rt0 = device.GetRenderTarget(0);

            // setup template quad
            CustomVertex.TransformedTextured[] tQuad = new CustomVertex.TransformedTextured[4];

            foreach(DataLayer layer in db.Layers)
            {
                RectangleGroupQuadTree tree = db.ProduceLayerMipMap(layer, 2048);
                Texture[][] textures = new Texture[tree.Depth][];
                for (int i = 1; i <= tree.Depth; i++)
                {
                    RectangleGroupQuadTree.GroupNode[] nodes;
                    tree.GetNodes(i, out nodes);
                    textures[i] = new Texture[nodes.Length];

                    // render each node to texture
                    int texIdx = 0;
                    foreach (RectangleGroupQuadTree.GroupNode node in nodes)
                    {
                        Texture texture = textures[i][texIdx++] = new Texture(device, node.NodeArea.Width,
                                                                              node.NodeArea.Height, 0,
                                                                              Usage.WriteOnly, Format.X8R8G8B8,
                                                                              Pool.Managed);
                        device.SetRenderTarget(0, texture.GetSurfaceLevel(0));

                        device.Clear(ClearFlags.Target, Color.Black, 1, 0);
                        device.BeginScene();

                        // draw each rectangle quad
                        foreach (DataArea area in node.Rectangles)
                        {
                            // setup quad
                            tQuad[0] = new CustomVertex.TransformedTextured(area.Area.Left, area.Area.Top, 1, 1,
                                                                            area.TexCoords.Left, area.TexCoords.Top);
                            tQuad[1] = new CustomVertex.TransformedTextured(area.Area.Right, area.Area.Top, 1, 1,
                                                                            area.TexCoords.Right, area.TexCoords.Top);
                            tQuad[2] = new CustomVertex.TransformedTextured(area.Area.Left, area.Area.Bottom, 1, 1,
                                                                            area.TexCoords.Left, area.TexCoords.Bottom);
                            tQuad[3] = new CustomVertex.TransformedTextured(area.Area.Right, area.Area.Bottom, 1, 1,
                                                                            area.TexCoords.Right, area.TexCoords.Bottom);

                            // render quad
                            device.SetTexture(0, (Texture)area.Data);
                            device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, tQuad);
                        }
                        device.EndScene();
                    }
                }
            }

            device.SetRenderTarget(0, rt0);
            device.RenderState.ZBufferEnable = true;

            return null;
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:62,代码来源:RasterDatabaseRenderer.cs

示例14: GetBezierImage


//.........这里部分代码省略.........
            deviceBezier.SetRenderState(RenderState.CullMode, Cull.None);
            deviceBezier.SetRenderState(RenderState.ShadeMode, ShadeMode.Gouraud);

            Vertex[] gridVertices = new Vertex[bezier.OutputPoints.Length];
            Vertex[] controlVertices = new Vertex[bezier.ControlPoints.Length];

            List<int>[] vertexTriangle = new List<int>[bezier.OutputPoints.Length];
            Parallel.For(0, vertexTriangle.Length, index => vertexTriangle[index] = new List<int>());
            /*for(int i = 0; i < vertexTriangle.Length; ++i)
            {
                vertexTriangle[i] = new List<int>();
            }*/

            int[] indices = new int[3 * bezier.triangles.Count];
            //int[] selIndices = new int[3 * scene.triangles.Count];
            uint numIndices = 0;
            //uint numSelIndices = 0;

            //bool[] selPoints = new bool[scene.points.Count];
            //Parallel.For(0, selPoints.Length, index => selPoints[index] = false);

            for (int i = 0; i < bezier.triangles.Count; i++)
            {
                indices[numIndices++] = (int)bezier.triangles[i].p1;
                indices[numIndices++] = (int)bezier.triangles[i].p2;
                indices[numIndices++] = (int)bezier.triangles[i].p3;

                vertexTriangle[bezier.triangles[i].p1].Add(i);
                vertexTriangle[bezier.triangles[i].p2].Add(i);
                vertexTriangle[bezier.triangles[i].p3].Add(i);
            }

            // Liczenie normalnych siatki trojkątów
            for (int i = 0; i < bezier.OutputPoints.Length; i++)
            {
                Vector3 normal = new Vector3();
                foreach (int face in vertexTriangle[i])
                {
                    normal += Utilities.CalculateNormal(bezier.OutputPoints[(int)bezier.triangles[face].p3], bezier.OutputPoints[(int)bezier.triangles[face].p2],
                            bezier.OutputPoints[(int)bezier.triangles[face].p1]);
                }
                normal.Normalize();

                gridVertices[i].Position = new Vector3(bezier.OutputPoints[i].x, bezier.OutputPoints[i].y, bezier.OutputPoints[i].z);
                gridVertices[i].Normal = normal;
                gridVertices[i].Color = Color.Beige.ToArgb();

            }

            Mesh gridMesh = numIndices > 2 ? new Mesh(deviceBezier, (int)numIndices / 3, bezier.OutputPoints.Length, MeshFlags.Managed | MeshFlags.Use32Bit,
                                                        vertexElems) : null;
            VertexBuffer vb = gridMesh != null ? gridMesh.VertexBuffer : null;
            IndexBuffer ib = gridMesh != null ? gridMesh.IndexBuffer : null;

            if (gridMesh != null)
            {
                vb.Lock(0, 0, LockFlags.None).WriteRange(gridVertices);
                vb.Unlock();

                ib.Lock(0, 0, LockFlags.None).WriteRange(indices, 0, (int)numIndices);
                ib.Unlock();
            }

            Viewport viewport = new Viewport(0, 0, 512, 512, 0, 1);

            Texture texture = new Texture(deviceBezier, 64, 64, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            deviceBezier.SetRenderTarget(0, texture.GetSurfaceLevel(0));

            float aspect = (float)perspective.Width / perspective.Height;

            deviceBezier.SetTransform(TransformState.View, Matrix.LookAtRH(
                bezierCam.position,
                bezierCam.lookAt,
                Utilities.RotatePointAroundVector(new Vector3(0, 1, 0),
                Vector3.Normalize(bezierCam.lookAt - bezierCam.position), bezierCam.rotateAngle)));

            deviceBezier.SetTransform(TransformState.Projection, Matrix.PerspectiveFovRH(
                bezierCam.fovAngle,
                aspect,
                0.01f,
                110000));

            deviceBezier.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1.0f, 0);
            deviceBezier.BeginScene();

            if (gridMesh != null)
            {
                gridMesh.DrawSubset(0);
            }

            deviceBezier.EndScene();

            Image image = Bitmap.FromStream(Texture.ToStream(texture, ImageFileFormat.Png));

            texture.Dispose();

            bezierImageCreated = true;

            return image;
        }
开发者ID:BGCX261,项目名称:zpi-modeler-svn-to-git,代码行数:101,代码来源:Renderer.cs

示例15: OnFrameRender

        /// <summary>
        /// This callback function will be called at the end of every frame to perform all the 
        /// rendering calls for the scene, and it will also be called if the window needs to be 
        /// repainted. After this function has returned, the sample framework will call 
        /// Device.Present to display the contents of the next buffer in the swap chain
        /// </summary>
        public void OnFrameRender(Device device, double appTime, float elapsedTime) {
            bool beginSceneCalled = false;

            // Clear the render target and the zbuffer 
            device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, unchecked((int)0x8C003F3F), 1.0f, 0);
            try {
                device.BeginScene();
                beginSceneCalled = true;

                // Render the arrows so the user can visually see the light direction
                ColorValue arrowColor = LightColor;
                lightControl.OnRender(arrowColor, camera.ViewMatrix, camera.ProjectionMatrix, camera.EyeLocation);

                if(nif!=null) {
                    // Update the effects now
                    Vector3 ldir=lightControl.LightDirection;
                    Vector3 edir=-camera.EyeVector;
                    Vector3 hdir=ldir+edir;
                    hdir.Normalize();
                    float[] dir=new float[] { ldir.X, ldir.Y, ldir.Z };
                    effect.SetValue(ehLightDir, dir);
                    effect.SetValue(ehLightCol, ColorOperator.Scale(LightColor, lightScale));
                    effect.SetValue(egAmbCol, ColorOperator.Scale(AmbientLightColor, ambLightScale));
                    effect.SetValue(ehViewProj, camera.ViewMatrix * camera.ProjectionMatrix);
                    dir=new float[] { camera.EyeLocation.X, camera.EyeLocation.Y, camera.EyeLocation.Z };
                    effect.SetValue(ehEyePos, dir);
                    dir=new float[] { edir.X, edir.Y, edir.Z };
                    effect.SetValue(ehEyeVec, dir);
                    dir=new float[] { hdir.X, hdir.Y, hdir.Z };
                    effect.SetValue(ehHalfVec, dir);

                    // Apply the technique contained in the effect
                    if(currentSubset==-1) nif.Render();
                    else nif.RenderSubset(currentSubset);
                }

                // Show frame rate and help, etc
                RenderText(appTime);

                // Show UI
                hud.OnRender(elapsedTime);
                sampleUi.OnRender(elapsedTime);
            } finally {
                if(beginSceneCalled) device.EndScene();
            }
        }
开发者ID:IntegralLee,项目名称:fomm,代码行数:52,代码来源:BasicHLSL.cs


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