Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm new to game development and XNA. I have this depthmap image and I want to render it in 3D, how do I do it, any tutorial or blog post would be helpful.

share|improve this question
    
do you want to draw it for example as wire frame? –  Vodáček Jul 22 '12 at 18:15
add comment

2 Answers

Load a texture:

texture = Content.Load<Texture2D>("depthmapimage");

Put the texture data into a color array:

Color[] pixels = new Color[width * height];
texture.GetData(0, new Rectangle(), pixels, 0, width * height);

Iterate the array to generate vertices:

for (i = 0; i < height; i++){
    for (j = 0; j < width; j++) {
        // check red value for z, convert i and j into x and y, etc...
        nextvertex = generateVertexFromColorDatum(pixels[i * width + j]);
        listOfVertices.Add(nextvertex);
    }
}

Follow this article to draw them:

http://msdn.microsoft.com/en-us/library/bb196414.aspx

Or examine this tutorial project:

http://xbox.create.msdn.com/en-US/education/catalog/sample/primitives_3d

share|improve this answer
add comment

For a simple vizualisation you can create plane mesh tessalated in you depth buffer resolution (for example 1024x728 vertices). If the plane is in xz axis, move vertices in y axis based on values in depth buffer. You can also use near and far plane information to have correct depth range and if you use perspective camera, you should take into account FoV angle too.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.