How to create a heightmap and skydome using Terragen for XNA

Google AdSense

In this example, I’m going to use the Generated Geometry Sample provided by the XNA Creators Club as the code base, so we can just focus on creating heightmaps and the skydome.

Terragen is a great scenery generator and best of all, it’s free for personal (non-commercial) use. However, the unregistered version has some limitations such as the image dimensions that you can generate. There’s a great gallery of Terragen graphics showcasing it’s abilities. Terragen also has numerous plug-ins for other 3D software packages such as Blender, 3D Studio MAX, LightWave 3D, Maya, etc.

The heightmap used by the sample is named “terrain.bmp” and it’s dimensions are 257×257. The sky image used by the sample is named “sky.bmp” and it’s dimensions are 2048×1024. Both of these images are found in the root Content folder.

Generating the heightmap

When Terragen opens, you will find the Landscape dialog at the foreground. To generate a random terrain, click the Generate button. On the Terrain Genesis dialog, you can play with the various options for a bit. Finally, click the Generate Terrain button and then the Close button.

To preview the terrain, click the Render Preview button on the Rendering Control dialog. Without a texture applied, you probably won’t see much.

Exporting the heightmap

To change the file dimensions, click on the Size button of the Landscape dialog (located in the Terrain panel). You can increase the size to 513×513 with the unregistered version of Terragen. Registering the software will allow you to export to higher resolutions.

You can export the surface to a RAW image format and then convert it to an image format such as BMP, JPG, etc. that is more friendly with the XNA environment. Alternatively, you can download the FEO (For Export Only) plug-in that enables you to save your terrains to BMP, DXF, RIB, and OBJ formats (once you follow the install instructions for FEO, you can click on Accessories and Export to BMP).

Once you get the image into a BMP format (or other XNA compatible format), just copy the file into your Content folder. We’ll get back to that after we finish the skybox.

Generating the skydome

Now that we have the heightmap finished, we can move on to the skydome. In this sample, the skydome is just one image that wraps around the terrain. We can create this by taking four images (North, East, South, West) from the center of our scene and stitching them together.

First, we need to setup our scene.

Uncheck the Fixed Height Above Surface for camera and target (2 checkboxes) in the Camera panel.

Find a good spot to use as the center point. I chose the center of my surface (x=128, y=128 terrain units). I played around a bit with the altitude (z) until I wasn’t below the surface.

Increase your detail slider to the max (rightmost) in the Image panel.

We need to apply some texture to the surface so our image will look nice. Click the Open button in the Surface Map panel of the Landscape dialog. Terragen comes with a handful of surface maps that you can use (you’ll may need to browse to your Terragen install directory). I’ll chose GrassAndSnow2.srf for my surface.

Exporting the skydome

Set your Image Width and Height to 960 and 960 (the best resolution you can export with unregistered is 1280×960).

The next few steps will take the longest time. You’ll need to change your camera settings, render an image, and save the image for each of our four directions.

Alternatively, you can download the script at the end of this article to automate the process. It will still take a while to render each of the images, but at least you can walk away for a few minutes.

View Name Camera Heading Camera Pitch Camera Bank
North 0 0 0
East 90 0 0
South 180 0 0
West 270 0 0

Change the camera orientation to the above parameters, render the image, and then export the image. Once all 4 images are done, stitch the images together in a clockwise manner (N->E->S->W or S->W->N->E, etc.).

You may need to reduce the combined width of the image to 2048 to run on your PC.

Testing the scene

Open the GeneratedGeometryWindows solution.

Note: If you overwrote the files from the sample using the same filenames, then you can skip this part and just start the sample application to view your work. You will need to rebuild the solution, so that the XNB files are updated via the pipeline otherwise, it will load the old XNB files.

Adding the files to the project

In the Solution Explorer, make sure you enable the Show All Files option by clicking the button above the solution tree. Expand the Content folder (you may need to refresh the file list).

Select the terrain heightmap image from the previous steps, right click, and choose Include In Project. View the heightmap image properties and change the Content Processor to TerrainProcessor.

Select the sky image from the previous steps, right click, and choose Include In Project. View the sky image properties and change the Content Processor to SkyProcessor

Make code changes

Update the code in the function called GeneratedGeometry.LoadContent. The model loaded for the terrain object should be the filename that you created (do not include the file extension). The sky file loaded for the sky object should be the skybox image that you created (do not include the file extension).

Run the application

Build your solution and then click Start Debugging (or just press F5) to see your newly created heightmap and skydome. You may also want to turn off the Fog effects drawn on the terrain (in the GeneratedGeometry.DrawTerrain function).

Notes on the Generated Geometry sample

The sample code uses a tiled texture for the terrain surfaces, so unless you replace “rocks.bmp” with a more fitting texture, your landscape scene might look a bit out of place.

Skybox Script for Terragen

