Jump to content

  • Log In with Google      Sign In   
  • Create Account


XNA in WPF window


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 TheAnti   Members   -  Reputation: 252

Like
0Likes
Like

Posted 21 March 2007 - 10:11 AM

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?

Sponsor:

#2 TheAnti   Members   -  Reputation: 252

Like
0Likes
Like

Posted 21 March 2007 - 04:14 PM

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.

#3 gharen2   Members   -  Reputation: 520

Like
0Likes
Like

Posted 21 March 2007 - 04:39 PM

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.

#4 TheAnti   Members   -  Reputation: 252

Like
0Likes
Like

Posted 21 March 2007 - 04:50 PM

Nope running XP and doesn't work. The demo doesn't even work. Odd.

#5 gharen2   Members   -  Reputation: 520

Like
0Likes
Like

Posted 21 March 2007 - 05:12 PM

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();
}
}
}
}




#6 TheAnti   Members   -  Reputation: 252

Like
0Likes
Like

Posted 21 March 2007 - 05:39 PM

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 : )!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS