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


C# Viewport类代码示例

本文整理汇总了C#中Viewport的典型用法代码示例。如果您正苦于以下问题:C# Viewport类的具体用法?C# Viewport怎么用?C# Viewport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: InitalizeGraphics

		private void InitalizeGraphics()
		{
			if (Window.RenderCanvasHandle == IntPtr.Zero)
				throw new InvalidOperationException("Window handle cannot be zero");

			SwapChainDescription swapChainDesc = new SwapChainDescription()
			{
				BufferCount = 1,
				Flags = SwapChainFlags.None,
				IsWindowed = true,
				OutputHandle = Window.RenderCanvasHandle,
				SwapEffect = SwapEffect.Discard,
				Usage = Usage.RenderTargetOutput,
				ModeDescription = new ModeDescription()
				{
					Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
					//Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
					Width = Window.ClientSize.Width,
					Height = Window.ClientSize.Height,
					RefreshRate = new Rational(60, 1),
					Scaling = DisplayModeScaling.Unspecified,
					ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified
				},
				SampleDescription = new SampleDescription(1, 0)
			};

			var giFactory = new SlimDX.DXGI.Factory();
			var adapter = giFactory.GetAdapter(0);

			Device device;
			SwapChain swapChain;
			Device.CreateWithSwapChain(adapter, DriverType.Hardware, DeviceCreationFlags.None, swapChainDesc, out device, out swapChain);
			_swapChain = swapChain;
			GraphicsDevice = device;

			// create a view of our render target, which is the backbuffer of the swap chain we just created
			using (var resource = SlimDX.Direct3D10.Resource.FromSwapChain<Texture2D>(swapChain, 0))
			{
				_backBuffer = new RenderTargetView(device, resource);
			}

			// setting a viewport is required if you want to actually see anything
			var viewport = new Viewport(0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
			device.OutputMerger.SetTargets(_backBuffer);
			device.Rasterizer.SetViewports(viewport);

			CreateDepthStencil();
			LoadVisualizationEffect();

			// Allocate a large buffer to write the PhysX visualization vertices into
			// There's more optimized ways of doing this, but for this sample a large buffer will do
			_userPrimitivesBuffer = new SlimDX.Direct3D10.Buffer(GraphicsDevice, VertexPositionColor.SizeInBytes * 50000, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None);

			var elements = new[]
			{
				new InputElement("Position", 0, Format.R32G32B32A32_Float, 0, 0),
				new InputElement("Color", 0, Format.R32G32B32A32_Float, 16, 0)
			};
			_inputLayout = new InputLayout(GraphicsDevice, _visualizationEffect.RenderScenePass0.Description.Signature, elements);
		}
开发者ID:dkushner,项目名称:PhysX.NET,代码行数:60,代码来源:Engine.cs

示例2: GenerateBits

        // Pack input data to ulong
        public static ulong GenerateBits(FSLayer layer, Viewport vp, VPLayer vpLayer, Translucency trans, ushort Material, ushort depth, ushort ibID, ushort vbID)
        {
            ulong result = (ulong)layer << 62;
            result += (ulong)vp << 59;
            result += (ulong)vpLayer << 56;
            result += (ulong)trans << 54;
            int maxvb = 1 << 10;
            if (vbID > maxvb || ibID > maxvb)
            {
                // Overflow
                Common.Instance.WriteLine("VB/IB OVERFLOW!!!");
            }
            result += (ulong)vbID << 43;
            result += (ulong)ibID << 32;

            if (trans == Translucency.OPAQUE)
            {
                // Material first
                result += (ulong)Material << 16;
                result += (ulong)depth;
            }
            else
            {
                // Depth first
                result += (ulong)depth << 16;
                result += (ulong)Material;
            }

            if (vpLayer != GetVPLayer(result))
            {
                int test = 2;
            }

            return result;
        }
开发者ID:maesse,项目名称:CubeHags,代码行数:36,代码来源:SortItem.cs

示例3: InitDevice

        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        public void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(host.Handle, out swapChain);

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView }, null);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)host.ActualWidth,
                Height = (uint)host.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.SetViewports(new Viewport[] { vp });
        } 
开发者ID:Prashant-Jonny,项目名称:phever,代码行数:28,代码来源:TutorialWindow.xaml.cs