Copy the following script into Notepad and save as “SkyboxScript.tgs”. Execute this script in the above steps. The below script will generate 4 images in your C:temp directory by changing the camera orientation to the same parameters as listed in the table above. The frend (frame render) command renders the image and saves to your temp folder. The images will be named skydome0001, skydome0002, skydome0003, and skydome0004. So just stitch them together in the same order.

initanim "C:tempskydome", 1 

Zoom 1.0
CamH 0
CamP 0
CamB 0

Zoom 1.0
CamH 90
CamP 0
CamB 0

Zoom 1.0
CamH 180
CamP 0
CamB 0

Zoom 1.0
CamH 270
CamP 0
CamB 0

Update 1 (3/4/2008): Some of my friends remarked that this post was useless without pics. With 3G of upload space remaining here, I might as well upload a few.

Scene example – generated from Terragen, default parameters
Terragen Scene Render

Heightmap example – generated from Terragen, default parameters
Terragen Heightmap Example

Skydome image example – generated from Terragen, default parameters using script above
Terragen Skydome Landscape render

Democratizing Game Development

Google AdSense

I’ve long been a fan of games and game development. I created my first game over 20 years ago and saved it to a cassette (remember those things we used to have in cars before CDs?) on my Coleco Adam computer.

I also remember creating numerous text driven games for my Apple IIc Plus using Applesoft BASIC and saving them to my 5 1/4 inch floppy disks. A few months ago, I found my first game development book (for SmartBASIC) and a stack of 5 1/4 inch floppy disks in my parents basement…

Well, that was a long time ago. Today, there’s lots of great gaming libraries and 3D engines for the PC. I experimented with a few of these using C++, but I’ve rarely finished any of games before I got distracted on another project or something else came up.

A few years ago, Microsoft released the XNA framework for Visual Studio. This framework allowed developers to make games compatible with both PCs (Microsoft operating systems) and XBOX 360s. I participated in the version beta prior to it’s release and I’ve worked with the 1.x and 2.x versions, but I still haven’t finished any games so far.

I’m still pretty excited about the XNA framework and it’s impact on the programming industry.  I’ve thought this was great for Microsoft since I heard the first rumors. I believe the XNA framework will bring young developers into the .NET world and even though very, very few will get into the game industry, they will take their .NET skills into the marketplace. Some colleges have even designed programming courses around the XNA framework.

At the Game Developers Conference this week, Microsoft announced their plans for the next version of XNA.  Version 3 will include “XBOX Live Community Games“. They also announced support for game development on the Zune, which I think is a good direction also.

This provides developers the ability to upload their games to a community site where peers can download and review your games. If your game passes the peer reviews, then it will become available to all XBOX owners to download and play.

TalkingAboutGames provides a little more details stating:

Gamers will be able to rate user-created XBLA titles through XNA Creators Club once the service goes live… Once a game is submitted, it goes through a peer review process (which eliminates copyrighted material and/or prohibited content), and if it passes, it’s made available for download over Creators Club, which will be located on the Xbox Live dashboard. If that’s not enough, XNA games can now be played on your Zune as well.

Gamasutra has a lengthy article titled, “Democratizing Game Distribution“. The article provides general instructions on the game submission process. The submission form will contain options for the developer to rate violence, sex, and mature content on a scale of 0 to 5, upload screenshots and movie trailers, and upload the game package (.ccgame file).  Next, fellow XNA Creator Club members can submit reviews and game defects (bugs) for the game. Once enough positive reviews have been submitted, XBOX users can download the game via the XNA Game Launcher.

There is a special preview of this ability available until mid-March. You can download the XNA games of The Dishwasher: Dead Samurai, JellyCar, Little Gamers, Proximity HD, Rocketball, TriLinea, and Culture.

Maybe it’s about time that I get back to work on my own game!

Reinstalling Internet Information Server (IIS)

Yesterday, I installed the required automatic updates from Microsoft and rebooted my work laptop and rebooted. When I started work this morning, I noticed that my Visual Studio projects weren’t loading the web site projects.

Upon further investigation, I found that IIS Admin service wasn’t running and would not start. The error provided by the service was “The IIS Admin service terminated with service-specific error 2147549183 (0x8000FFFF).”

When I clicked on Internet Information Service (via the Management Console), it would prompt me with a dialog stating “The username/password you used to connect to this machine does not have administrator privileges, or you entered an incorrect password.”

My account was in the local administrators group, but when I entered my username and password, I was greeted with a message of “You have been denied access to this machine.” (Sounds scary, huh?)

In addition, a DCOM error of “The service cannot be started, either because it is disabled or because it has no enabled devices associated with it. ‘ attempting to start the service IISADMIN with arguments ” in order to run the server:” is logged in the System Event Viewer.

Collecting Service Status Error Message

Specific error information about the service can be found using the “sc” command. The “sc” command is used to interact with the NT Service Controller. Using this command, you can also stop and start services. The query argument will return service status and hopefully the reason why it couldn’t be started.

