OpenGL help

Soldato
Joined
22 Oct 2005
Posts
2,883
Location
Moving...
Hi guys, just started learning some OpenGL and GLUT in C. I want to recreate something similar to google earth but instead of using photo images i'm just goin to use terrain data which i've got. So basically I want to make the world lumpy!

What would be the best way to go about this using OpenGL? The data I have is basically the longitude and latitude of a point, then the height above sea level at this point. I'm guessing I would need to create a sphere to represent the Earth then put some kind of wireframe model over the surface to detail the terrain, then just add some colour? Is there any specific functions that would be useful/I should avoid?

Thanks.
 
GLUT has some functions to create basic shapes such as a sphere, but I think you're probably better off finding an algorithm to create the vertex data for a sphere yourself. That way you can more easily manipulate individual vertices to plot the altitude.
 
Yup. Implement your own sphere subdivision algorithm (google search for the method) and then simply normalize the length of the vector to each vertex to equal the height you want at that point.
 
Yup. Implement your own sphere subdivision algorithm (google search for the method) and then simply normalize the length of the vector to each vertex to equal the height you want at that point.
I've had a look but all I can find about sphere subdivision algorithms is to do with making the sphere more rounded, i.e. turning an icosahedron into a more spherical looking object by subdividing the triangles which make up the surface???

I understand what you're saying but I'm not sure how I would go about coding the solution.
 
I've had a look but all I can find about sphere subdivision algorithms is to do with making the sphere more rounded, i.e. turning an icosahedron into a more spherical looking object by subdividing the triangles which make up the surface???

I understand what you're saying but I'm not sure how I would go about coding the solution.

Sphere subdivision is how you make a sphere, starting from a basic shape as you say. You don't just magically draw a sphere you know!

So:
1. Implement a sphere subdivision algorithm to get all the triangles you need to make a sphere with the desired accuracy.
2. Change the distance each vertex is from the center of the circle to set the height to what you want.
3. Draw the adjusted triangles.

Its not really that hard. You should probably do some more reading (i.e. try harder).
 
I'm sure a good algorithm for making a sphere is documented somewhere. Try wikipedia, that's normally a good starting place.
 
You can do it one of two ways :

Geodesic subdivision (start with something like an Icosahedron and subdivide each triangle, specifying that the new points' distance to the centre be specificed by referencing somehow into your image.

Polar co-ordinates based, basically you are going to rotate a vector around the x and y axis, to produce your new vector, length of the vector specified by referencing the image (easier because you can use u,v co-ordinates of your image to correspond to the rotations of each axis).
 
Is a "flat" earth an option? You could use SRTM data and just render a regular heightfield. The .hgt file format is quite simple. Much easier to visualize and implement than a sphere.
 
Thanks for all the replies guys.
Is a "flat" earth an option? You could use SRTM data and just render a regular heightfield. The .hgt file format is quite simple. Much easier to visualize and implement than a sphere.
I think this may be a more viable solution for me, I've been doing some research and the performance problems I would encounter trying to render the whole globe at once would be a big problem. So i think i'm gonna go with the more traditional view (i.e. a few countries in view at the same time) and focus more on accuracy and a nice camera engine for a nice degree of freedom for the user.

On a side note, what are the limitations on the sizes of the arrays that can be used in C/openGL, either physical restrictions, or a size that would be too large to run in an 'acceptable' timeframe if you know what I mean?
 
Thanks for all the replies guys.

I think this may be a more viable solution for me, I've been doing some research and the performance problems I would encounter trying to render the whole globe at once would be a big problem. So i think i'm gonna go with the more traditional view (i.e. a few countries in view at the same time) and focus more on accuracy and a nice camera engine for a nice degree of freedom for the user.
What you should do is have a variable "resolution" on the sphere. For example if you are zoomed quite far out you could plot the average altitude for a large group of data points rather than each one individually. Then when you zoom in, you just render that local area. As you zoom in you get closer and closer to representing each data point one to one as a vertex on the sphere.
 
On a side note, what are the limitations on the sizes of the arrays that can be used in C...

there are no limitations on array size in the C language itself.
you are of course limited by the amount of memory you have available in the system (physical + virtual - already in use amount)

you may want to read over some "data structures and algorithms" stuff to help you in this regard.
 
Thanks for all the replies guys.

I think this may be a more viable solution for me, I've been doing some research and the performance problems I would encounter trying to render the whole globe at once would be a big problem. So i think i'm gonna go with the more traditional view (i.e. a few countries in view at the same time) and focus more on accuracy and a nice camera engine for a nice degree of freedom for the user.

On a side note, what are the limitations on the sizes of the arrays that can be used in C/openGL, either physical restrictions, or a size that would be too large to run in an 'acceptable' timeframe if you know what I mean?

I cant believe that in a final year project (I believe this is what you are doing?) you are just giving up on something without even trying it. Have you actually tried drawing a sphere yet? Modern graphics cards can draw millions of polygons a second - its not going to be a performance issue if its coded even semi-sensibly :(.

If you get even an average mark for drawing a flat map with bumps on it, then to be honest, your degree wont be worth the paper its written on. Consider this a kick up the backside. lol.

p.s. If you want to know the performance, just write a program and test it! Its not hard to write a program to draw a million polygons or something and then see what framerate you get is it?
 
Last edited:
Back
Top Bottom