Terrian With OpenGL

Started by
10 comments, last by HellCreator 19 years, 3 months ago
I know this may have been talked about but the search is not working right now so i will ask this questions anyways. I need to find as much resource on how to render terrainwith OpenGL. i like to fins indpeth content about doing it with heightmaps or any other method there is. thanks for the info.
Advertisement
Try these sites, they have complete tutorials on terrain rendering.

http://www.gametutorials.com
http://nehe.gamedev.net
Author Freeworld3Dhttp://www.freeworld3d.org
The various methods for storing, generating, and maintaining a terrain are really nothing to do with OpenGL. The particular graphic API is probably the smallest part of the project and is the simplest part. Terrain rendering is 99% about the techniques you chose to generate and maintain the terrain than actually rendering it. In my current simple project I over 50 separate routines, and only two actually have OpenGL calls in them (3 including the skybox). There are plenty of resources on the web for this. If gamedev search is down, then go directly to Google.

By far the simplest approach to start with is a heightmap stored in some form of 1D or 2D array and generate the heightmap by either loading an image and generating the various height values from that, or load a file of raw height data. Once you have the data in the array, it's a relatively simple brute-force routine to render the heightmap with OpenGL calls. Some other relatively simple methods for generating dynamic terrains are fault, plasma, noise, and hill algorithms - all can be found via google. Once you have your heightmap generated and rendered, then you can look at the various texturing methods, and advanced methods of rendering the heightmap, like ROAM or CLOD for maintaining it. Again, Google is your friend :)

Start with these:
NeHe
Game Tutorials

And of course, the Virtual Terrain Project has a lot of info - but it gets advanced almost straight away.

hth
F451

[edit] : Doh! the faster Sean got there with the same links :)

[Edited by - Fahrenheit451 on January 16, 2005 7:02:01 PM]
what zones like it WOW and Everquest or is that something that has to do with MMORPGS only?
well i was looking at the gametutorials site but looking at there free tuts, like the oct 3all they give you is source code, and if i am going to pay for somthing it might be nice get a bit of explanation on it.
Oh yeah. Looks like the GameTutorials site has changed considerably (fixed my [now] broken link). The OpenGL tutorials are all still there though and are still free. They contain well commented source code, so you do get an explanation of what is being done.
I loved this article:
here
______________________________________________________________________________________With the flesh of a cow.
Quote:Original post by Ainokea
I loved this article:
here


Indeed. That particular method is the main routine in my current little coding project. The island mode is unbeatable.

Hey guys, I'm trying to get the hill algorithim to work (I'm pretty much finishing up Beginning OpenGL Game Programming, so I hope I have enough knowledge to try and get this to work. However, I just get a black screen. Anyone know whats wrong with this?

glPushMatrix();	glColor3f(1.0, 0.0, 0.0);	for(int x = 0; x < terrain.GetSize(); ++x)	{		glBegin(GL_TRIANGLE_STRIP);		for(int z = 0; z < terrain.GetSize(); ++z)		{			float y = terrain.GetCell(x, z);			glVertex3f(x, y, z);		}		glEnd();	}glPopMatrix();


Any help is appreciated.

-Limb
-Limb
With what you've posted it wouldn't be clear as to whether the problem is in the render routine, or the actual hill generation routine. Your mesh render loop does look incorrect though. You need at least two glVertex3f calls in there for a triangle strip. The first should the current vertex [x][z], and the second should be [x+1][z]. Your x outer loop would therefore run from 0 to terrain.size-1. eg. In the mesh below the x loop would run from 0 to 1, and the z loop from 0 to 2. Each iteration would make two glVertex3f calls. Iteration one would be a and d, iteration 2 would be b and e, iteration three would be c and f, iteration 4 : d and g, iteration 5 : e and h, and finally f and i. That forms the triangle strip properly.

       -z-     0  1  2   0 a--b--c     | /| /| |   |/ |/ | x 1 d--e--f |   | /| /|     |/ |/ |   2 g--h--i


With your loop it would be as follows:

float y = 0.0f;glPushMatrix();	glColor3f(1.0, 0.0, 0.0);	for(int x = 0; x < terrain.GetSize()-1; x++)	{		glBegin(GL_TRIANGLE_STRIP);		for(int z = 0; z < terrain.GetSize(); z++)		{			y = terrain.GetCell(x, z);			glVertex3f(x, y, z);			y = terrain.GetCell(x+1, z);			glVertex3f(x+1, y, z);		}		glEnd();	}glPopMatrix();


Give it a try and let us know if it doesn't work. The other problem might be in the jill routine, but then you should still get a flat mesh if you initialise all heights to zero at the start.

hth
F451

This topic is closed to new replies.

Advertisement