|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis is the second in a series of tutorials which will allow you to create your own game engine (from initialization, to a fully rotatable, height-mapped 3D world!). In this second tutorial, we will actually write code to create a link to the computer's graphics card. To do this, we will initialize Direct3D, and create a BackgroundThe code from these tutorials is taken from my own game engine: MAGEngine.NET at different stages in development. Using the codeYou may use all of the code I provide as how you see fit, except to create another tutorial. You can use it as a sturdy(ish ;)) framework for your own applications, or print loads of copies off so that when I'm rich and famous you can sell them for $100 each ;) PrerequisitesTo do this series of tutorials, you will need:
Tutorial 1: Setting Up DirectXDirect3D is the main component of DirectX graphics. With it, you can render and initialize 3D objects. We will not get to render anything in this tutorial, but we will set D3D up so that we can do this easily in the next tutorial. InitializationThe point of initialising Direct3D is to get a The initialization function is as follows: public Device(
"http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemint32classtopic.asp" target=_blank>int adapter,
"http://msdn.microsoft.com/archive/en-us/directx9_m_dec_2004/directx/ref/ns/microsoft.directx.direct3d/e/devicetype/devicetype.asp" target=_blank>DeviceType deviceType,
"http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasstopic.asp" target=_blank>Control renderWindow,
"http://msdn.microsoft.com/archive/en-us/directx9_m_dec_2004/directx/ref/ns/microsoft.directx.direct3d/e/createflags/createflags.asp" target=_blank>CreateFlags behaviorFlags,
"http://msdn.microsoft.com/archive/en-us/directx9_m_dec_2004/directx/ref/ns/microsoft.directx.direct3d/c/presentparameters/presentparameters.asp" target=_blank>PresentParameters[] presentationParameters );
OK, this may look complicated at first, but we can break it down.
So, our initialization process will consist of two parts:
To start with, add the following variables to the top of your window class: public Device device;
public PresentParameters presentParams;
Now, before we get started on making a class and functions to initialize Direct3D, we should explore the For this application, we only need to assign two members from the
public PresentParameters SetPParams() {
PresentParameters pp = new PresentParameters();
return pp;
}
This will be set as the framework for the function that will create the presentation parameters for us in our engine. Now, as stated before, we need to input two variables and edit these accordingly, so simply add a public partial class cEngine
// the partial keyword specifies that this
// class is declared in multiple files
{
public PresentParameters SetPParams (bool wind, SwapEffect swap)
{
PresentParameters pp = new PresentParameters();
pp.Windowed = wind; // Is our device going to be running
// in a windowed or full screen application?
pp.SwapEffect = swap;
// How should we handle the refreshing of our application?
return pp;
}
}
So, that covers As mentioned before, the device represents the GPU, or graphics card. Towards the top of this tutorial, you saw a layout of the public partial class cEngine
// the partial keyword specifies that
// this class is declared in multiple files
{
public Device SetDevice( Control wnd, PresentParameters pp)
{
Device device = new Device(0, DeviceType.Hardware,
wnd, CreateFlags.HardwareVertexProcessing, pp);
return device;
}
}
This function simplifies the creation of a device by limiting the number of parameters, as ones which are almost always the same are omitted. With these two methods, all you need to do to get your D3D application running is add the required variables to the //Form1
public cEngine Engine = new cEngine();
//Main
using (Form1 GameWindow = new Form1())
{
GameWindow.presentParams =
GameWindow.Engine.SetPParams(true,
SwapEffect.Discard);
GameWindow.device =
GameWindow.Engine.SetDevice(GameWindow,
GameWindow.presentParams);
Application.Run(GameWindow);
}
If you get errors, make sure you have Now, when you run this application, there is no proof of all that work you did - which I personally find annoying. So, add a paint event handler to the form. X-CHALLENGE
Well done - you should now have a working Direct3D application, along with a basic framework! Get ready to move on to tutorial 3 - where we will actually render something on screen! ContactPlease send all emails to xpyder@magclan.cwhnetworks.com. I do have MSN Messenger, my email address for this is jamespraveen@aol.com. History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||