示例4: ViewportAdapter

		/// <summary>
		/// Constructor that takes an attribute list.
		/// </summary>
		/// <param name="attrList"> A <see cref="System.Int32"/>. </param>
		public ViewportAdapter(System.Int32[] attrList) : base(attrList)
		{
			Viewport = new Viewport(this);
			
			// make sure the viewport catches all events
			AddEvents((int)Gdk.EventMask.AllEventsMask);
					
			
			// mouse interaction signals
			ButtonPressEvent += OnButtonPress;
			ButtonReleaseEvent += OnButtonRelease;
			MotionNotifyEvent += OnMotionNotify;
			ScrollEvent += OnScroll;
			KeyPressEvent += OnKeyPress;
			KeyReleaseEvent += OnKeyRelease;
			
			// Connect some other signals		
			DeleteEvent += OnWindowDeleteEvent;
			ExposeEvent += OnExposed;
			Realized += OnRealized;
			SizeAllocated += OnSizeAllocated;
			ConfigureEvent += OnConfigure;	
			
			CanFocus = true;
			GrabFocus();
		}
开发者ID:erisonliang,项目名称:monoworks,代码行数:30,代码来源:ViewportAdapter.cs

示例5: initialize

 public Sprite initialize(Viewport v)
 {
     created_at = DateTime.Now;
     viewport = v;
     viewport.sprites.Add(this);
     return this;
 }
开发者ID:mattiascibien,项目名称:OpenGame.exe,代码行数:7,代码来源:Sprite.cs

示例6: CheckHit

 public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
 {
     HitResult result = HitResult.NoHit;
     transform.Push();
     transform.NJTranslate(item.Position.ToVector3());
     transform.NJRotateY(item.Rotation.Y);
     transform.Push();
     transform.NJTranslate(0, 0, 10);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 2);
     result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(0, 0, 20);
     transform.NJRotateX(0x2000);
     transform.NJTranslate(0, 0, -3);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
     result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(0, 0, 20);
     transform.NJRotateX(0xE000);
     transform.NJTranslate(0, 0, -3);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
     result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
     transform.Pop();
     transform.NJScale((item.Scale.X + 10) / 5f, (item.Scale.Y + 10) / 5f, 0.1000000014901161f);
     result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
     transform.Pop();
     return result;
 }
开发者ID:Radfordhound,项目名称:sa_tools,代码行数:30,代码来源:Wall.cs

示例7: InitDevice

        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain);

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView });

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)directControl.ClientSize.Width,
                Height = (uint)directControl.ClientSize.Height,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.SetViewports(new Viewport[] { vp });
        } 
开发者ID:Prashant-Jonny,项目名称:phever,代码行数:28,代码来源:TutorialWindow.cs

示例8: SetupViewport

		void SetupViewport()
		{
			var renderer = Renderer;
			var graphics = Graphics;

			renderer.NumViewports = 2;

			// Set up the front camera viewport
			Viewport viewport = new Viewport(Context, scene, CameraNode.GetComponent<Camera>(), null);
			renderer.SetViewport(0, viewport);

			// Clone the default render path so that we do not interfere with the other viewport, then add
			// bloom and FXAA post process effects to the front viewport. Render path commands can be tagged
			// for example with the effect name to allow easy toggling on and off. We start with the effects
			// disabled.
			var cache = ResourceCache;
			RenderPath effectRenderPath = viewport.RenderPath.Clone();
			effectRenderPath.Append(cache.GetXmlFile("PostProcess/Bloom.xml"));
			effectRenderPath.Append(cache.GetXmlFile("PostProcess/FXAA2.xml"));
			// Make the bloom mixing parameter more pronounced
			effectRenderPath.SetShaderParameter("BloomMix", new Vector2(0.9f, 0.6f));

			effectRenderPath.SetEnabled("Bloom", false);
			effectRenderPath.SetEnabled("FXAA2", false);
			viewport.RenderPath = effectRenderPath;

			// Set up the rear camera viewport on top of the front view ("rear view mirror")
			// The viewport index must be greater in that case, otherwise the view would be left behind
			IntRect rect = new IntRect(graphics.Width*2/3, 32, graphics.Width - 32, graphics.Height/3);
			Viewport rearViewport = new Viewport(Context, scene, rearCameraNode.GetComponent<Camera>(), rect, null);

			renderer.SetViewport(1, rearViewport);
		}
开发者ID:cianmulville,项目名称:urho-samples,代码行数:33,代码来源:MultipleViewports.cs

示例9: LoadResources

		public void LoadResources()
		{
			if (m_Disposed == true)
			{
				Buffer = new Texture2D(GameEnvironment.Device, new Texture2DDescription()
				{
					Format = m_Format,
					Width = m_Width,
					Height = m_Height,
					OptionFlags = ResourceOptionFlags.None,
					MipLevels = 1,
					ArraySize = 1,
					BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
					CpuAccessFlags = CpuAccessFlags.None,
					SampleDescription = new SampleDescription(1, 0),
					Usage = ResourceUsage.Default
				});

				View = new RenderTargetView(GameEnvironment.Device, Buffer);
				ResourceView = new ShaderResourceView(GameEnvironment.Device, Buffer);
				Viewport = new Viewport(0, 0, Buffer.Description.Width, Buffer.Description.Height);

				m_Disposed = false;
			}
		}
