Writing a game using Managed DirectX.. The Contest..

With the upcoming release of my new book, I thought it would be pretty cool if there was a contest held for writing the ‘best game’ using Managed DX.  Details are sketchy right now (like will people outside of the US be allowed to enter), but it’s something that will be happening..

While rules and regulations are still being decided, here are some things you can start thinking about if you’re interested..  The devleopment process will probably be two-three months..  Entries will be scored on numerous different ‘categories’ such as:

  • Originality
  • Gameplay
  • Fun-Factor
  • Use of Shaders (HLSL)
  • Use of ‘DX9 Features’ (i.e., PRT, HDR, etc)
  • Artisitic appeal

Naturally, the categories will be weighted.. Oh, and good prizes, etc..  I’ll keep you posted on details as they become available..

Why can’t I compile Managed DX code using the MC++ Compiler?

This has become a popular quest recently, so naturally that means it must be time to blog about it..  People have been discovering that simple MDX code just doesn’t seem to compile with the Summer 2004 release of the Managed DX assemblies..  Simple code such as this:

Form1 __gc* pForm = new Form1();
// Create a new device
Device __gc* pDevice = NULL;
PresentParameters __gc* pParams = new PresentParameters();
PresentParameters* pArrayParams __gc[] = {pParams};
// Setup params
pParams->SwapEffect = SwapEffect::Discard;
pParams->Windowed = true;
pDevice = new Device(0, DeviceType::Hardware, pForm, CreateFlags::SoftwareVertexProcessing, pArrayParams);

They’ll see compilation errors such as:

Form1.cpp(24) : error C3635: ‘Microsoft.DirectX.PrivateImplementationDetails::IDirect3DDevice9’: undefined native type used in ‘Microsoft::DirectX::Direct3D::Device’; imported native types must be defined in the importing source code
did you forget to include a header file?

Which is puzzling to say the least, and even more so because using the Summer 2003 SDK release will work correctly.  The problem lies in how the MC++ compiler generates assemblies with native code in them.  First, it will actually create public variations of the unmanaged components (i.e., IDirect3DDevice9) and stick them in the assembly.  Unfortunately, it places these ‘types’ in whatever namespace the #include for the header file happened to be in, normally the ‘blank’ namespace.  Look at the MDX assemblies from the 2003 release in the object browser and you’ll see what I mean as it is literally cluttered with hundreds of these bogus types.

For the 2004 release, we decided to ‘tidy up’ these references, and move them into a single ‘private’ namespace.  Looking at the MDX assemblies for the 2004 release, you’ll see that all of those unusable ‘types’ are now found in the Microsoft.DirectX.PrivateImplementationDetails namespace.  Much cleaner to look at, much better organized.

