Thursday, June 01, 2006

Beginner Direct X & Life

Life

Today( i should say is yesterday...) is "Duan Wu Jie" a chinese festival, name as DragonBoat festival in english i guess. Traditionally we should eat some "zhong zi" or "Ketupat" in Malay as celebration for this festival and race a dragonboat, sad to say that, i didnt eat any :( The fun thing is the crazy Larry and his Puchong Gang came over to Setapak to have a LATE dinner with us. So we end up at "Dong Jin" or "Tokyo" which located at Setapak Indah. 11 of us ordered 9 plate of dishes which is totally break my life record. The price is STUNNING, why? 11 people 9 plate of dishes just rm 140. Stun? hehe.

Life today is easy, actually I added this topic today because I want to make one chance to share a forward mail, by my friends to share with you all, Malaysian especially. The mail is about some hidden news which actually happened at Malaysia but no media dare to report it on their media tools. So this reporter write an online article and share it within the net. We can see how darkness and controlless of Malaysian freedom now. This article is written in chinese, i guess an english and malay version should be around in anytime and i dont have the actually source of it, i got it in mail form and it is damn long article. So, anyone interest can PM me or leave an comment here and i will forward to mail to you.

Direct X at a very Beginning Stage

I not sure this is useful or not, but this is the answer which I searching all the way when I want to start learning my Direct X. The question is "How actually am I going to make a "hallo world" program in Direct X. For me, the very 1st step to actually start learning a language is know how exactly it going to use and happen something. I read all the books, articles and theory but i still have no idea how actually i can start coding a direct X program. I learnt this today. and stupid me i don't know the answer i seeking all the way is sleeping in my laptop for so long time just the matter i didn't realize it. Where is it? C:\Program Files\Microsoft Direct X SDK June 2005\Sample\Tutorials\ . Now you know why I said i am stupid, because you are laughing too.

(It's actually 5 am now...ahh.....tired)

Okay, what i am trying to share today is how actually is a very damn basic direct X program going to work and actually display some easy stuff on the screen. I going to express in a written and more theory way, mean, no code and if got code, the syntax is not 100% correct :P Find me personally to discuss about it then.

First of all, download the direct x sdk from microsoft.com, it is free. extract it. Get yourself a Visual compiler, recommend is Microsoft Visual Studio 2005. Find the Tools->Option->Project and Solution->VC++ includes. from the second drop down combo, chose Include files and Library files. find the "\include" and "\lib" folder at Direct X SDK folder, add them and move them to the highest place in that list. One thing extra is, when you adding the Library file, you will notice that there are two folder in the \Lib, one is \x86, another one is \x64. I dont know what is that, but i need to include the \x86 to actually compile the tutorial code without a single problem, so...beware of that.

Now you can add any of those sample to the compiler and run them by the time study the code. This is my favourite and fastest way of learning programming and I think most of the people will love this way. I learn a lot of theory and some coding by the Direct 9 RPG programming book but i have no idea how to actually code one. I knew now. Theory + pratical make perfect, hehe.

I like to share some of my OWN guildeline about how actually the D3D thingy flow in the program (this is just Kuan's own view). What i learn today, i think is the basic of the Fixed Pipeline i talked about at previous post, vertex programming is expert mode I think, we need some stepping stone and basic understanding anyway. Don't Fly.

  1. Direct X work in windows, so, it is actually windows programing of C++. WinMain is the entry point of the program. From here you create the Game Loop by peeking the window's message everytime and render the screen.
  2. Before entering your loop, you need to do a lot of initialization. That is the core part of Direct X i think, many, and many of initialization need to be done to get the thing works, but as you did the init, then the work after that is much more easier.
  3. Init a D3D object (g_pD3D). from the obejct, get a parameter variable, and create a device (g_pD3Ddevice). set the renderstate of the device if needed at the Init() function.
  4. After the device is done, Init the Vertex (or geomatry if multiple meshes needed). If both is pass, then only enter the game loop.
  5. In every Render() called. First clear the screen with one color then only begin rendering.
  6. Sequence of rendering is. 1st get the matrices (world, view and projected), 2nd, set the material, 3rd, create the vertex stream and lastly draw it. Repeat if any other meshes appear on the screen. Last thing is swap the back Buffer.
Well, i think this is the most most most basic thing i learnt today. I guess it is still buggy and many features cut of. Will improve it very soon. So i end my post now. SLEEPY.

Today Feeling !!! Friends are wonderful and the people to give meaning to your life.