SpriteBlendMode, SaveStateMode
1 2 | // XNA 3.1sprite.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState); |
1 2 | // XNA 4.0sprite.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); |
1 2 3 | // XNA 3.1// Sort the object layer and player sprite according to depthspriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None); |
1 2 3 | // XNA 4.0// Sort the object layer and player sprite according to depthspriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); |
1 2 | // XNA 3.1sprite.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState); |
1 2 | // XNA 4.0sprite.Begin(SpriteSortMode.Immediate, BlendState.Opaque); |
1 2 3 4 5 6 | // XNA 3.1// Draw the background image.spriteBatch.Begin(SpriteBlendMode.None);Viewport viewport = GraphicsDevice.Viewport;spriteBatch.Draw(background, new Rectangle(0, 0, viewport.Width, viewport.Height), Color.White);spriteBatch.End(); |
1 2 3 4 5 | // XNA 4.0// Draw the background image.spriteBatch.Begin(0, BlendState.Opaque);spriteBatch.Draw(background, GraphicsDevice.Viewport.Bounds, Color.White);spriteBatch.End(); |
RenderState
1 2 3 4 5 6 7 8 9 10 | // XNA 3.1// enable alpha blending and disable depth writeGraphicsDevice.RenderState.AlphaBlendEnable = true;GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = true;GraphicsDevice.RenderState.AlphaBlendOperation = BlendFunction.Add;GraphicsDevice.RenderState.AlphaSourceBlend = Blend.One;GraphicsDevice.RenderState.AlphaDestinationBlend = Blend.One;GraphicsDevice.RenderState.DepthBufferWriteEnable = false; |
1 2 3 4 | // XNA 4.0// enable alpha blending and disable depth writeGraphicsDevice.BlendState = BlendState.AlphaBlend;GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; |
1 2 3 4 5 | // XNA 3.1// reset blend and depth writeGraphicsDevice.RenderState.AlphaBlendEnable = false;GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = false;GraphicsDevice.RenderState.DepthBufferWriteEnable = true; |
1 2 3 4 | // XNA 4.0// reset blend and depth writeGraphicsDevice.BlendState = BlendState.Additive;GraphicsDevice.DepthStencilState = DepthStencilState.Default; |
1 2 3 | // XNA 3.1// enable depth bufferingGraphicsDevice.RenderState.DepthBufferEnable = true; |
1 2 3 | // XNA 4.0// enable depth bufferingGraphicsDevice.DepthStencilState = DepthStencilState.Default; |
1 2 3 4 | // XNA 3.1//disable depth bufferingGraphicsDevice.RenderState.DepthBufferWriteEnable = false;GraphicsDevice.RenderState.DepthBufferEnable = false; |
1 2 3 | // XNA 4.0//disable depth bufferingGraphicsDevice.DepthStencilState = DepthStencilState.None; |
1 2 3 4 5 6 | // XNA 3.1// set additive blend (zero on alpha)GraphicsDevice.RenderState.DepthBufferWriteEnable = false;GraphicsDevice.RenderState.AlphaBlendEnable = true;GraphicsDevice.RenderState.SourceBlend = Blend.One;GraphicsDevice.RenderState.DestinationBlend = Blend.One; |
1 2 3 4 | // XNA 4.0// set additive blend (zero on alpha)GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;GraphicsDevice.BlendState = BlendState.AlphaBlend; |
1 2 3 4 5 | // XNA 3.1// restore blend modesGraphicsDevice.RenderState.DepthBufferWriteEnable = true;GraphicsDevice.RenderState.AlphaBlendEnable = false;GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = false; |
1 2 3 4 | // XNA 4.0// restore blend modesGraphicsDevice.BlendState = BlendState.Opaque;GraphicsDevice.DepthStencilState = DepthStencilState.Default; |
1 2 3 4 5 6 7 | // XNA 3.1// set alpha blend and no depth test or writeGraphicsDevice.RenderState.DepthBufferEnable = false;GraphicsDevice.RenderState.DepthBufferWriteEnable = false;GraphicsDevice.RenderState.AlphaBlendEnable = true;GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; |
1 2 3 4 | // XNA 4.0// set alpha blend and no depth test or writeGraphicsDevice.DepthStencilState = DepthStencilState.None;GraphicsDevice.BlendState = BlendState.AlphaBlend; |
1 2 3 4 5 | // XNA 3.1// Set suitable renderstates for drawing a 3D modelGraphicsDevice.RenderState.AlphaBlendEnable = false;GraphicsDevice.RenderState.AlphaTestEnable = false;GraphicsDevice.RenderState.DepthBufferEnable = true; |
1 2 3 4 | // XNA 4.0// Set suitable renderstates for drawing a 3D modelGraphicsDevice.BlendState = BlendState.Opaque;GraphicsDevice.DepthStencilState = DepthStencilState.Default; |
1 2 3 4 5 | // XNA 3.1// additive blendGraphicsDevice.RenderState.AlphaBlendEnable = true;GraphicsDevice.RenderState.SourceBlend = Blend.One;GraphicsDevice.RenderState.DestinationBlend = Blend.One; |
1 2 3 | // XNA 4.0// additive blendGraphicsDevice.BlendState = BlendState.Additive; |
1 2 3 | // XNA 3.1// set additive blendGraphicsDevice.RenderState.DestinationBlend = Blend.One; |
1 2 3 | // XNA 4.0// set additive blendGraphicsDevice.BlendState = BlendState.Additive; |
1 2 3 | // XNA 3.1// set alpha blendGraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; |
1 2 3 | // XNA 4.0// set alpha blendGraphicsDevice.BlendState = BlendState.AlphaBlend; |
1 2 | // XNA 3.1GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; |
1 2 | // XNA 4.0 GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // XNA 3.1// set render statesGraphicsDevice.RenderState.DepthBufferEnable = false;GraphicsDevice.RenderState.DepthBufferWriteEnable = false;GraphicsDevice.RenderState.AlphaBlendEnable = true;GraphicsDevice.RenderState.SourceBlend = Blend.One;GraphicsDevice.RenderState.DestinationBlend = Blend.One;GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = true;GraphicsDevice.RenderState.AlphaBlendOperation = BlendFunction.Add;GraphicsDevice.RenderState.AlphaDestinationBlend = Blend.Zero;GraphicsDevice.RenderState.AlphaSourceBlend = Blend.Zero; // drawing code here..// restore render statesGraphicsDevice.RenderState.DepthBufferEnable = true;GraphicsDevice.RenderState.DepthBufferWriteEnable = true;GraphicsDevice.RenderState.AlphaBlendEnable = false;GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = false; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // XNA 4.0//save the statesDepthStencilState ds = GraphicsDevice.DepthStencilState;BlendState bs = GraphicsDevice.BlendState;//set render statesGraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;GraphicsDevice.BlendState = BlendState.AlphaBlend; // drawing code here..// restore render statesGraphicsDevice.DepthStencilState = ds;GraphicsDevice.BlendState = bs; |
Effect and EffectPass, Begin(), End(), CommitChanges(), Clone()
1 2 3 4 5 6 7 | // apply effect XNA 3.1blurEffect.CommitChanges();blurEffect.Begin(SaveStateMode.SaveState);blurEffect.CurrentTechnique.Passes[0].Begin();GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);blurEffect.CurrentTechnique.Passes[0].End();blurEffect.End(); |
1 2 3 | // apply effect XNA 4.0blurEffect.CurrentTechnique.Passes[0].Apply();GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); |
1 2 3 | // XNA 3.1// commit effect changeseffect.CommitChanges(); |
1 2 3 | // XNA 4.0// you will need to call EffectPass.Apply() if any of the effect properties change// Otherwise Delete it. |
1 2 3 4 | // XNA 3.1// begin effecteffect.Begin(SaveStateMode.SaveState);effect.CurrentTechnique.Passes[0].Begin(); |
1 2 3 | // XNA 4.0// begin effecteffect.CurrentTechnique.Passes[0].Apply(); |
1 2 3 4 | // XNA 3.1// end effecteffect.CurrentTechnique.Passes[0].End();effect.End(); |
1 2 | // XNA 4.0// Delete it. No longer needed. |
1 2 3 | // XNA 3.1// Make a clone of our replacement effectEffect newEffect = replacementEffect.Clone(replacementEffect.GraphicsDevice); |
1 2 3 | // XNA 4.0// Make a clone of our replacement effect. 3.1Effect newEffect = replacementEffect.Clone(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // XNA 3.1// Activate the appropriate effect techniquepostprocessEffect.CurrentTechnique = postprocessEffect.Techniques[effectTechniqueName]; // Draw a fullscreen sprite to apply the postprocessing effect.spriteBatch.Begin(SpriteBlendMode.None,SpriteSortMode.Immediate, SaveStateMode.None);postprocessEffect.Begin();postprocessEffect.CurrentTechnique.Passes[0].Begin();spriteBatch.Draw(sceneRenderTarget.GetTexture(), Vector2.Zero, Color.White);spriteBatch.End();postprocessEffect.CurrentTechnique.Passes[0].End();postprocessEffect.End(); |
1 2 3 4 5 6 7 8 | // XNA 4.0// Activate the appropriate effect techniquepostprocessEffect.CurrentTechnique = postprocessEffect.Techniques[effectTechniqueName];// Draw a fullscreen sprite to apply the postprocessing effect.spriteBatch.Begin(0, BlendState.Opaque, null, null, null, postprocessEffect);spriteBatch.Draw(sceneRenderTarget, Vector2.Zero, Color.White);spriteBatch.End(); |
ShaderProfile, TotalRealTime, TransparentBlack
1 2 3 | // XNA 3.1graphics.MinimumPixelShaderProfile = ShaderProfile.PS_3_0; //any PS number...graphics.MinimumVertexShaderProfile = ShaderProfile.VS_3_0;//any VS number... |
1 2 | // XNA 4.0// Delete it. No longer needed. |
1 2 | // XNA 3.1float myTime = (float)gameTime.TotalRealTime.TotalSeconds * 0.2f; |
1 2 | // XNA 4.0float myTime = (float)gameTime.TotalGameTime.TotalSeconds * 0.2f; |
1 2 | // XNA 3.1GraphicsDevice.Clear(Color.TransparentBlack); |
1 2 | // XNA 4.0GraphicsDevice.Clear(Color.Transparent); |
ResolveTexture2D, ResolveBackBuffer, RenderTarget2D, GetTexture, DepthStencilBuffer, PresentationParameters, MultiSampleType, MultiSampleQuality, SetRenderTarget
1 2 | // XNA 3.1ResolveTexture2D sceneMap; |
1 2 | // XNA 4.0RenderTarget2D sceneMap; |
1 2 3 4 5 6 | // XNA 3.1// Look up the resolution and format of our main backbuffer.PresentationParameters pp = GraphicsDevice.PresentationParameters;// Create a texture for reading back the backbuffer contents.sceneMap = new ResolveTexture2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, pp.BackBufferFormat); |
1 2 3 4 5 6 7 8 9 10 11 | // XNA 4.0// Look up the resolution and format of our main backbuffer.PresentationParameters pp = GraphicsDevice.PresentationParameters;// Create a texture for reading back the backbuffer contents.sceneMap = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat);//or sceneMap = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); |
1 2 | // XNA 3.1GraphicsDevice.ResolveBackBuffer(sceneMap); |
1 2 | // XNA 4.0GraphicsDevice.SetRenderTarget(sceneMap); |
1 2 3 4 5 6 | // XNA 3.1int width = GraphicsDevice.Viewport.Width;int height = GraphicsDevice.Viewport.Height;// create render targetmyRenderTarget = new RenderTarget2D(GraphicsDevice, width, height, 1, SurfaceFormat.Color); |
1 2 3 4 5 6 | // XNA 4.0int width = GraphicsDevice.Viewport.Width;int height = GraphicsDevice.Viewport.Height;// create render targetmyRenderTarget = new RenderTarget2D(GraphicsDevice, width, height, true, SurfaceFormat.Color, DepthFormat.Depth24); |
1 2 3 4 5 6 | // XNA 3.1PresentationParameters pp = GraphicsDevice.PresentationParameters;// Create custom rendertargetsceneRenderTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, pp.BackBufferFormat, pp.MultiSampleType, pp.MultiSampleQuality); |
1 2 3 4 5 6 7 | // XNA 4.0PresentationParameters pp = GraphicsDevice.PresentationParameters;// Create custom rendertargetsceneRenderTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); |
1 2 3 4 5 6 7 8 9 | // XNA 3.1PresentationParameters pp = GraphicsDevice.PresentationParameters;// Setup a DepthBufferdrawBuffer = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, SurfaceFormat.Color, pp.MultiSampleType, pp.MultiSampleQuality);drawDepthBuffer = new DepthStencilBuffer(GraphicsDevice, pp.AutoDepthStencilFormat, pp.MultiSampleType, pp.MultiSampleQuality); |
1 2 3 4 5 6 7 8 | // XNA 4.0PresentationParameters pp = GraphicsDevice.PresentationParameters;// Setup a DepthBufferdrawBuffer = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, SurfaceFormat.Color,DepthFormat.Depth24Stencil8, pp.MultiSampleCount, RenderTargetUsage.DiscardContents);//NOTE: DepthStencilBuffer class no longer exists |
1 2 | // XNA 3.1spriteBatch.Draw(myRenderTarget.GetTexture(), Vector2.Zero, Color.White); |
1 2 | // XNA 4.0spriteBatch.Draw(myRenderTarget, Vector2.Zero, Color.White); // NOTE: ".GetTexure()" No longer needed |
1 2 | // XNA 3.1Texture2D myTexture = myRenderTarget.GetTexture(); |
1 2 | // XNA 4.0Texture2D myTexture = myRenderTarget; // NOTE: ".GetTexure()" No longer needed |
1 2 | // XNA 3.1GraphicsDevice.SetRenderTarget(0, myRenderTarget); |
1 2 | // XNA 4.0GraphicsDevice.SetRenderTarget(myRenderTarget); |
1 2 3 4 | // XNA 3.1// Set the two render targetsGraphicsDevice.SetRenderTarget(0, colorRT);GraphicsDevice.SetRenderTarget(1, depthRT); |
1 2 3 | // XNA 4.0// Set the two render targetsGraphicsDevice.SetRenderTargets(colorRT, depthRT); |
1 2 | // XNA 3.1GraphicsDevice.SetRenderTarget(0, null); |
1 2 | // XNA 4.0GraphicsDevice.SetRenderTarget(null); |
1 2 3 4 5 6 7 8 9 | // XNA 3.1// resolve the backbuffer as the depth mapGraphicsDevice.ResolveBackBuffer(depthMap);// draw the scene image again, blur it with the depth mapGraphicsDevice.Textures[1] = depthMap;Viewport viewport = GraphicsDevice.Viewport;dofEffect.CurrentTechnique = depthBlurTechnique;DrawFullscreenQuad(sceneMap, viewport.Width, viewport.Height, dofEffect); |
1 2 3 4 5 6 7 8 9 10 | // XNA 4.0// resolve the backbuffer as the depth mapGraphicsDevice.SetRenderTarget(null);// draw the scene image again, blur it with the depth mapGraphicsDevice.Textures[1] = depthMap;GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp;Viewport viewport = GraphicsDevice.Viewport;dofEffect.CurrentTechnique = depthBlurTechnique;DrawFullscreenQuad(sceneMap, viewport.Width, viewport.Height, dofEffect); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // XNA 3.1ResolveTexture2D resolveTarget;RenderTarget2D renderTarget1;RenderTarget2D renderTarget2;// Look up the resolution and format of our main backbuffer.PresentationParameters pp = GraphicsDevice.PresentationParameters;int width = pp.BackBufferWidth;int height = pp.BackBufferHeight;SurfaceFormat format = pp.BackBufferFormat;// Create a texture for reading back the backbuffer contents.resolveTarget = new ResolveTexture2D(GraphicsDevice, width, height, 1, format);// Create two rendertargets half size for the bloom processing.width /= 2;height /= 2;renderTarget1 = new RenderTarget2D(GraphicsDevice, width, height, 1,format);renderTarget2 = new RenderTarget2D(GraphicsDevice, width, height, 1,format);// ... In the Draw Method... GraphicsDevice.ResolveBackBuffer(resolveTarget); // ...apply effect and draw pass 1... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | // XNA 4.0RenderTarget2D sceneRenderTarget;RenderTarget2D renderTarget1;RenderTarget2D renderTarget2;// Look up the resolution and format of our main backbuffer.PresentationParameters pp = GraphicsDevice.PresentationParameters;int width = pp.BackBufferWidth;int height = pp.BackBufferHeight;SurfaceFormat format = pp.BackBufferFormat;// Create a texture for rendering the main scene, prior to applying bloom.sceneRenderTarget = new RenderTarget2D(GraphicsDevice, width, height, false, format, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents);// Create two rendertargets half size for the bloom processing.width /= 2;height /= 2;renderTarget1 = new RenderTarget2D(GraphicsDevice, width, height, false, format, DepthFormat.None);renderTarget2 = new RenderTarget2D(GraphicsDevice, width, height, false, format, DepthFormat.None);// ...In the Draw Method...GraphicsDevice.SetRenderTarget(sceneRenderTarget);GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;// ...apply effect and draw pass 1.... |
VertexDeclaration, Vertices, VertexElements, SizeInBytes
1 2 3 | // XNA 3.1// Vertex declaration for rendering our 3D model. GraphicsDevice.VertexDeclaration = new VertexDeclaration(VertexPositionTexture.VertexElements); |
1 2 | // XNA 4.0// Delete it. No longer needed. |
1 2 3 4 | // XNA 3.1// set vertex buffer and declarationGraphicsDevice.VertexDeclaration = vertexDeclaration;GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionTexture.SizeInBytes); |
1 2 3 | // XNA 4.0// set vertex buffer and declarationGraphicsDevice.SetVertexBuffer(vertexBuffer); |
1 2 3 | // XNA 3.1// create vertex declarationvertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionTexture.VertexElements); |
1 2 3 | // XNA 4.0// create vertex declarationvertexDeclaration = new VertexDeclaration(VertexPositionTexture.VertexDeclaration.GetVertexElements()); |
1 2 3 4 | // XNA 3.1// reset vertex buffer declarationGraphicsDevice.VertexDeclaration = null;GraphicsDevice.Vertices[0].SetSource(null, 0, 0); |
1 2 3 | // XNA 4.0// reset vertex buffer declarationGraphicsDevice.SetVertexBuffer(null); |
1 2 3 4 5 6 7 | // XNA 3.1// the vertices arrayVertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[100]; // set new particles to vertex buffervertexBuffer.SetData<VertexPositionNormalTexture>(VertexPositionNormalTexture.SizeInBytes * vertexCount, vertices,vertexCount,count,VertexPositionNormalTexture.SizeInBytes); |
1 2 3 4 5 6 | // XNA 4.0// the vertices arrayVertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[100];// set new particles to vertex buffervertexBuffer.SetData<VertexPositionNormalTexture>(vertices); |
VertexBuffer, StreamOffset, VertexStride, IndexBuffer, BaseVertex
1 2 3 4 5 6 7 8 9 10 11 12 | // XNA 3.1// for each mesh partforeach (ModelMeshPart meshPart in mesh.MeshParts){ // if primitives to render if (meshPart.PrimitiveCount > 0) { // setup vertices and indices GraphicsDevice.VertexDeclaration = meshPart.VertexDeclaration; GraphicsDevice.Vertices[0].SetSource(mesh.VertexBuffer, meshPart.StreamOffset, meshPart.VertexStride); GraphicsDevice.Indices = mesh.IndexBuffer; ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 | // XNA 4.0GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; // may be needed in some cases...// for each mesh partforeach (ModelMeshPart meshPart in mesh.MeshParts){ // if primitives to render if (meshPart.PrimitiveCount > 0) { // setup vertices and indices GraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer); GraphicsDevice.Indices = meshPart.IndexBuffer; ... |
1 2 3 4 5 | // XNA 3.1// draw primitivesGraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, meshPart.BaseVertex, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount); |
1 2 3 4 | // XNA 4.0// draw primitivesGraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount); |
Points, PointSpriteEnable, PointSizeMax, PointList
1 2 3 4 | // XNA 3.1 // create the vertex buffervertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionNormalTexture), 250, BufferUsage.WriteOnly | BufferUsage.Points); |
1 2 3 4 | // XNA 4.0// create the vertex buffervertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionNormalTexture), 250, BufferUsage.WriteOnly | BufferUsage.None); |
1 2 3 4 | // XNA 3.1// enable point sprite 3.1GraphicsDevice.RenderState.PointSpriteEnable = true;GraphicsDevice.RenderState.PointSizeMax = 128; |
1 2 | // XNA 4.0// Delete it. No longer available. |
1 2 3 | // XNA 3.1// draw the point spritesGraphicsDevice.DrawPrimitives(PrimitiveType.PointList, vertexPosition, numberVertices); |
1 2 3 | // XNA 4.0// draw the point spritesGraphicsDevice.DrawPrimitives(PrimitiveType.LineList, vertexPosition, numberVertices); |
OpenContainer, BeginShowStorageDeviceSelector, EndShowStorageDeviceSelector, Path, TitleLocation, FileStream
1 2 3 | // XNA 3.1// open the containerStorageContainer storageContainer = storageDevice.OpenContainer("YourGameName"); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // XNA 4.0//To make life easier simply create a method to replace the storageDevice.OpenContainer... /// <summary>/// Synchronously opens storage container/// </summary>private static StorageContainer OpenContainer(StorageDevice storageDevice, string saveGameName){ IAsyncResult result = storageDevice.BeginOpenContainer(saveGameName, null, null); // Wait for the WaitHandle to become signaled. result.AsyncWaitHandle.WaitOne(); StorageContainer container = storageDevice.EndOpenContainer(result); // Close the wait handle. result.AsyncWaitHandle.Close(); return container;}// open the containerStorageContainer storageContainer = OpenContainer(storageDevice, "YourGameName"); |
1 2 3 | // XNA 3.1// retrieve the storage deviceGuide.BeginShowStorageDeviceSelector(GetStorageDeviceResult, retrievalDelegate); |
1 2 3 4 5 6 | // XNA 4.0// retrieve the storage deviceif (!Guide.IsVisible){ StorageDevice.BeginShowSelector(GetStorageDeviceResult, retrievalDelegate);} |
1 2 3 | // XNA 3.1 // retrieve and store the storage device storageDevice = Guide.EndShowStorageDeviceSelector(result); |
1 2 3 | // XNA 4.0// retrieve and store the storage device storageDevice = StorageDevice.EndShowSelector(result); |
1 2 3 | // XNA 3.1// get the level setup files string[] filenames = Directory.GetFiles(storageContainer.Path, "LevelSetup*.xml"); |
1 2 3 | // XNA 4.0// get the level setup filesstring[] filenames = storageContainer.GetFileNames("LevelSetup*.xml""); |
1 2 3 4 5 6 | // XNA 3.1// save game level datausing (FileStream stream = new FileStream(Path.Combine(storageContainer.Path, levelFilename), FileMode.Create)){ new XmlSerializer(typeof(SaveGameLevel)).Serialize(stream, levelData);} |
1 2 3 4 5 6 | // XNA 4.0// save game level datausing (Stream stream = storageContainer.OpenFile(levelFilename, FileMode.Create)){ new XmlSerializer(typeof(SaveGameLevel)).Serialize(stream, levelData);} |
1 2 3 4 5 6 7 8 9 | // XNA 3.1// Delete the saved game level data.using (StorageContainer storageContainer = storageDevice.OpenContainer("saveGameName")){ File.Delete(Path.Combine(storageContainer.Path, saveGameLevel.FileName)); File.Delete(Path.Combine(storageContainer.Path, "SaveGameLevel" + Path.GetFileNameWithoutExtension(saveGameLevel.FileName).Substring(8) +".xml"));} |
1 2 3 4 5 6 7 8 9 | // XNA 4.0// Delete the saved game level data. NOTE: using OpenContainer method created in previous exampleusing (StorageContainer storageContainer = OpenContainer(storageDevice, "saveGameName")){ storageContainer.DeleteFile(saveGameLevel.FileName); storageContainer.DeleteFile("SaveGameLevel" + Path.GetFileNameWithoutExtension(saveGameLevel.FileName).Substring(8) + ".xml");} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | // XNA 3.1//Load the Next Level...// Find the path of the next level.string levelPath;// Loop here so we can try again when we can't find a level.while (true){ // Try to find the next level. They are sequentially numbered txt files. levelPath = String.Format("Levels/{0}.txt", ++levelIndex); levelPath = Path.Combine(StorageContainer.TitleLocation, "Content/" + levelPath); if (File.Exists(levelPath)) break; // If there isn't even a level 0, something has gone wrong. if (levelIndex == 0) throw new Exception("No levels found."); // Whenever we can't find a level, start over again at 0. levelIndex = -1;}// Unloads the content for the current level before loading the next one.if (level != null) level.Dispose();// Load the level.level = new Level(Services, levelPath); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // XNA 4.0// Load the Next Level...// move to the next levellevelIndex = (levelIndex + 1) % numberOfLevels;// Unloads the content for the current level before loading the next one.if (level != null) level.Dispose();// Load the level.string levelPath = string.Format("Content/Levels/{0}.txt", levelIndex);using (Stream fileStream = TitleContainer.OpenStream(levelPath)) level = new Level(Services, fileStream, levelIndex); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | // XNA 3.1//Save the current state of the session, with the given storage device. // check the parameterif ((storageDevice == null) || !storageDevice.IsConnected){ return;}// open the containerusing (StorageContainer storageContainer = storageDevice.OpenContainer(Session.SaveGameContainerName)){ string filename; string descriptionFilename; // get the filenames if (overwriteDescription == null) { int saveGameIndex = 0; string testFilename; do { saveGameIndex++; testFilename = Path.Combine(storageContainer.Path, "SaveGame" + saveGameIndex.ToString() + ".xml"); } while (File.Exists(testFilename)); filename = testFilename; descriptionFilename = "SaveGameDescription" + saveGameIndex.ToString() + ".xml"; } else { filename = Path.Combine(storageContainer.Path, overwriteDescription.FileName); descriptionFilename = "SaveGameDescription" + Path.GetFileNameWithoutExtension(overwriteDescription.FileName).Substring(8) + ".xml"; } using (FileStream stream = new FileStream(filename, FileMode.Create)) { using (XmlWriter xmlWriter = XmlWriter.Create(stream)) { //create and write xml data... } } // create the save game description SaveGameDescription description = new SaveGameDescription(); description.FileName = Path.GetFileName(filename); description.ChapterName = IsQuestLineComplete ? "Quest Line Complete" : Quest.Name; description.Description = DateTime.Now.ToString(); using (FileStream stream = new FileStream(Path.Combine(storageContainer.Path, descriptionFilename), FileMode.Create)) { new XmlSerializer(typeof(SaveGameDescription)).Serialize(stream, description); }} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | // XNA 4.0//Save the current state of the session, with the given storage device. // check the parameterif ((storageDevice == null) || !storageDevice.IsConnected){ return;}// open the container Note: using OpenContainer method from previous examplesusing (StorageContainer storageContainer = OpenContainer(storageDevice, Session.SaveGameContainerName)){ string filename; string descriptionFilename; // get the filenames if (overwriteDescription == null) { int saveGameIndex = 0; string testFilename; do { saveGameIndex++; testFilename = "SaveGame" + saveGameIndex.ToString() + ".xml"; } while (storageContainer.FileExists(testFilename)); filename = testFilename; descriptionFilename = "SaveGameDescription" + saveGameIndex.ToString() + ".xml"; } else { filename = overwriteDescription.FileName; descriptionFilename = "SaveGameDescription" + Path.GetFileNameWithoutExtension(overwriteDescription.FileName).Substring(8) + ".xml"; } // Note: using Stream instead of FileStream... using (Stream stream = storageContainer.OpenFile(filename, FileMode.Create)) { using (XmlWriter xmlWriter = XmlWriter.Create(stream)) { //create and write xml data... } } // create the save game description SaveGameDescription description = new SaveGameDescription(); description.FileName = Path.GetFileName(filename); description.ChapterName = IsQuestLineComplete ? "Quest Line Complete" : Quest.Name; description.Description = DateTime.Now.ToString(); // Note: using Stream instead of FileStream... using (Stream stream = storageContainer.OpenFile(descriptionFilename, FileMode.Create)) { new XmlSerializer(typeof(SaveGameDescription)).Serialize(stream, description); }} |
VertexShader, PixelShader, ps_1_x
Inside your shader (*.fx) files…
Inside your shader (*.fx) files…
1 2 3 4 5 6 7 8 9 | // XNA 3.1VertexShaderOutput VertexShader(...){ //some code}float4 PixelShader(...){ // some code} |
1 2 3 4 5 6 7 8 9 10 11 | // XNA 4.0// VertexShader can not be usedVertexShaderOutput VertexShaderFunction(...){ // some code}// PixelShader can not be usedfloat4 PixelShaderFunction(...){ // some code} |
1 2 3 4 5 6 7 8 9 | // XNA 3.1technique{ pass { VertexShader = compile vs_1_1 VertexShader(); PixelShader = compile ps_1_1 PixelShader(); }} |
1 2 3 4 5 6 7 8 9 | // XNA 4.0technique{ pass { VertexShader = compile vs_2_0 VertexShaderFunction(); //VertexShader can not be used & set vs higher than 1_1 PixelShader = compile ps_2_0 PixelShaderFunction(); //PixelShader can not be used & set ps higher than 1_1 }} |
XNA Model drawn inside out, slightly transparent, missing parts or just looks wrong
Add the following code before the XNA Model Draw code
1 2 3 4 5 | // Set suitable renderstates for drawing a 3D modelGraphicsDevice.BlendState = BlendState.Opaque;GraphicsDevice.DepthStencilState = DepthStencilState.Default;// your model draw code starts here... |
浙公网安备 33010602011771号