开发者ID:RugCode,项目名称:drg-pt,代码行数:25,代码来源:BloomLayer.cs

示例10: Minimap

        public Minimap(Device device, DeviceContext dc, int minimapWidth, int minimapHeight, Terrain terrain, CameraBase viewCam)
        {
            _dc = dc;

            _minimapViewport = new Viewport(0, 0, minimapWidth, minimapHeight);

            CreateMinimapTextureViews(device, minimapWidth, minimapHeight);

            _terrain = terrain;

            SetupOrthoCamera();
            _viewCam = viewCam;

            // frustum vb will contain four corners of view frustum, with first vertex repeated as the last
            var vbd = new BufferDescription(
                VertexPC.Stride * 5,
                ResourceUsage.Dynamic,
                BindFlags.VertexBuffer,
                CpuAccessFlags.Write,
                ResourceOptionFlags.None,
                0
            );
            _frustumVB = new Buffer(device, vbd);

            _edgePlanes = new[] {
            new Plane(1, 0, 0, -_terrain.Width / 2),
            new Plane(-1, 0, 0, _terrain.Width / 2),
            new Plane(0, 1, 0, -_terrain.Depth / 2),
            new Plane(0, -1, 0, _terrain.Depth / 2)
            };

            ScreenPosition = new Vector2(0.25f, 0.75f);
            Size = new Vector2(0.25f, 0.25f);
        }
开发者ID:jackinf,项目名称:dx11,代码行数:34,代码来源:Minimap.cs

示例11: CreateDeviceSwapChainAndRenderTarget

        public static void CreateDeviceSwapChainAndRenderTarget(Form form,
            out Device device, out SwapChain swapChain, out RenderTargetView renderTarget)
        {
            try
            {
                // the debug mode requires the sdk to be installed otherwise an exception is thrown
                device = new Device(DeviceCreationFlags.Debug);
            }
            catch (Direct3D10Exception)
            {
                device = new Device(DeviceCreationFlags.None);
            }

            var swapChainDescription = new SwapChainDescription();
            var modeDescription = new ModeDescription();
            var sampleDescription = new SampleDescription();

            modeDescription.Format = Format.R8G8B8A8_UNorm;
            modeDescription.RefreshRate = new Rational(60, 1);
            modeDescription.Scaling = DisplayModeScaling.Unspecified;
            modeDescription.ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified;

            modeDescription.Width = WIDTH;
            modeDescription.Height = HEIGHT;

            sampleDescription.Count = 1;
            sampleDescription.Quality = 0;

            swapChainDescription.ModeDescription = modeDescription;
            swapChainDescription.SampleDescription = sampleDescription;
            swapChainDescription.BufferCount = 1;
            swapChainDescription.Flags = SwapChainFlags.None;
            swapChainDescription.IsWindowed = true;
            swapChainDescription.OutputHandle = form.Handle;
            swapChainDescription.SwapEffect = SwapEffect.Discard;
            swapChainDescription.Usage = Usage.RenderTargetOutput;

            using (var factory = new Factory())
            {
                swapChain = new SwapChain(factory, device, swapChainDescription);
            }

            using (var resource = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTarget = new RenderTargetView(device, resource);
            }

            var viewport = new Viewport
            {
                X = 0,
                Y = 0,
                Width = WIDTH,
                Height = HEIGHT,
                MinZ = 0.0f,
                MaxZ = 1.0f
            };

            device.Rasterizer.SetViewports(viewport);
            device.OutputMerger.SetTargets(renderTarget);
        }
开发者ID:Christof,项目名称:afterglow,代码行数:60,代码来源:EmptyWindow.cs

示例12: CreateRasterizer

 public static PrimitiveRasterizer CreateRasterizer(
     PrimitiveTopology primitiveTopology,
     RasterizerStateDescription rasterizerState, 
     int multiSampleCount, 
     ShaderOutputInputBindings outputInputBindings, 
     ref Viewport viewport,
     Func<int, int, bool> fragmentQuadFilter)
 {
     switch (primitiveTopology)
     {
         case PrimitiveTopology.PointList:
             throw new NotImplementedException();
         case PrimitiveTopology.LineList:
         case PrimitiveTopology.LineStrip:
             throw new NotImplementedException();
         case PrimitiveTopology.TriangleList:
         case PrimitiveTopology.TriangleStrip:
             return new TriangleRasterizer(
                 rasterizerState, multiSampleCount,
                 outputInputBindings, ref viewport,
                 fragmentQuadFilter);
         default:
             throw new ArgumentOutOfRangeException("primitiveTopology");
     }
 }