C:>sc query IISAdmin
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 1 STOPPED
        WIN32_EXIT_CODE    : 1066       (0x42a)
        SERVICE_EXIT_CODE  : -2147418113        (0x8000ffff)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

After spending about an hour trying everything to avoid re-installing IIS, I found a few Microsoft knowledge base articles relating to this error code. However, none of these articles seemed to help or make any difference. I was still unable to start IIS.

Uninstalling IIS

  1. Go to the Control Panel->Add or Remove Programs->Add/Remove Windows Components
  2. Unchecked “Internet Information Server (IIS)”
  3. Click “Next”

Installing IIS

  1. Go to the Control Panel->Add or Remove Programs->Add/Remove Windows Components
  2. Checked “Internet Information Server (IIS)”
  3. Click “Next”

Installing ASP.NET version 2.0

  1. Open command prompt
  2. Browse to “%WINDOWS%Microsoft.NETFrameworkv2.0.50727” directory
  3. Enter the command “aspnet_regiis -i”


This seemed to have fix my problem and the “IIS Admin” and “World Wide Web Publishing” services were started. I lost all of my IIS configurations such as virtual directories, web sites, etc. And I needed to re-install ASP.NET 2.0.


As soon as I re-installed IIS, 3 more Microsoft automatic updates were downloaded and waiting for me to install: KB939373, KB942830, KB942831. I took the chance and installed these updates, rebooted, and everything seems to be working after the updates.

Update 1 (the next morning): After a reboot, IIS could not be started again. Same problems as above. Re-installed IIS for second time. I’m thinking that MS08-006 is causing the problem, more details to come as I try to get this working.

Update 2 (the next morning 2): I rebooted after uninstalling some software and IIS refused to start up again. The service was once again disabled and it appears that I need to re-install IIS again.

Update 3 (2 years later): I think I found a fix for it. By changing the “Remote Procedure Call (RPC)” Windows service account from “NT Authority/Network Service” to log on as “Local System Account”. After a reboot, my IIS finally works.



As a ASP.NET programmer, I’ve visited many times since it’s launch in November 2000. The site has gone through some problems and a couple facelifts since then and now it has officially been closed. It was the first ASP.NET community web site and my first ASP.NET reference web site.

There are other great ASP.NET web sites including:

I never understood why Microsoft develops so many web sites that are so similar in nature (providing code samples, documentation, user uploaded controls, forums, etc.).

I’d love to see a single .NET portal that includes ASP.NET (which I like a little better than, .NET 3.0 web sites (,,, etc.), and the other framework web sites.

[Via Betsy Aoki’s WebLog]

My Related Posts: , ,

XBOX 360 DRM issues

So far, I haven’t needed to return my XBOX 360, but with the high failure rate, I expect that I’ll probably be shipping it back sometime this year. With the new announcement of the Mass Effect downloadable content (DLC), I’ll be purchasing some DRM (digital rights management) XBOX 360 content for the first time.

Unfortunately, BioWare isn’t planning on releasing the content on CD at storefront or from their own online store. This means that when my XBOX gets the “red rings of death” (RRoD), I’ll be stuck with the DRM glitch.

I’m a new owner of the XBOX, so I first learned about the problem while reading the Official XBOX Magazine’s article titled “Six Resolutions for Microsoft in 2008.”

If your console breaks … the digital-rights management doesn’t detach from the old hardware, and it doesn’t know how to mate with the new machine. The only way to play the XBLA games you’ve bought, then, is to be logged in. That’s a problem for any users who don’t have a home network, who find themselves stuck with trial versions of the games they “own” until Mom’s done surfing the internet on the PC and surrenders the Ethernet cable.

It’s also a pain in the ass for two-gamertag households. Consider this very common scenario: Gamer A and Gamer B live together. (They might even be married — the ultimate multiplayer experience!) Gamer A bought Puzzle Quest, knowing Gamer B would love it — and she did. So they each played independently, until the three red lights showed up. After the console came back from Microsoft’s repair lab, suddenly, Gamer B couldn’t play Puzzle Quest — or any of the games Gamer A bought on his account. Part of the “fix” was to (accidentally? intentionally?) lock out anyone but the purchaser.

I was asking a couple questions on some of the XBOX related forums about this and then a few hours later, I noticed that Jeff Atwood of Coding horror wrote a nice write up explaining that DRM ignorance is expensive.

I foolishly assumed all along that it would be no big deal to transfer that purchased content if I ever purchased an Xbox 360 for my home.

Big mistake.

I didn’t realize how precarious my understanding was of Xbox 360 digital rights management was.

Jeff’s big mistake ended up costing him about $140 to repurchase all of his content for a second time. Jeff proposes a couple solutions and I really like the method that iTunes uses to manage DRM content where a limited number of machines are registered through your profile to access the content.  Hopefully, Microsoft will come out with a solution this year.

My Related Posts: , , ,