Delta Engine Blog

AI, Robotics, multiplatform game development and Strict programming language

NormalMapCompressor v1.4

As announced in my last post I've updated NormalMapCompressor to Managed DirectX for .NET 2.0 with help of the February 2006 DirectX SDK.

You can download the whole thing by clicking on the image on the right or with help of these 2 links:

Couple of notes: The GraphicBuffer (formally GraphicStream or just accessing data with .Lock methods directly) is really strange. Writing does always work, but when reading data all kinds of things have to be checked by yourself. All the data in GraphicBuffer (Data sizes, Elements, Data lengths, etc.) are always 0, so they don't help you at all. Doing foreach is possible, but doesn't work either. Direcly accessing with help of the indexer works fine (but you have to copy all data over to a temp. variable and then copy it back). I found that out the hard way by trying everything out until it worked finally. Here is some code:

int numOfVertices = someMesh.VertexCount;
GraphicsBuffer<TangentVertex> verts =
  someMesh.LockVertexBuffer<TangentVertex>(LockFlags.None);
for (int i = 0; i < numOfVertices; i++)
{
  // Get vertex data
  TangentVertex vert = verts[i];
                
  // Change texture coordinates
  vert.u = (float)(Math.Atan2(
    -vert.pos.X, vert.pos.Z) / Math.PI);
  vert.v = 0.8f *
    (float)(0.5f - vert.pos.Y / 2.0f);

  // Set changed vertex
  verts[i] = vert;
} // foreach (vert)

Same problems for converting the texture, but I used a totally different approach there (converting everything to a bitmap stream and than creating a new texture with that). Other than that the initial conversion took less than a hour, couple of renames and thats it.

I don't get the point why VS 2005 puts the Microsoft.DirectX.dll (MDX 2.0) into the debug and release directories. First I thought: "Cool, maybe this works now even with older DirectX versions". But after testing on my brothers computer nothing worked except when DirectX Feb2006 was installed. I adjusted the installer to that.

So if you can live without the missing MDX 2.0 help (for example if you are already experienced enough in MDX 1.1), it is really an option with DX Feb2006. All missing methods from the last betas were added and most problems are resolved. I think it looks pretty good and I will use MDX 2.0 directly in future projects.

Comments are closed