Advertisement

Terrain rendering question

Started by July 25, 2000 08:48 AM
13 comments, last by dinotrack 24 years, 3 months ago
Hi, its me again.

Well, I drew the terrain as GL_POINTS. It looked okay, a grid of points at different elevations, corresponding to the heightmap.

However, I would like to draw the terrain as a solid mesh now.

I tried drawing it as triangles, triangle strip, polygon, quads, quad strip.

But they all look pretty much the same, terrible. They are just rows, not even half-connected, with holes in them, and floating in mid air all over the place.

I don''t know how to draw them as a solid mesh of triangles, or whatever.

Any ideas?
        for (int x = 0; x < 255; x++){	for (int z = 0; z < 255; z++)	{		SetVertex(V1,    x*5, height_map[x  ][z  ],   z*5);		SetVertex(V2,  x*5+5, height_map[x+1][z  ],   z*5);		SetVertex(V3,  x*5+5, height_map[x+1][z+1], z*5+5);		SetVertex(V4,    x*5, height_map[x  ][z+1], z*5+5);		WorldToCamera(V1, Camera);		WorldToCamera(V2, Camera);		WorldToCamera(V3, Camera);		WorldToCamera(V4, Camera);		ProjectPoint(V1);		ProjectPoint(V2);		ProjectPoint(V3);		ProjectPoint(V4);		color = RGB(height_map[x][z], height_map[x][z], height_map[x][z]);		DrawTriangle(hDC, V1, V2, V4, color);		DrawTriangle(hDC, V2, V3, V4, color);	}}        


That's how you do it.. you basically connect two points from the height_map....

and make a triangle out of it...

-------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..

Edited by - Gladiator on July 26, 2000 11:03:19 AM
Advertisement
Hey,

Glad that snippet of code helped.. Reminds me of the days when you had to reference the screen 320x240 by doing a 320*x + y..

Anyway, back to the point.. It's funny you're asking these questions because I just got my targa loader to work ( right anyway.. ) the other day and I'll be headed in this direction as soon as I get off my lazy ass..

As far as drawing the terrain as simple quads, have you checked out tutorial 11? I know it may not be obvious, but in fact it's very applicable in the way I draw the grid.. It's a 45x45 instead of 256x256 but it's relatively the same concept.

As far as drawing triangles and/or triangle strips, I don't have a lot of experience, but let me throw one idea at you.

Once you can draw the array as quads, the step to triangle strips shouldn't be a great one. The following is prone to errors as I've never done it, but I believe it's correct. Triangle strips are drawn with the first three vertices being the first triangle and then every point after that making a triangle. N-2 triangles are drawn.

                1------------3-------------5|            |             ||            |             ||            |             ||            |             |2------------4-------------6So imagine this as two quads side by side. You would do this in psuedocode OpenGL code.glBegin( GL_TRIANGLE_STRIP );   Vertex( 1 );   Vertex( 2 );   Vertex( 3 );   Vertex( 4 );   Vertex( 5 );   Vertex( 6 );glEnd();                


Of course, what you want to remember now, is that the code I gave earlier for sorting your array was simply for rows and columns. What you may have noticed from this post is that you may want to either have a seperate array or sort the one you have now so it's advantageous for drawing this way.. In other words ordered so you can feed a glBegin( GL_TRIANGLE_STRIP ) with vertices in order of your array (i.e. MyArray[0..1..2..3] instead of coming up with some unique reference scheme each time.. Alternately you could write all this as a class ( are you?? ) and have handler functions..

Whew.. hope this is all right.. Written from the sleeve of my shirt so who knows.. But, send me an email if you want more help or post here..


bosco()


--
leader of the free world .. or something ..

Edited by - bosco on July 26, 2000 10:44:20 AM

Edited by - bosco on July 26, 2000 10:45:13 AM
--leader of the free world .. or something ..
i wouldnt draw a landscape with quads use triangles. quads give u nasty things when a polygon is clipped with the normals.

but if u wanna use quads try this

        for (x=0;x<WORLDSIZE;x++)	{	for (y=0;y<WORLDSIZE;y++)		{	glBindTexture(GL_TEXTURE_2D, mapSquare[x][y].terrain_texture);								glBegin(GL_QUADS);				glNormal3fv(mapSquare[x][y].normal);		glTexCoord2f (0, 1);	glVertex3f(x*SQUARESIZE		,mapSquare[x][y].height		, y*SQUARESIZE);				glNormal3fv(mapSquare[x][y+1].normal);		glTexCoord2f (1, 1);	glVertex3f(x*SQUARESIZE		,mapSquare[x][y+1].height	, (y+1)*SQUARESIZE);				glNormal3fv(mapSquare[x+1][y+1].normal);	glTexCoord2f (1, 0);	glVertex3f((x+1)*SQUARESIZE	,mapSquare[x+1][y+1].height	, (y+1)*SQUARESIZE);				glNormal3fv(mapSquare[x+1][y].normal);		glTexCoord2f (0, 0);	glVertex3f((x+1)*SQUARESIZE	,mapSquare[x+1][y].height	, y*SQUARESIZE);			glEnd();		}	}        


mapSquare[x+1][y] == mapSquare[x<<8+1+y]

Edited by - zedzeek on July 26, 2000 6:19:00 PM
Thanks everyone for your help. I finally got it working!

I used triangle strips for drawing the terrain.

Now I guess I better implement some texture mapping and LOD.

See ya,
Jonathan



This topic is closed to new replies.

Advertisement