Problem with XNA.

Started by
9 comments, last by coding penguin 16 years, 11 months ago
So, I created a new Windows Game project. I added a few lines of code to the standard stuff so that I could run it on my computer because my graphics card doesn't support shader models 1 and 2. It builds successfully, but a window doesn't open, and I get a message saying that WindowsGame1 has to close. Can anyone give a guess to the problem? here's the code:

#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace WindowsGame1
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;


        public Game1()
        {
            // Checks if graphics card supports Pixel Shader 2. If not, creates Refrence device.
            if (GraphicsAdapter.DefaultAdapter.GetCapabilities(DeviceType.Hardware).MaxPixelShaderProfile < ShaderProfile.PS_2_0)
            
                graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(SetToReference);
            
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
        }

        //Creates device that uses CPU instead of graphics card.
        void SetToReference(object sender, PreparingDeviceSettingsEventArgs eventargs)
        {
            eventargs.GraphicsDeviceInformation.CreationOptions = CreateOptions.SoftwareVertexProcessing;
            eventargs.GraphicsDeviceInformation.DeviceType = DeviceType.Reference;
            eventargs.GraphicsDeviceInformation.PresentationParameters.MultiSampleType = MultiSampleType.None;
        }



        /// <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

            base.Initialize();
        }


        /// <summary>
        /// Load your graphics content.  If loadAllContent is true, you should
        /// load content from both ResourceManagementMode pools.  Otherwise, just
        /// load ResourceManagementMode.Manual content.
        /// </summary>
        /// <param name="loadAllContent">Which type of content to load.</param>
        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                // TODO: Load any ResourceManagementMode.Automatic content
            }

            // TODO: Load any ResourceManagementMode.Manual content
        }


        /// <summary>
        /// Unload your graphics content.  If unloadAllContent is true, you should
        /// unload content from both ResourceManagementMode pools.  Otherwise, just
        /// unload ResourceManagementMode.Manual content.  Manual content will get
        /// Disposed by the GraphicsDevice during a Reset.
        /// </summary>
        /// <param name="unloadAllContent">Which type of content to unload.</param>
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent == true)
            {
                content.Unload();
            }
        }


        /// <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)
        {
            // Allows the default game to exit on Xbox 360 and Windows
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // 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)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}

----------------------------My site: www.sudoexec.net
Advertisement
Have you got the box in the DirectX Control Panel for "Enumerate Reference Rasterizer" checked?

Regards,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
Sorry, but where could I find this control panel?
----------------------------My site: www.sudoexec.net
For me, it is located at
C:\Program Files\Microsoft DirectX SDK (February 2007)\Utilities\Bin\x86\dxcpl.exe
Your mileage may vary depending on the DX SDK version you have installed etc. [cool]

Regards,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
Ah, that may be the solution. I can't seem to find the DirectX SDK installed. That's wierd, I remember installing it last month.
----------------------------My site: www.sudoexec.net
The fact that your video card doesn't support shader model 1 is probably the problem. Xna requires 1.1, and may be throwing an exception that you're not catching.

Regardless, you won't be able to do any xna development with that video card. Not even 2D sprite stuff: xna still uses shaders under the hood for sprites.
Quote:Original post by gharen2
The fact that your video card doesn't support shader model 1 is probably the problem. Xna requires 1.1, and may be throwing an exception that you're not catching.

Regardless, you won't be able to do any xna development with that video card. Not even 2D sprite stuff: xna still uses shaders under the hood for sprites.


That's why in my code I check whether the graphics card supoorts Shader Model 2.
If it doesn't, it creates a Refrence device, and runs everything on the CPU.
----------------------------My site: www.sudoexec.net
I remember reading about a bug where the exception is thrown even if you asked to start with the reference device. I'm not sure if it's still in the current release, but it's something to investigate anyways.
sorry for posting to this old topic but i find it quite interesting. however i found that this is not enought to make it work for xna 1.0. if it could help to someone, heres the link i found: http://www.nuclex.org/articles/using-the-reference-rasterizer-in-xna
I'm pretty sure you are not supposed to use the reference rasterizer for anything you distribute - I don't think it's installed with the retail DirectX stuff.

http://msdn2.microsoft.com/en-us/library/bb219625.aspx
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.

This topic is closed to new replies.

Advertisement