Jump to content
  • Advertisement
Sign in to follow this  
Kitasia

XNA in WPF window

This topic is 4230 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a game in XNA but the problem Is I've made an Application using WPF and MDX. I can't load things to my game because they contain classes from MDX. It's really a pain, so I'm wondering is there any info on running XNA in a WPF window. I'm trying and I'm getting a lot of errors. I was thinking of making my classes independent of the two but seeing as I'm rather attached to many of the the classes (EVEN THOUGH THEY'RE IDENTICAL [Razz]!!) I'm fairly sure I can't, smoothly at least. So, any advice?

Share this post


Link to post
Share on other sites
Advertisement
Ah screw it I guess I'll have to try and make things (sigh) independent. If anyone else is trying the same thing the closest I came was......... Here

Didn't work for some reason kept getting an error when I set the device.

Share this post


Link to post
Share on other sites
Are you running vista or xp? Xna isn't compatible with vista yet, maybe that's the problem.

I'm using Xna inside a winform on window xp, the same way as that sample you posted, and it works great.

Share this post


Link to post
Share on other sites
Then the first thing I'd do is make sure you've converted the initialisation enums from mdx to xna correctly. The backbuffer format and such.

I threw this together based on my code (which is too complex to post here). Runs fine for me:


using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Form form = new Form();
form.ClientSize = new Size(800, 600);
form.Show();

PresentationParameters presentationParameters = new PresentationParameters();
presentationParameters.BackBufferFormat = SurfaceFormat.Bgr32;
presentationParameters.BackBufferHeight = form.ClientSize.Height;
presentationParameters.BackBufferWidth = form.ClientSize.Width;
presentationParameters.SwapEffect = SwapEffect.Discard;
presentationParameters.IsFullScreen = false;
presentationParameters.EnableAutoDepthStencil = true;
presentationParameters.AutoDepthStencilFormat = DepthFormat.Depth24Stencil8;
presentationParameters.PresentOptions = PresentOptions.DiscardDepthStencil;
presentationParameters.PresentationInterval = PresentInterval.Immediate;

GraphicsDevice device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware,
form.Handle, CreateOptions.HardwareVertexProcessing, presentationParameters);

while (form.Created)
{
if (form == Form.ActiveForm)
{
device.Clear(Microsoft.Xna.Framework.Graphics.Color.CornflowerBlue);
device.Present();
}
Application.DoEvents();
}
}
}
}


Share this post


Link to post
Share on other sites
Hey it works now! Thanks a load! It seems things didn't work when I use SurfaceFormat Rgb32. I'll look into that weird little error.

You're a life saver [wink]!

[Update] More think I'd like to note that I looked at the XNA migration guide it's stupid to have it used backwards like that. I'm speaking without knowing the exact reason why but as far as I can know it's stupid : )!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!