开发者ID:modulexcite,项目名称:rasterizr,代码行数:25,代码来源:PrimitiveRasterizerFactory.cs

示例13: Offset

        public static ScreenOffset Offset(Vector3 point, Rectangle bounds, Viewport viewport, Matrix projection,
            Matrix view, Matrix currentAttitude)
        {
            // Create a World matrix for the point.
            var world = Matrix.CreateWorld(point, new Vector3(0, 0, -1), new Vector3(0, 1, 0));

            // Use Viewport.Project to project the point from 3D space into screen coordinates.
            var projected = viewport.Project(Vector3.Zero, projection, view, world*currentAttitude);

            if (projected.Z > 1 || projected.Z < 0)
            {
                // If the point is outside of this range, it is behind the camera.
                // So hide the TextBlock for this point.
                return default(ScreenOffset);
            }

            // Create a TranslateTransform to position the TextBlock.
            // Offset by half of the TextBlock's RenderSize to center it on the point.
            var tt = new ScreenOffset
            {
                TranslateX = projected.X - (bounds.Width/2),
                TranslateY = projected.Y - (bounds.Height/2),

                Scale = 1/projected.Z
            };
            return tt;
        }
开发者ID:builttoroam,项目名称:BuildIt,代码行数:27,代码来源:WorldHelpers.cs

示例14: RenderTarget

 public RenderTarget(Device device, int width, int height, int sampleCount, int sampleQuality, Format format)
     : this()
 {
     Texture = _disposer.Add(new Texture2D(device, new Texture2DDescription
     {
         Format              = format,
         Width               = width,
         Height              = height,
         ArraySize           = 1,
         MipLevels           = 1,
         BindFlags           = BindFlags.RenderTarget | BindFlags.ShaderResource,
         CpuAccessFlags      = CpuAccessFlags.None,
         OptionFlags         = ResourceOptionFlags.None,
         Usage               = ResourceUsage.Default,
         SampleDescription   = new SampleDescription(sampleCount, sampleQuality),
     }));
     RenderTargetView = _disposer.Add(new RenderTargetView(device, Texture, new RenderTargetViewDescription
     {
         Format = format,
         Dimension = RenderTargetViewDimension.Texture2DMultisampled,
         //MipSlice = 0,
     }));
     
     ShaderResourceView = _disposer.Add(new ShaderResourceView(device, Texture));
     Viewport = new Viewport(0, 0, width, height, 0.0f, 1.0f);
 }
开发者ID:JoltSoftwareDevelopment,项目名称:Jolt.MashRoom,代码行数:26,代码来源:RenderTarget.cs

示例15: FilterPixelShader

        public FilterPixelShader(Device device, int imageWidth, int imageHeight, int constantBufferSize, string pixelShaderBytecodeFilename)
        {
            vertexShader = new VertexShader(device, new ShaderBytecode(File.ReadAllBytes("Content/FullScreenQuadVS.cso")));
            pixelShader = new PixelShader(device, new ShaderBytecode(File.ReadAllBytes(pixelShaderBytecodeFilename)));

            var rasterizerStateDesc = new RasterizerStateDescription()
            {
                CullMode = CullMode.None, 
                FillMode = FillMode.Solid,
                IsDepthClipEnabled = false,
                IsFrontCounterClockwise = true,
                IsMultisampleEnabled = false,
            };
            rasterizerState = new RasterizerState(device, rasterizerStateDesc);

            if (constantBufferSize > 0)
            {
                var constantBufferDesc = new BufferDescription()
                {
                    Usage = ResourceUsage.Dynamic,
                    BindFlags = BindFlags.ConstantBuffer,
                    SizeInBytes = constantBufferSize,
                    CpuAccessFlags = CpuAccessFlags.Write,
                    StructureByteStride = 0,
                    OptionFlags = 0,
                };
                constantBuffer = new Buffer(device, constantBufferDesc);
            }

            viewport = new Viewport(0, 0, imageWidth, imageHeight); // TODO: get these dimensions
            vertexBufferBinding = new VertexBufferBinding(null, 0, 0);
        }
开发者ID:Dallemanden,项目名称:RoomAliveToolkit,代码行数:32,代码来源:FilterPixelShader.cs


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