# Run XNA game without graphics

Wondering if there is anyway to run an XNA game with out displaying anything.

I have a working game that runs in a client server setup where one player is the host and other people can connect to his game.

I now want to be able to run the game as a host on a decicated server with no graphics card, basically I dont want to run any Draw() logic at all.

Do i really need to go through the entire game and remove all references to XNA?

How have people done this?

EDIT: The reason I want to do this is because I have a working client server setup in the game and I dont want to make a separate "headless" server program.

• Why can't you just write code in Draw like if (headless) { return; }? – ashes999 Feb 4 '13 at 2:41
• @asher999 Not sure if that will completely remove all draw and graphics logic from the game. A virtual server may not have any real graphics adapter at all. – JensB Feb 4 '13 at 11:44
• Changing the output type or skipping drawing will not magically remove XNA's dependency on a graphics device. If you are loading any content that requires a graphics device (especially textures) there is a very good chance those will fail to load using either of the proposed solutions. – dadoo Games Feb 11 '13 at 14:14

Just make a normal C# project and include the XNA binaries. This will gain you access to the XNA data types and framework methods. My game does this and it works flawlessly.

• I'm guessing you wrote a wrapper that acts like XNA calling the needed methods such as Update for you? I'll give this a go, thanks. – JensB Feb 4 '13 at 11:46

The answer is: don't do this. If you don't need to make a game - i.e; you're not looking to take advantage of the things XNA offers, why do it? You really should be looking into developing a custom piece of software that can successfully simulate the game you wish to play - typically a console system of some sort. If you give more details, I will update my answer with a less generic response.

• I can give you one reason: unit testing. Often you want to test a piece or section of code without having to load or draw and graphics. – Stephen Tierney Feb 4 '13 at 1:10
• @StephenTierney I can give you one other reason: he's not trying to, he's trying to run a game server (on a dedicated machine). Please re-read the question and consider taking back your downvote. – Vaughan Hilts Feb 4 '13 at 1:11

Well if you simply wish to eliminate the draw calls have you tried using this : Suppress Draw

To build on untitled's suggestion, you can just include references to the DLLs and use them without using any of the default game loops. For examples of this you can look at the winforms tutorial series on the creators club: http://xbox.create.msdn.com/en-us/education/catalog/sample/winforms_series_2

Also if you want to get even more fancy you can replace the entire XNA game loop with your own custom one, and control the entire process. For more information on this look at https://stackoverflow.com/questions/6361691/custom-xna-game-loop-in-windows

If you change the Output Type of a XNA Project to "Console Application", the application will simply open an empty Console at start-up, without ever opening the actual game's window. This might be useful for what you are trying to accomplish, since you want to do tests, and you can very easily use the Console as a debug window.

You can also consider overriding the update and draw calls, and simply return.

Also, dont call the graphicsdevice in your main game classes, which should stop the xna window from being instanced on the game acting as your server.