Sign in to follow this  
BenThereDoneThat

Problem with XNA.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
thanks for reply, but to said it, you cant really produce anything on this ref device :) its really slow. im using it just because i dont have any pixel shaders on my graphics card in notebook and im getting new one in about four months, so i thought it could be a good idea to get started with xna by simple 2d things and then, when i will buy new notebook get into 3d ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this