Basic Tutorial 0 (Setting up your application, Windows) - Axiom : A 3D Rendering Engine in C#

Basic Tutorial 0 (Setting up your application, Windows)

From Axiom

Jump to: navigation, search

Show code samples in
For setting up an application on Linux, see From SVN to RenderWindow

This tutorial will explain how you get a new own project working as soon as possible

Contents

Tutorial Conventions

This tutorial uses certain terms and placeholders to mean certain things which may change from one machine to another.

  • {$ProjectOutput} is a placeholder for where Visual Studio places the outputs of the compile. This folder is usually in your project folder under bin\Debug or bin\Release. For Visual Studio C# Express, the folder used is determined by how you compile, Compile + Debug ( F5 ) uses bin\Debug, and Compile and Run ( Ctrl-F5 ) uses bin\Release. If you are using any of the Visual Studio 2010 editions ( Standard, Professinal, or Ultimate ) then the folder used is determine by your configuration, which by default is bin\Debug for a Debug build or bin\Release for a Release build.

Prerequisites

Download and install either XNA Game Studio 3.1 or SlimDX
If you're going to be compiling from source, it's recommended to install both.
Note: if downloading SlimDX, be sure to download the Developer SDK

Get Axiom

Downloading the Binaries

  • Go to Axiom's Codeplex page
  • Click on the Download button on the right hand side of the screen.
  • Save the zip file somewhere on your harddrive.
  • Whilst you're waiting for the download to complete, create a folder called Axiom on your C:// drive. (Or another place of your choosing)
  • After the download completes, you'll need to unblock the zip file by Right-Clicking the Zip file and chossing Properties.
    • On the General Tab there's a button label 'Unblock' click it to unblock the zip file.
  • Now, extract the contents into the folder you created in the above step.

Obtaining source from SVN

If you want to be able to make changes to the Engine itself, you'll need to edit the source code. Note that part of the license requires that any changes that you make to improve the engine must be shared with the community. This does not mean that you need to share your the source code of your game (although that would be really nice), it simply means if you alter Axiom itself, your version of Axiom must be given back to the community. This enables us all to have a consistently better Rendering Engine.

Obtaining The Source

Compiling the Source

Now that TortoiseSVN has completed checking out Axiom, it's time to build it.

  • Browse to C:\Axiom\Projects and double-click either Axiom.2008, or Axiom.2010 depending on your version of Visual Studio.

You'll notice other solutions such as Axiom.Xbox and Axiom.Droid are present, but this is a tutorial for Windows, so they will not be mentioned further.

  • Now that the solution has been opened, right-click the solution in the Solution Explorer and select Build Solution

If you're lucky, it will compile without a hitch and you can move on to Creating your first Project.
However, if you're like me, you received errors. Just about all the errors deal with missing dependencies. In the error list window, in the far-right column it lists the Project that the error originated from. In the solution explorer find that project, and expand the References folder. If one of the files listed has a yellow checkmark next to it, it is missing that assembly. All of my errors were from missing the SlimDX assembly. To solve that, delete the missing assembly and right-click on the References folder. Select the browse tab and browse to "C:\Program Files (x86)\SlimDX SDK (June 2010)\Bin\net20\x86" assuming that you installed SlimDX to the default location and downloaded the Developer SDK. In this folder you'll find SlimDX.dll. Double-click it to add to the project. Do this for the remainder of the projects that rely on SlimDX. Right-click the solution and select Build Solution

For a list of Dependencies see Source Dependencies

Creating your First Project

Open Visual Studio and Create a new Console Application

 VERY IMPORTANT: If you are using a 64-bit operating system, you MUST make sure that your project is set to compile for x86. 
 Do this by:
      * right-clicking your project, 
      * Select Properties from the context menu, 
      * select the Build Tab on the left hand side, 
      * in the Platform Target drop-down box select x86.

Note about this: if you downloaded the source, you could compile Axiom as a 64 bit library, however this is hardly worth it as any Axiom application you create will only run on 64 bit systems.

Gathering Dependencies

