Пост N: 211
Зарегистрирован: 23.03.07
Откуда: Санкт Петербург
Рейтинг:
0
Отправлено: 25.04.09 14:12. Заголовок: проблемма с GraphicsDevice в XNA
Всем добрый день. Помогите мне пожалуйста, при инициализации девайса у меня происходит ошибка:An unexpected error has occurred. Так как я чайник не могу понять в чем причина. И надеюсь на помощь более квалифицированных программистов. Вот исходный код(строка в которой происходит ошибка выделена красным):
цитата:
using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage;
namespace DogmaTank { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDevice device = null; PresentationParameters presentationParameters;
public Game1() { Content.RootDirectory = "Content"; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here presentationParameters = new PresentationParameters(); presentationParameters.BackBufferWidth = 1024; presentationParameters.BackBufferHeight = 768; presentationParameters.BackBufferFormat = SurfaceFormat.Rgba32; presentationParameters.BackBufferCount = 1; presentationParameters.MultiSampleType = MultiSampleType.None; presentationParameters.MultiSampleQuality = 0; presentationParameters.SwapEffect = SwapEffect.Discard; presentationParameters.DeviceWindowHandle = this.Window.Handle; presentationParameters.IsFullScreen = true; presentationParameters.EnableAutoDepthStencil = true; presentationParameters.AutoDepthStencilFormat = DepthFormat.Depth24; presentationParameters.FullScreenRefreshRateInHz = 0; presentationParameters.PresentationInterval = PresentInterval.Immediate;
device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Reference, this.Window.Handle, presentationParameters);
base.Initialize(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() {
// TODO: use this.Content to load your game content here }
/// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) {
// TODO: Add your update logic here
base.Update(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { device.Clear(Color.Gold);
// TODO: Add your drawing code here
device.Present(); base.Draw(gameTime);
} } }
Вроде все написал правильно, но все равно не работает. Помогите кто может.
В методе graphics_PreparingDeviceSettings получаешь информацию о девайсе и устанавливаешь нужные настройки. Вот так можно установить тип девайса, а так же изменить presentation параметры: void graphics_PreparingDeviceSettings( object sender, PreparingDeviceSettingsEventArgs e) { if (e.GraphicsDeviceInformation.Adapter.IsDeviceTypeAvailable( DeviceType.Hardware) == false) { GraphicsDeviceInformation gi = e.GraphicsDeviceInformation; gi.DeviceType = DeviceType.Reference; gi.PresentationParameters.MultiSampleType = MultiSampleType.None; } }
Пост N: 215
Зарегистрирован: 23.03.07
Откуда: Санкт Петербург
Рейтинг:
0
Отправлено: 27.05.09 19:08. Заголовок: Так а зачем тебе ref..
цитата:
Так а зачем тебе reference девайс?
Решил по старинке инициализировать DirectX. Как в старые добрые времена, когда нужно было создать девайс, заполнить структуру PresentationParameters от руки. А не то, что счас, на всем готовеньком.
Пост N: 216
Зарегистрирован: 23.03.07
Откуда: Санкт Петербург
Рейтинг:
0
Отправлено: 27.05.09 19:11. Заголовок: Решается это с помощ..
цитата:
Решается это с помощью использования эвента:
Я на шел более оригинальный способ: Forms1.cs:
цитата:
using System; using System.Windows.Forms; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage;
namespace Test { public partial class Form1 : Form { GraphicsDevice device = null;
public Form1() { this.ClientSize = new System.Drawing.Size(800, 600); InitializeComponent(); }
public void Init_Video() { PresentationParameters present = new PresentationParameters(); present.IsFullScreen = false; present.SwapEffect = SwapEffect.Discard; device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, this.Handle, present); }
using System; using System.Collections.Generic; using System.Windows.Forms;
namespace Test { static class Program { /// <summary> /// The main entry point for the application. /// </summary> static void Main() { using (Form1 frm = new Form1()) { frm.Init_Video(); frm.Show();
while (frm.Created) { frm.Render(); Application.DoEvents(); } } } } }
Все даты в формате GMT
3 час. Хитов сегодня: 12
Права: смайлы да, картинки да, шрифты да, голосования нет
аватары да, автозамена ссылок вкл, премодерация откл, правка нет