nick5454

Ok so my question now is.

I first draw the main game screen. it works great.

Then I execute the code below to draw a rectangle on top. But, it never shows up. When I take out the render code it draws fine to the screen. So I think I'm only missing one statement to add the the texture to the main screen.

Can anyone spot the problem ( I'm trying to draw rt to the screen )

Thanks,

Nick

// I draw main screen here

RenderTarget2D rt = new RenderTarget2D(graphics.GraphicsDevice, 200, 200, 1, graphics.GraphicsDevice.DisplayMode.Format);

//object o = graphics.GraphicsDevice.GetRenderTarget(0);

RenderTarget2D backBuffer = (RenderTarget2D)graphics.GraphicsDevice.GetRenderTarget(0);

graphics.GraphicsDevice.SetRenderTarget(0, rt);

graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

// draw

ScannerForegroundBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Texture, SaveStateMode.SaveState);

ScannerForegroundBatch.Draw(SpriteTextureBlank, new Rectangle(player.X * (rt.Width / map.Width), player.Y * (rt.Height / map.Height), 6, 8), Color.White);

ScannerForegroundBatch.End();

//// reset the render target

graphics.GraphicsDevice.ResolveRenderTarget(0);

Texture2D renderedTexture = rt.GetTexture();

graphics.GraphicsDevice.SetRenderTarget(0, null);

base.Draw(gameTime);

rt.Dispose();



Re: XNA Framework My second render isnt showing

Jim Perry

Why are you going through such a convoluted process Why not just do:

graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
ScannerForegroundBatch.Begin();
ScannerForegroundBatch.Draw(whatever texture, new Rectangle(), Color.White)
;  //fill in the blanks
ScannerForegroundBatch.End();

Maybe I'm just missing something.






Re: XNA Framework My second render isnt showing

nick5454

Well because I have a maze game. First I draw the main screen and then I want to draw another texture, which will eventually be 50% transparent. ( its like the map for the maze)

The problem is that all of the code works separately. But when I try to a separate texture. I can't draw it on the screen. I don't understand how to draw other texture on the screen.

 

Is it through other sprite batches, or something else





Re: XNA Framework My second render isnt showing

nick5454

Wow thanks for replying.

I looked at your code and realized that since I have the texture created I can create another sprite bacth and then draw it

SpriteBatch sp = new SpriteBatch(graphics.GraphicsDevice);

sp.Begin(SpriteBlendMode.None, SpriteSortMode.Texture, SaveStateMode.SaveState);

sp.Draw(renderedTexture, new Rectangle(20, 20, 200, 200), Color.White);

sp.End();

But, it works now.

Thanks,

Nick