2010-11-09 66 views
0

我有以下聲明: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,ResolveTexture2DResolveBackBuffer方法已被刪除。我將如何重新編碼以便在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(); 

回答

3

啊啊啊,在這裏你去: 移動GraphicsDevice.SetRenderTarget()的GraphicsDevice.Clear()調用之前

+0

完美!剛剛解決了一個透明度問題,但很好:D – 2010-11-09 16:31:51

6

ResolveTexture2D從XNA 4.0去除explained here

基本上你應該使用渲染目標。過程的要點如下:

創建要使用的渲染目標。

RenderTarget2D renderTarget = new RenderTarget2D(graphicsDevice, width, height); 

然後將其設置到設備:

graphicsDevice.SetRenderTarget(renderTarget); 

然後渲染場景。

然後取消設置渲染目標:

graphicsDevice.SetRenderTarget(null); 

最後,你可以使用一個RenderTarget2D作爲一個Texture2D,像這樣:

spriteBatch.Draw(renderTarget, new Rectangle(0, 0, 800, 600), Color.Cyan); 

您也可以找到這個overview of RenderTarget changes in XNA 4.0值得一讀。

+0

感謝您幫助。 – 2010-11-09 16:31:06