« Alas, How Plans Change | Main | New Website and Plans! (Not April Fools) »
Monday
Apr042011

Hi DirectX, It's Nice to See You Again

So I spent this weekend exploring SlimDX and DirectX in general. Why SlimDX and DirectX instead of XNA? XNA is cool and all, but if you've got no content to draw then it's not very interesting. So I thought I'd write myself some tools to start with, and brush up on my C# and DirectX knowledge along the way.

I started with the SlimDX tutorials (which are kind of oddly written, but easy enough to follow) and was happy to see my very first DirectX triangle in years. The last time I had played with DirectX was when DirectX 9 was shiny and new, and that was long before I understood the math that mapped that triangle to the screen. But now I do, and thus the next logical step was writting some camera class to manage that math for me.

In visualization, the most common tool for this is an arcball camera. Everyone uses an arcball camera, and conceptually it's pretty damn easy. Perfect first 'project' in C# and DirectX. Took about an hour (where in the DirectX docs can you find info on how constant buffers expect matrices to be laid out?) but after a lot of swearing and futzing, I had a nice, smooth arcball.

Of course, my cube (upgraded from the initial triangle) wasn't particularly interesting. Rather than do the most familiar thing and write a simple raycaster, I decided to try to do something more game related.and I wanted to draw a moel, but then I found out that Microsoft dropped model loading code in DirectX 10, and since I was targetting 11 for my tools, I was going to need to write my own.

But before that I would need some models to load. Thankfully, the DirectX 11 SDK comes with some, even if they're in the not-for-production-use SDKMesh format. I decided to write a loader for SDKMesh files anyway -- it'd be good C# practice.

First off, let me just say that the MSDN description of a SDKMesh file is useless. If they had listed the types and byte offsets of the members of their structures then it would have been easy, but alas I spent most of my time poking around SDK example projects and hitting F12. I also got a healty refresher on C/C++ struct layout guarentees -- the one where the compiler will lay them out as it pleases.

All in all, it took much longer than I had thought it would, but I did finally get it working. Granted, I did waste a bit of time by porting the DDS without D3DX example because I couldn't find where SlimDX had put the stuff, but hey, now I've got a separate DDS loader just in case. Next up is a crash course on HLSL I guess, then some ironing out of the actual Tactical RPG game design and data formats.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (5)

Like your blog so far, looking forward to reading more about your adventures in SlimDX. I too just started looking into, got here from a google search of SDKMesh. I'm thinking it will be quite a bit easier to use the .obj and .mtl formats though. I just starting reading up on it today, but most likely tomorrow I'm going to write a obj/mtl parser library for SlimDX. I'll just stick with obj at first, just to make it easy to load in files, but I will extend it for shading groups as well eventually. I'll let you know when it's done if you are interested.

April 15, 2011 | Unregistered CommenterTanner

I had always wanted to learn about this topic ... I think it's great the way you expose .. great work and continuing on with this great blog hdyclt hdyclt - Moncler Jackets Kids.

October 25, 2011 | Unregistered Commentervjpgip vjpgip

As one of the most popular tv series,Game Of Thrones dvd has been one of the bestsellers of our products.If you wanna more information of game of thrones dvd release date ,you may come to our site learn more.We offer the cheapest and best items.Welcome!

November 11, 2011 | Unregistered CommenterGame Of Thrones Season 1 DVD

Just wanna to say hi! Really, nice posts. By the way, Christmas is coming! and our store gave lots of free gifts for you.
christmas special: Free Shipping for all!!!
1000s of dvds watting for you, such as Sons of Guns DVD

November 14, 2011 | Unregistered Commenterdvds

Your website have very interesting article. I got knowledge from here. Besides that, your blog is so popular among the searchers from search engines. It means yours website is very goodAlarm Monitoring Houston [url=http://www.smithmonitoring.com/houston-security/]Alarm Monitoring Houston[/url]

December 11, 2011 | Unregistered CommenterAlarm Monitoring Houston

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>