
Terrain Heightmapping
Posted Friday, 9 January, 2009 - 19:38 by flopoloco inA simple example on how to do simple heightmapping with OpenTK, enjoy...

| Attachment | Size |
|---|---|
| OpenTKHeightmap.png | 61.08 KB |
| OpenTKTutorials.rar | 470.36 KB |

A simple example on how to do simple heightmapping with OpenTK, enjoy...

| Attachment | Size |
|---|---|
| OpenTKHeightmap.png | 61.08 KB |
| OpenTKTutorials.rar | 470.36 KB |
Comments
Re: Terrain Heightmapping
Hoho! Nice.
Re: Terrain Heightmapping
Thanks, preety speedy also if you noticed :P
Re: Terrain Heightmapping
How do you pick the Color for each Quad? Or what kind of primitives is it?
Re: Terrain Heightmapping
I have loaded all the pixels of the height map in a 2D array (512x512), I use these rgb values (of the image file) for two purposes, (first) getting the height and (second) the color value for each specific rendering step. Points are very easy to render with in a rendering loop, you simply add a GLVertex in it and you are OK. The tricky part on the other hand for rendering Quads and Lines successully, is that you will have to advance a step in order to form the slopes correctly. By meaning that will have to do 2 or 4 GLVertex calls in one loop, that's why you will have to advance the array indices.
For instance, let's say: I currently am in the 16th index of the array, I use a step of 8 and I want to draw a line. Then I do this.
GL.Begin(BeginMode.Lines);
GL.Vertex2(x, y); // current location
GL.Vertex2(x+step, y+step); // get values of the the next step.
GL.End();
Same goes for quads...
I hope I explain this properly (I am not much experienced).
Re: Terrain Heightmapping
So is it quads, triangles or something else..?
Re: Terrain Heightmapping
Heh, pick the code and see ;)
btw i read somewhere that triangels are faster than quads but triangle lists are faster..one of my terrain renderer uses triangle lists and it uses lod.. i think vbo is even faster.
Re: Terrain Heightmapping
The screenshot has quads :), this example however is not considered good for real time rendering... it definitely needs optimizations (like lod, and culling)...
Re: Terrain Heightmapping
Hi,
I have this error
Error 2 No overload for 'TutorialTerrain_ButtonDown' matches delegate 'System.EventHandler' c:\users\ruba\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\TutorialTerrain.cs 83 29 WindowsFormsApplication2
Error 1 No overload for 'TutorialTerrain_KeyUp' matches delegate 'System.EventHandler' c:\users\ruba\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\TutorialTerrain.cs 82 36 WindowsFormsApplication2
and when I tried to run the .exe file, I got a blank blue window :(
Please help me
thanks a lot.
Re: Terrain Heightmapping
Hi there ruba, I have updated the code. OpenTK API has changed a bit since I created this example, I did not expect it to "break" :D
I can't edit the uploaded files in the initial post, use the text above instead. Works fine with OpenTK1.0!
TutorialTerrain.cs
P.S.
Re: Terrain Heightmapping
I do not mean to be a stick in the mud here, but I just have to know.. because this part is a bit confusing. I got the original code in your RAR file to work. Pretty easily actually. ( I just reset the paths to the two OpenTK files you supplied with the code. ) But I look and I see GL and GLU commands in there.
Then I look at the above code you have here, and I see that you replaced the GLU commands with Matrix4 commands.
Can you explain to me why the change or what the difference is ? So I am not sure what got "Corrected".
Keep in mind, I am not a C# noob, but I am an OpenGL noob. So GLU and GL is still new to me. I have used Matrix4 in other languages.
EDIT : Is it that these three are replacing the GLU commands ?
using OpenTK.Graphics.OpenGL;
using OpenTK.Graphics;
using OpenTK.Input;
Am I to assume that GLU is an older library and OpenTK has replaced it ?