And On The Second Day, He Made A Cube. And It Was Good.

March 15th, 2009 | 7 comments

D3D10 Cube

I’m pretty stoked right now. I have my first real render in D3D10. It took me a while to get things set up, but now I’m feeling a bit better. It definitely has shaken some of my conceptions of how things worked in Native Land, but I’m getting there.

So far the two main stopping blocks for me are 1) inadequate help materials from Microsoft and 2) outdated materials from the community. One of the largest sources of help for this step was to read Jack Hoxley’s page on Beginning Direct3D 10 Programming. I’m not sure when he wrote that, but I’m guessing it was during a beta of D3D10 as a few of the structures and functions have changed. It wasn’t too hard to sort out with MSDN, but it wasn’t the most easy of things.

Which brings me to Microsoft. Coming from the world of XNA, I’m really disappointed in the help materials Microsoft provides for their native side. Sure MSDN is great and documents each method and structure, but none of those pages (well, almost none) give you any actual idea how to use the methods. No code examples, no tips or tricks, not even a link to an example somewhere else. It made a lot of things very trial and error for me.

Then there’s the SDK samples and their MSDN accompaniments. Those are nearly worthless. The code is only minimally commented and the accompanying MSDN articles don’t cover all the code. So there were parts of the code I literally was just copying and pasting with no idea what they did. I read theMSDN docs on the structures so I think I get it, but what’s missing is the conceptual help.

Sure it’s great that I got all of this set up, but there are lots of things I’m still a little confused on. For example, the BufferCount of the DXGI_SWAP_CHAIN_DESC. MSDN has this to say: “A value that describes the number of buffers in the swap chain, including the front buffer.”. So to me, that means I should specify two there because I want double buffering. But then I see this post from a guy who knows way more about native Direct3D than I that says that the docs have a typo and that it’s just the number of backbuffers I want. So now I’m basically left to trust him (because I do) and start wondering what else is wrong in the MSDN docs.

All in all it’s been a steep curve. I have stuff rendering now so hopefully most of the setup stuff is done for me and I can learn all the APIs for managing index buffers and learning more about some of the new shader semantics (which if you’ve not touched SM4.0 yet, you’d do well to look that up as they changed a lot of how the .fx file works for D3D10). I’m not at a point where I feel like I should be sharing code because I don’t know how good it is, but I will share a few of the main points I noted while working:

  1. After you create the render target view, make sure you set it. I know it sounds stupid, but after the few steps it takes to get the backbuffer and make the render target view, I forgot to set it to the device. This won’t result in an error or a crash, mind you. In fact, you can still clear the screen color however you’d like. But when you go to draw any triangles at all, you won’t see anything. Took me a while to spot that line was missing from my code.
  2. When setting up a D3D10_BUFFER_DESC for your vertex buffer, just use sizeof(myVertexArray) for the ByteWidth field. ByteWidth expects the total size of the vertex buffer. So while you could use sizeof(MyVertexStruct) * numberOfVerts, it’s just easier to use sizeof on the actual array. Less error prone.
  3. When it comes to rendering, if you’re coming from XNA, you’ll be a little shocked when you find out there is no Begin/End methods when it comes to effects. You simply iterate over the passes of a given ID3D10EffectTechnique, call Apply on the pass, and then draw your triangles. That’s it. I really feel like I’m missing something here, but that’s how the sample shows it, so I guess that’s really just how it is.

Stay tune as I keep on my way. It’s getting interesting now that I can actually see something on the screen and have a stable game loop implemented.


Possibly Related Posts

(Automatically Generated)
I am Employed Once More!
Completing My MVP
Extension Methods and You
Paint.NET plugin for premultiplied alpha

  1. March 15th, 2009 at 18:02

    Now, make it dance. I love the feeling of learning something new. Always good to meet someone with that same enthusiasm.

  2. Bjoern
    March 16th, 2009 at 02:04

    The DX docs (and I include the XNA FX ones in there, too) have always been on the sparse side – I presume to support MVPs writing books about it ;) And I am a bit unsure whether the lack of a Begin/End pair on ID3D10EffectTechnique shocks me even the slightest: simplicity ftw!

    Anyway, welcome to the native side :)

  3. March 16th, 2009 at 05:21

    @Andre: I have it spinning. Does that count? :)

    @Bjoern: I’m all about the simplicity. It’s just a bit of a change to go from Effect.Begin-Pass.Begin-Draw-Pass.End-Effect.End to Pass.Apply-Draw. But it’s a good change.

  4. March 16th, 2009 at 08:47
  5. March 19th, 2009 at 14:37

    Outdated materials wouldn’t happen if the API wouldn’t change that much between two versions – however that’s why DX is superior to OpenGL, at least IMHO (was sooo much fun to read the reactions on the ogl3.0 release, which didn’t match the expectations).

    Well, I’m curious how far you will get within the next few months/weeks. When I decided to take a look into DX, I just lost interest after two weeks. But that might be because I wanted to get something done, and not getting in touch with it ;)

  6. March 20th, 2009 at 07:08

    What’s with all this native DirectX stuff Nick? Are you getting bored with XNA?

  7. March 20th, 2009 at 07:13

    @sphereinabox: That is my new bible. Thanks for the link.

    @sirlantis: I’m hoping to keep with it, though my new job does eat up a lot of time with the commuting required. So it’s likely I’ll only have time for this project on weekends.

    @darknut101: Nope. I just believe in doing something if it seems fun and interesting. I don’t feel like I have to choose between native Direct3D and XNA; I can play with each of them when I want to. Plus as I mentioned in my other post, my MVP says XNA/DirectX so I figure I should get to know that DirectX side a bit more.

You must be logged in to post a comment.