Reputation: 2282
I use XNA in Windows Forms.
According to Microsoft tutorial, the control that uses XNA should have something like this in OnPaint()
:
GraphicsDevice.Present(srcRectangle, null, this.Handle);
But I wanted to draw additional things with Windows Forms Graphics object. I can do it just fine placing drawing code after GraphicsDevice.Present()
, but I get horrible flickering. That's why I thought of setting double buffering this way:
protected override CreateParams CreateParams
{
get
{
var cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
But unfortunately it will draw only thing drawn with Graphics object (or the internal controls). That's why I would like to render my XNA scene to Graphics object. Is there any way for that?
I have tried:
Present()
and then showing it with Graphics object.Image.FromStream(Stream)
where stream came from RenderTarget.SaveAsPng()
.Every idea failed. Is there anything else?
Upvotes: 0
Views: 733
Reputation: 2282
Actually, Rendering to Texture is OK. Just rembember to call:
GraphicsDevice.SetRenderTarget(null);
Before you access data from it
Upvotes: 0