Alright, now in Windows Explorer, browse to where you created your project, usually: ...Documents\Visual Studio 2008\Projects\YourProjectName

  • Create a folder called 'References' and open it up
  • Open another Window Explorer, browse to either
    • C:\Axiom\lib\.Net 3.5\Release (if you downloaded the binaries)
    • C:\Axiom\Projects\AxiomDemos\Source\Browser\WinForm\bin\YourRenderingSystemOfChoice (if you built from source)
  • Copy all of the .dll's and all of the .xml's and paste them into the other Windows Explorer you have open, which should be in the References folder of your project.
  • Also copy Axiom.Framework from the C:\Axiom\Samples\samples folder to the References folder in your project.
  • Now you'll need to copy the media
    • If you built from source, copy the Media folder and paste it into your projects {$ProjectOutput} folder.
    • If you downloaded the binaries, Browse to C:\Axiom\samples, copy the media folder and paste in into your project's {$ProjectOutput} folder.
  • Now, back in Visual Studio, in the Solution Explorer, right click the References folder of your project, and select Add New Reference from the context menu.
  • Browse to Documents\Visual Studio 2008\Projects\YourProjectName\References and use CTRL+Click to select the following:
    • Axiom
    • Axiom.Framework
    • Axiom.Platforms.Win32
    • Axiom.Plugins.FreeImageCodecs
    • Axiom.Plugins.ParticleFX
    • Axiom.RenderSystems.Xna OR Axiom.RenderSystems.OpenGL.OpenTK OR Axiom.RenderSystems.DirectX9
  • and then click add.

Now you'll need to copy the native dll's to the output directory. From the References folder select the following files, and copy them to your projects {$ProjectOutput} folder usually bin\Debug or bin\Release

freeimage.dll
zlib1.dll

Test Code

If you are using Visual Studio 2010 and .Net 4.0, you'll need to add an App.Config file to your project as there are some assemblies that Axiom depends on that are built for .Net 2.0. Add the following to the <configuration /> element in your App.Config file.

  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>

Alright, almost done. We'll be creating a small scene to see if everything is correctly configured. At the top of Program.cs, add the following using statements:

using Axiom.Core;
using Axiom.Graphics;
using Axiom.Math;
using Axiom.Framework.Configuration;
Imports Axiom.Core
Imports Axiom.Graphics
Imports Axiom.Math
Imports Axiom.Framework.Configuration

In the main function of your program, copy and paste the following code:

IConfigurationManager ConfigurationManager = ConfigurationManagerFactory.CreateDefault();
using ( var root = new Root( "Game1.log" ) )
{
	if ( ConfigurationManager.ShowConfigDialog( root ) )
	{
		RenderWindow window = root.Initialize( true );

		ResourceGroupManager.Instance.AddResourceLocation( "media", "Folder", true );

		SceneManager scene = root.CreateSceneManager( SceneType.Generic );
		Camera camera = scene.CreateCamera( "cam1" );
		Viewport viewport = window.AddViewport( camera );

		TextureManager.Instance.DefaultMipmapCount = 5;
		ResourceGroupManager.Instance.InitializeAllResourceGroups();

		Entity penguin = scene.CreateEntity( "bob", "penguin.mesh" );
		SceneNode penguinNode = scene.RootSceneNode.CreateChildSceneNode();
		penguinNode.AttachObject( penguin );

		camera.Move( new Vector3( 0, 0, 300 ) );
		camera.LookAt( penguin.BoundingBox.Center );
		root.RenderOneFrame();
	}
	Console.Write( "Press [Enter] to exit." );
	Console.ReadLine();
}

Module Module1

    Sub Main()
        Dim ConfigurationManager As IConfigurationManager = ConfigurationManagerFactory.CreateDefault()

        Using varRoot As Root = New Root("Game1.log")
            If ConfigurationManager.ShowConfigDialog(varRoot) Then
                Dim window As RenderWindow = varRoot.Initialize(True)

                ResourceGroupManager.Instance.AddResourceLocation("media", "Folder", True)

                Dim scene As SceneManager = varRoot.CreateSceneManager(SceneType.Generic)
                Dim camera As Camera = scene.CreateCamera("cam1")
                Dim viewport As Viewport = window.AddViewport(camera)

                TextureManager.Instance.DefaultMipmapCount = 5
                ResourceGroupManager.Instance.InitializeAllResourceGroups()

                Dim penguin As Entity = scene.CreateEntity("bob", "penguin.mesh")
                Dim penguinNode As SceneNode = scene.RootSceneNode.CreateChildSceneNode()
                penguinNode.AttachObject(penguin)

                camera.Move(New Vector3(0, 0, 300))
                camera.LookAt(penguin.BoundingBox.Center)
                varRoot.StartRendering()
            End If
        End Using
    End Sub

End Module

< Press Ctrl+F5 to build and run the project. if everything works, you should be staring at a penguin and are now capable of moving on to Basic Tutorial 1 If you have any problems setting up an application, post in this thread.

Views
Powered by MediaWiki GNU Free Documentation License 1.2