我有以下聲明:ResolveTexture2D - 在XNA的噩夢4
ResolveTexture2D rightTex;
我用它在Draw
方法,像這樣:
GraphicsDevice.ResolveBackBuffer(rightTex);
現在,我再畫出來使用SpriteBatch
:
spriteBatch.Draw(rightTex, new Rectangle(0, 0, 800, 600), Color.Cyan);
這在XNA 3.1中的工作很棒。但是,現在我轉換爲XNA 4,ResolveTexture2D
和ResolveBackBuffer
方法已被刪除。我將如何重新編碼以便在XNA 4.0中工作?
編輯
所以,這裏是一些代碼,也許幫助。在這裏,我初始化RenderTargets:
PresentationParameters pp = GraphicsDevice.PresentationParameters;
leftTex = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, pp.BackBufferFormat, pp.DepthStencilFormat);
rightTex = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, pp.BackBufferFormat, pp.DepthStencilFormat);
然後,在我Draw
方法,我做的:
GraphicsDevice.Clear(Color.Gray);
rightCam.render(model, Matrix.CreateScale(0.1f), modelAbsTrans);
GraphicsDevice.SetRenderTarget(rightTex);
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.Gray);
leftCam.render(model, Matrix.CreateScale(0.1f), modelAbsTrans);
GraphicsDevice.SetRenderTarget(leftTex);
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.Black);
//start the SpriteBatch with Additive Blend Mode
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
spriteBatch.Draw(rightTex, new Rectangle(0, 0, 800, 600), Color.Cyan);
spriteBatch.Draw(leftTex, new Rectangle(0, 0, 800, 600), Color.Red);
spriteBatch.End();
完美!剛剛解決了一個透明度問題,但很好:D – 2010-11-09 16:31:51