Tutorials

XNA 3D Engine - Introduction (Part 1)

Nivå : 100
This is the first part in a series of many, in which we'll explain how to make a 3D engine in XNA from the ground up.

 

We expect the reader to have some knowledge in C# and linear algebra.

 

Here’s what you need to be able to create games built in XNA:

 

  • Any copy of Visual Studio 2005 or Visual C# 2005 Express

     

  • Microsoft XNA Game Studio 2.0

     

  • Graphics card that supports DirectX 9.0c and Shader Model 1.1 (some ”starter kits” need Shader Model 2.0)
Let's start by opening Visual Studio 2005 and create a new project.

 

Go to “Visual C#” and “XNA Game Studio 2.0”, then select ”Windows Game (2.0)” and call the project ”XNA3DEngine”. Click “Ok”.

 

The first thing we’d like to do is to rename our “Game1” class to “XNA3DEngine”. You can do that from the solution explorer by right clicking on the file, and then choose “Rename”.

 

Next, delete the SpriteBatch field and the instantiation in “LoadContent()”.

 

This is code that is generated for us but we don’t need it now.

 

You can now test build your application by hitting F5.

 

You’ll se a nice cornflower blue screen, isn’t that nice!

 

clip_image002

 

The code that does this is in a method in our game class called Draw(GameTime gameTime).

 

The draw method is where all the graphics operations are taking place, and later we’ll create DrawableGameComponents that has the exactly same method.

 

Exit by hitting Alt+F4 and you’ll bounce back to the code.

 

We can see in solution explorer that a Content folder has been made for us.

 

Let’s put our content there

 

 

 

 

 

Follow the link at the bottom of this tutorial to download the content

Unzip it to whatever folder you like, then right click on “Content”, choose “Add” and “Existing Item”. Choose the files you downloaded and then hit the arrow button next to the “Add” button. Then click “Add As Link”.

 

clip_image004

 

Right click on the CastleSiege.x file and verify that Build action is set to compile:

 

clip_image006

 

Now that we have added our content we need to display it.

 

XNA does this amazingly easy as you are about to see.

 

Right click on the project in the solution explorer and click “Add”->”New Item…”

 

clip_image008

 

Choose the GameComponent template, and call it “Scene.cs”. Click OK.

 

This just creates a normal game component without our Draw method.

Lets change the class definition with this:

 

public class Scene : DrawableGameComponent

 

Click “Class Diagram” in the Solution explorer. Right click our “Scene” class there, choose Intellisense->Override members.

 

Expand the GameComponent class in the listbox, and choose to override the Draw and LoadContent methods and hit “OK”.

 

Go back to your scene class and you’ll see that the methods you selected to be overridden are implemented.

 

OK, this is just meant as a teaser for what’s to come here on www.gamecamp.no

 

In the next part of this tutorial, we’ll look at how easy XNA can display our scene component.

 

 

Here's the graphics:

 

 

Here’s the code so far:

 

 

See you next time, take care!

 

Comments

No Comments