BlockLeftTop, PRELOAD BlockLeftBottom, PRELOAD BlockLeftStretch, PRELOAD BlockTop, PRELOAD BlockBottom, PRELOAD BlockStretch, PRELOAD BlockRightTop, PRELOAD BlockRightBottom, PRELOAD BlockRightStretch, PRELOAD
DeltaEngine

Moving to Managed DirectX for .NET 2.0

by Benjamin Nitschke 14. December 2005 07:26
The rocket commander website does support few new features now (hour, day, week lists and top 100 for all lists). Btw: Thanks to all beta testers who reported bugs.

Monday of this week the DirectX December 2005 SDK did came out (with updated Managed DirectX for .NET 2.0 stuff and even a technical preview of DirectX 10, but this does require Vista to run).

Today I tried to port my NormalMapCompressor tool to Managed DirectX for .NET 2.0 (December 2005 Edition). If you want to port your DirectX code to .NET 2.0, this post could be helpful :) If you ask why even bother porting, here is the answer: For easier debugging (using Visual Studio 2005 with .NET 1.1 DirectX causes a lot of annoying Loader Lock errors when trying to debug, etc.)! Also I like to refactor my code from time to time and make it more clean if I continue working on it, this is what happens if you port to Managed DirectX for .NET 2.0.
Please also see this post from ZMan about DirectX for .NET 2.0 changes (he already wrote about it for the October 2005 edition).

I will only mention things that happend in this little project (NormalMapCompressor), I'm sure porting Rocket Commander over will take a couple of more refactorings.

  • The DXHelp class doesn't exist anymore. For using DXHelp.GetTypeSize(typeof(YourVertexStruct)) you have to use the VertexInformation class now:
    VertexInformation.GetDeclarationVertexSize(YourVertexStruct.VertexDeclaration, 0); and obviously you have to define the VertexDeclaration in your vertex class now (but I had that done anyways).
  • TextureLoader doesn't exist anymore either, I've used it to get image information.
    For that you can now use Texture.GetImageInformationFromFile
    (was TextureLoader.ImageInformationFromFile(filename) before).
  • Many methods now expect the device as the first parameter instead of the last (more consistent method parameters now). Some examples: Mesh.FromFile, Mesh.Clone or the Mesh constructors.
  • LockVertexBuffer and many other Mesh methods are simplified now and use generics and the GraphicBuffer class now. For example the following code:
    TangentVertex[] verts =
    (TangentVertex[])someMesh.LockVertexBuffer(
    typeof(TangentVertex),
    LockFlags.None,
    new int[1] { someMesh.NumberVertices });

    gets converted to:
    TangentVertex[] verts = someMesh.LockVertexBuffer(LockFlags.None).
    ReadArray(someMesh.NumberVertices);

    If you want to write to the GraphicBuffer just use Write(.), thats also much easier.
  • PresentParameters.Windowed is now called PresentParameters.IsWindowed
  • For some strange reason the device has to be created with an IntPtr instead of a form or control, ZMan also pointed that out here. Just write form.Handle or control.Handle now.
  • Device GetDeviceCaps becomes GetDeviceCapabilities, also all other Caps became Capabilities.
  • Matrix methods got a lot longer names, say hello to Matrix.PerspectiveFieldOfViewLeftHanded and Matrix.LookAtLeftHanded (instead of Matrix.PerspectiveFovLH and Matrix.LookAtLH). There are a lot more.
  • Material does not have the .Ambient property anymore, just .AmbientColor now, which is the ColorValue. This pretty much sucks because I use Color's all over the place and have to convert them to ColorValue now, wtf? Same for Diffuse, Specular and even SpecularSharpness got renamed to Power (I still think SpecularSharpness is a way better name). I don't agree with ZMan who says "nice to see this confusing mess tidied up".
    Material mat = new Material();
    mat.Ambient = darkCol;
    mat.Diffuse = lightCol;
    mat.Specular = lightCol;
    mat.SpecularSharpness = 16.0f;

    becomes
    Material mat = new Material();
    mat.AmbientColor = ColorValue.FromColor(darkCol);
    mat.DiffuseColor = ColorValue.FromColor(lightCol);
    mat.SpecularColor = ColorValue.FromColor(lightCol);
    mat.Power = 16.0f;
  • Light.Type becomes Light.LightType, I also don't like that change (Light.Type says it all, doesn't it?), but who cares.
  • TextureLoader.FromFile(device, filename) and TextureLoader.FromCubeFile(device, filename) are now new Texture(device, filename) and new CubeTexture(device, filename), much cleaner. Why not remove Effect.FromFile and similar methods too?
  • Effect.FromFile does require an EffectPool now (I just created an empty one, I only use 1 effect in NormalMapCompressor). Also the paramerters have changed a bit.

And now the only thing I couldn't resolve yet. If anyone has ANY tips or tricks to do this, please tell me!
I could not find out how to do TextureLoader.Save or any texture save functionality at all. I need this to save the generated textures as dds files (compressed of course), saving bmp files is no problem (just locking the texture data and building a bitmap with it, then saving that bitmap). I already tried to contact specialists like Tom Miller or ZMan, but no answer yet ^^

