opengl -- displaying contours on 3D terrain.

hi all…

i have some terrain that i have drawn using triangle strips and now i need to plot 2D contours onto the surface. i have discovered something called marching cubes but it is hard to understand(the very few examples that i have found) and most of them are old and seem to be outdated. is there another way to plot 2D contours? i already have my terrain colormapped, a deep blue to a light blue with light blue representing the highest points of the terrain and the deep blue the lowest points. where do i (should i) go from here? thanks all in advance for your help…

What are 2d contours?

(Since this is the advanced forum, I’m assuming you’re not just asking about the basic contours explained in the red book.)

this image is what i would like to do. my terrain is 3D and i guess my contours would be 3D too… sorry for the confusion – thanks for your patience…

Is your problem about computing or rendering these contours ?
Answer #1 -> this is not opengl related so you’re not in the right place ot ask
Answer #2 -> well … use GL_LINES mode


Oops, I guess you had it right. I just assumed the contours were were called 1d contours since they only depend on one variable - the height of the terrain.

One way to do this is to set up texcoord generation for a 1d texture, with the texcoord dependent only on z. Then you create a 1d texture that holds a view of your contour line (eg-an empty texture except for a thin band at one end), and map it to your terrain with texcoord wrapping enabled so you don’t get just the first contour above z=0.

You mentioned you’re coloring the terrain based on its height. This method is probably the fastest way to do that, too. Just use your color gradient as the 1d texture.

If this doesn’t make much sense, search for “creating contours” here (chapter 9 of the red book).

I would think that using a 1D texture and setting the texcoords for each vertex according to the altitude of the terrain would do exactly what you want - but that seems too much like a basic solution to me.

use a 1d texture and then use auto texture generation to generate the coordinates based on the height
most recent photo i stuck up is what i assume what u want, im using a shader here but the effect can be easily achieved with like i said auto texture generation