Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 1 down vote accepted

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]);

Follow this article to draw them:

Or examine this tutorial project:

share|improve this answer

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

Your Answer


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.