When that problem is resolved I will release the new version of the NormalMapCompressor.

Comments


12/28/2005 1:14:28 AM #

Tom Miller tried to post this, but the post got deleted somehow (must be a bug with IE and the current dasBlog version, dunno why that happens):

------------------
Just a few comments since I'm in a typing kind of mood.

In your first bullet, rather than using GetTypeSize, you could just use the native C# 'sizeof' keyword in unsafe code.. ie, unsafe { someSize = sizeof(YourStruct); }

.Ambient being missing is a bug that is slated to be fixed now.. I didn't even realize it was missing.

Certain things such as effects still need the "FromFile/FromString" methods because each of those methods take the same parameters.  The API needs some way to 'know' that the string is either a filename or the actual text of the effect.  I suppose I could have made a constructor that was something like Effect(string data, bool isFile), but that seems even more confusing than the way it is now.

You can pass in 'null' for the effect pool object if you don't need/want it.

Rather than the TextureLoader.Save() methods, each of the texture classes should have a save method on it.. If they don't, that's a bug.

Hope this helps!
------------------

Feel free to let me know any other feedback/bugs you see/have seen..

abi | Reply



12/28/2005 1:15:13 AM #

My answer to that:
> In your first bullet, rather than using GetTypeSize, you could just use the
> native C# 'sizeof' keyword in unsafe code.. ie, unsafe { someSize =
> sizeof(YourStruct); }

Hmm, yap that is possible too, but I don't use a single line of unsafe
code in Rocket Commander (thats what the ms guys wanted ^^).

> .Ambient being missing is a bug that is slated to be fixed now.. I didn't
> even realize it was missing.

Good thing it will be fixed Smile

> You can pass in 'null' for the effect pool object if you don't need/want it.

Good to know.

> Rather than the TextureLoader.Save() methods, each of the texture classes
> should have a save method on it.. If they don't, that's a bug.

Well, there is just no save method, its not only the texture class,
almost every other class, which had some save method or helper class
to save don't have the save capability now. Only
PrtBuffer/PrtCompressedBuffer and XFileSaveObject do have a save
method. Just to name a free classes, that had a Save method before:
Mesh, SurfaceLoader (for surfaces), TextureLoader (for saving all kind
of textures) and VolumeLoader.
It would be nice if these save methods would be available again in the
next MDX2 release, then I could port my little NormalMapCompressor
tool.

I will work on some MDX2 code next month maybe if I find some time and
try to find out more, currently I'm not doing any graphical work
(writing a compiler, hehe).

abi | Reply



2/6/2006 12:44:03 AM #

Yeah, it is really annoying that you can no longer save Textures -- it's cool that you noticed this issue as well.  I'll have to hold off going to 2.0 until this is fixed.

-ben

Ben Houston | Reply



2/12/2006 11:44:17 AM #

It is fixed now in the February 2006 DirectX SDK.

abi | Reply



11/19/2009 2:46:03 PM #

Like your writing! Still you can do some things to improve it.

cash loans | Reply



1/7/2010 2:12:30 PM #

thanks!  very helpful post!! like the template btw ;)

faxless payday loans | Reply



4/9/2010 4:00:15 PM #

Great post! Thanks for the information

auctions online | Reply



4/9/2010 4:00:38 PM #

Great post, you’ve helped me a lot

customer service | Reply



4/18/2010 1:28:02 PM #

Great post! Thanks for the information

us | Reply



4/27/2010 10:15:49 PM #

I\'m happy I found this blog, I couldnt discover any info on this subject matter prior to. I also run a site and if you want to ever serious in a little bit of guest writing for me if possible feel free to let me know, i\'m always look for people to check out my site. Please stop by and leave a comment sometime!

Rapidshare | Reply



4/30/2010 11:37:17 AM #

No life ever grows great until it is focused, dedicated, disciplined.

fast payday loans | Reply



5/4/2010 6:53:35 PM #

Top Rapidshare Search engine

Rapidshare Search engine | Reply



5/5/2010 10:27:49 AM #

my God, i thought you were going to chip in with some decisive insght at the end there, not leave it with ?e leave it to you to decide?

porno izle | Reply



5/14/2010 7:43:50 PM #

I am so satisfied that I have found this your post because I have been searching for some information about the directX for .Net almost two hours. You helped me a lot indeed and reading this your article I have found many new and useful information about this subject. Well, I will definitely bookmark your website and wait for other useful and informative posts like this one in the future. Sincerely, Brandon.

viagra sverige | Reply


Add comment




biuquote
  • Comment
  • Preview
Loading



Disclaimer: The opinions expressed in this blog are own personal opinions and do not represent the companies view.
© 2000-2011 exDream GmbH & MobileBits GmbH. All rights reserved. Legal/Impressum

Poll

Which platform should Soulcraft be released on next?











Show Results Poll Archive

Recent Games

Soulcraft

Fireburst

Jobs @ exDream

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910