However, now when the MC++ compiler tries to *use* these assemblies, for whatever reason it looks for the native types to be declared *within that same namespace*.  You’d have to ask the MC++ team why this is since it seems a little strange to me (i.e., C# and VB.NET work just fine without this information)..  In order to successfully compile the code above using the 2004 release you need to actually *include* the d3d9 header files within the namespace mentioned above.  Something such as:

namespace Microsoft
{
namespace DirectX
{
namespace PrivateImplementationDetails
{
#include
}
}
}

Thankfully, the MC++ compiler for the Whidbey timeframe is much improved, and situations like this will soon be a thing of the past.  But in the meantime, this is how you get around the issue people are having trouble with.  (Note that you’d also need to include the file if you’re using the functionality provided there)

Who would have thought road trips involved so much driving?

I guess I should have realized that since I did use Streets And Trips 2005 to actually plan the trip, but I’m here to tell you..  Reading about a 2-day 19 hour one way drive is a lot different than actually *doing* said drive.  That being said though, once you ignore all of the driving that was done, once we were actually in Vegas, then we had a great time.  It wasn’t our first trip onto the strip, but it was the first time I actually realized you could go up to the top of the Eifel tower they have there.  You get a great view, but boy was it windy..

Of course, while you’re there you’ve got to gamble.  Well, I suppose you don’t *have* to, but it’s something that I enjoy.  Naturally, I enjoy black jack since that’s one of the few games in the casino you could actually do well at, providing you know what you’re doing.  For me, it never fails..  I’ll get to some point where I’m actually winning, and ‘up’ a decent amount of money before I forget how I got to that point, and start changing my betting habits, dramatically increasing the amount of bets i’m placing.  Every trip down there, I spend a portion of time way up, just to give most (or all) of it back before I leave, and this trip was no different.  I suppose that’s better than losing money (which I’ve yet to do), but just once I’d like to see my winnings pay for the trip. 🙂

We weren’t there long enough to see many of the shows this year, but we’ve seen most of them already anyway.. A couple years ago, we saw Blue Man group @ Luxor, and IMHO, that is probably one of the best shows in Vegas..  Surprisingly enough, it wasn’t dramatically hot there this time either.  Sure, it was much hotter than it was here in the Seattle area, but it only broke 100 once, and was only ‘warm’ in the evenings..  A dramatic change from late August 2002, when it was regularly >115..

Even with my complaints on the driving, there were still some interesting things to look at.. Like a golf course in the desert.  The mountains you see in Arizona and Utah are much different that what we see here in our area as well.  I even saw a small tumbleweed blow by once..  It was straight out of a cartoon..  Oh, and one more minor thought about speed limits..  The speed limit around here in 60 around the ‘cities’, and 70 everywhere else.. Oregon was similar, except it seemed to be 60/65 instead of 60/70..  All of the other states we drove through were 65/75, and that extra 5mph makes a world of difference..  I remember back in the day, the speed limit was national (granted it was only 55mph)..  All of the changing speed limits were really annoying, particularly on the way back when i had to slow down as I got closer..  And don’t even get me started on road construction..

Anyway..  My next trip will definitely involve a plane..  Even with the added security headaches, it’s still easier than all that driving..

Road Trip!

Like Greg mentioned earlier this week, my birthday is rapidly approaching (oh, happy birthday to Greg too!), so since i rarely get to go on vacation, I decided to take a road trip..

I’ll be gone for about a week.. Will barely have access to a computer, won’t have access to email or anything..  Instead i’ll be in Las Vegas having quite the time..  What Fun!

The Summer 2004 SDK Update For DirectX has been released..

— Official announcement – DX Web site should be updated soon..
The DirectX(r) Team is pleased to announce the final release of DirectX 9.0 SDK Update (Summer 2004)!
The DirectX 9.0 SDK Update (Summer 2004) contains updated versions of the D3DX library, graphics samples, sample framework, tools and Managed DirectX documentation. Areas of concentration in the DirectX 9.0 SDK Update (Summer 2004) release are:
– HLSL support for Pixel Shader & Vertex Shader 3.0
– Effects Framework performance improvements
– Pre computed Radiance Transfer improvements
– New Sample framework
– New & Updated Samples
– Improved Documentation
– PIX tool for better debugging of Direct3D applications
– Introduction of the Preview Pipeline for easier content creation
For information on what is supported in shader model 3.0, refer to the updated reference documentation. You can install the final releases from the below locations.
Software Developer Kit (230Mb+)
Extras (40Mb+)

Symbols (20Mb+)

Release Notes
Please feel free to post any concerns and/or discuss any issues with this SDK release within this forum, the public newsgroups or mail us directly at directx@microsoft.com
Enjoy!

Moving Day!!!

Hard to believe that in a little less than 20 hours I’ll be moved into our new house.  While the wait between signing the papers to have the house constructed (November of last year) until now has seemed to take eons upon eons to get here, in reality, it hasn’t been that long at all..  And now that the day has finally arrived, and my current house is virtually completely packed (aside from my computer of course), it’s definitely a lot harder to believe than I imagined it would be.

Look at it now!

Amazing how quickly these things happen.  Now, the fun of moving and unpacking begins.  Somehow I think these things will be much less exciting once the move is complete.

Why are these textures taking up so much memory..

Someone on the newsgroups was recently asking why loading his simple 800×600 texture was taking up so much memory (more than 5 megs).  He was using code something like the following:

Texture myTexture = TextureLoader.FromFile(myDevice, somePath);

The quest seemed interesting enough for me to post my response here as well as in the newsgroup since this reinforces my belief that you should always know what the methods you’re calling ‘cost’.  It wouldn’t surprise me to find out that most people don’t realize all the things that go in with that simple line above.

So here was my response:

First, if you’re texture is really 800×600, using this overload (TextureLoader.FromFile) will ‘upscale’ the texture so that it is square and a power of two, in this case, 1024×1024..  Assuming 32bit color for each pixel, the default mip level would be:
1024x1024x4 = 4 megs of pixel data.
Now, this overload would also create a mipmap chain down to 1×1, so you would also have:
512x512x4 = 1 meg of pixel data
256x256x4 = 256k of pixel data
128x128x4 = 64k of pixel data
64x64x4 = 16k of pixel data
32x32x4 = 4k of pixel data
16x16x4 = 1k of pixel data
8x8x4 = 256 bytes of pixel data
4x4x4 = 64 bytes of pixel data
2x2x4 = 16 bytes of pixel data
1x1x4 = 4 bytes of pixel data
So, add it all up, and each texture you load would take (on average) 5.6 megs of pixel data..  So the numbers make sense to me..

Now that the Whidbey Beta is out, what about Managed DirectX?

With the release of the Whidbey (err, I mean Visual Studio.NET 2005) beta a few weeks ago, my thoughts have drifted towards how Managed DirectX may work in this new release.  For those of you who haven’t seen VS2005, or the new CLR, the changes there are magnificent.  Across the board, improvements have been made, and the thing is looking wonderful.

So my thoughts roll over to MDX, and I think to myself, “Self: wouldn’t it be awesome if we took advantage of some of those features?”  Who wouldn’t want to declare the vertex data they’re about to use like:

VertexBuffer vb = null;
IndexBuffer ib = null;

Of course that just scratches the surface of the possibilities that would lie in a VS2005 specific version of Managed DirectX.  Which begs the question, what do you think?