Click here to Skip to main content
11,705,453 members (32,739 online)
Click here to Skip to main content

d3d Game Engine Written in C#

, 6 Nov 2007 33K 1.7K 27
Rate this:
Please Sign up or sign in to vote.
The beginning of a 1st person 3d game engine written in C# using managed DirectX
Screenshot - illusions.jpg


Required for debugging: DirectX9 SDK for .NET

This is my first try to write my own 3D game engine in C# using managed directX.
To get this done, I had to solve many small and complex problems.

Here are some of the implemented features:


  • Setting up a d3d device
  • Reading keyboard and mouse input
  • Drawing fonts
  • Drawing primitives
  • Loading and drawing meshes
  • Using light and fog basics


  • Rotating and translating world and meshes around the camera
  • Integrate automativ collision detection between meshes
  • Effects that collision has on the player's movement
  • Logic for opening doors and using elevators

My backgound is easy. Like thousands, I have a dream of writing my own game sometime.
Unfurtunately I've not got enough free time to finalize it...

Using the Code

Sorry my code is a hell of 'non documentation'. Give me feedback, if there's interest, I'll add a full documentation of the code.

But if you want to read it, you should begin with OnPaint method in Form1. This is the main loop which calls all relevant functions.

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
            if (WorldLive.Exit)

            IConsole.DisplayText = "";            
            for (int i=0;i<WorldLive.MovingGameObjects.Count;i++)
                if (WorldLive.MovingGameObjects[i].PU != null)
            DateTime DT = DateTime.Now;
            TimeSpan TS = DateTime.Now - DT; 
	   IConsole.DisplayText += "CheckInterceptions " + TS.Ticks.ToString() + "\n";



             DT = DateTime.Now;
             TS = DateTime.Now - DT; IConsole.DisplayText += 
			"HandleInterceptions " + TS.Ticks.ToString() + "\n";

             DT = DateTime.Now;
             TS = DateTime.Now - DT; IConsole.DisplayText += 
			"RealizePrecalc " + TS.Ticks.ToString() + "\n";

             DT = DateTime.Now;
             TS = DateTime.Now - DT; IConsole.DisplayText += 
			"ClearInterceptions " + TS.Ticks.ToString() + "\n";            

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 
					Color.DarkGray, 1.0f, 0);
            DT = DateTime.Now;
            device.RenderState.Ambient = Color.DarkSlateGray   ;
            TS = DateTime.Now - DT; IConsole.DisplayText += 
				"Scene " + TS.Ticks.ToString() + "\n";
            text.DrawText(null, IConsole.DisplayText, new Point(10, 20), Color.White);
            displayText = "";


  • 6th November, 2007: Initial post


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionA fun project Pin
vertex434331-Dec-13 4:47
membervertex434331-Dec-13 4:47 
Questiongood Pin
MichMsk6-Nov-07 23:43
memberMichMsk6-Nov-07 23:43 
AnswerRe: good Pin
cellarjay7-Nov-07 2:40
membercellarjay7-Nov-07 2:40 
QuestionCool project Pin
Borg.kz6-Nov-07 18:55
memberBorg.kz6-Nov-07 18:55 
Very cool project!!! I`m want write 3D turn-base strategy on Gexagon map, and was find simple hex engine (in this portal), but he written whithout documentation. My knowledge DirectX too small and can i ask you, recommend useful internet resources or maybe you know intresting project with Gexagon(source code on C#).
Sorry, on the my terrible english Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150819.1 | Last Updated 6 Nov 2007
Article Copyright 2007 by cellarjay
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid