A terrain patch

Hi there…

i’m in trouble here, i’ve been trying and trying to draw a terrain or surface(whatever). But i dont know how. have to put in matrix ???
how can i do that ???
Somebody can give me a short and bull’s eye explanation about ??
I ll really appreciate…

thanks a lot !!!

One way is to store your terrain data in a heightmap array - say terrain[x,z], and then step through this drawing each quad (to start with, triangle strips are better) one by one. eg.

glBegin(GL_QUADS)
for (x=0;x<max_x;x++)
{
for (z=0;z<max_z;z++)
{
glVertex3f(x,terrain[x,z],z);
glVertex3f(x+1,terrain[x+1,z],z);
glVertex3f(x,terrain[x,z+1],z+1);
glVertex3f(x+1,terrain[x+1,z+1],z+1);
}
}
glEnd();

This is only basic of course! You’ll still have to include texture co-ords and normals, not to mention only drawing the quads or tri’s that are within your field of vision… But I hope that helps to get you started!

  • Phrantik

yeah Phrantik…
but i have to a put some values in terrain array.

and what kind of values ??? more than 1 ???
less than 1 ???

and i get a lot tri’s on the surface, how can i make it homogeneous…

sorry the many question, man…

thnx

Well, I usually use a greyscale bitmap to represent my terrains - that is, values between 0 and 255. You can use any values however, and then use glScale to adjust it.
The example I gave (using quads) should give you a continuous surface, but if you use Triangles, you’re right, it will have holes all over the place! Off the top of my head try this for TRIANGLE_STRIP terrain…

glBegin(GL_TRIANGLE_STRIP);

  • x loop -
  • z loop -
    glVertex3f(x,terrain[x,z],z);
    glVertex3f(x,terrain[x,z+1],z+1);
    glVertex3f(x+1,terrain[x+1,z],z);
    glVertex3f(x+1,terrain[x+1,z+1],z+1);
  • end z loop -
  • end x loop -
    glEnd();

Hope this helps! =)

  • Phrantik

Sorry… i f@#$'d up!

The glBegin should go between the x loop and the z loop and the glEnd between the end of the x loop and the end of the z. This way you get long strips of triangles running in the z direction.

  • Phrantik

Geee…
you’re right !!!
Thanks for attention.

But man, i have another question:
I usually work with Delphi5. and i dont wanna jump to C. i mean, i know a bit of C and like Delphi a lot.
Is Delphi a good opengl plattaform ???
can i continue with delphi and write a nice engine ???

Personally, I much prefer Delphi 5! It’s what I used to code my engine, and even though it’s still in early development, it’s getting there!! I’ve heard that C++ executes OpenGL faster than Delphi, which I have no doubt is true, but it’s never made me want to switch. The point is, you can write a great engine in ANY language, you’re still using OpenGL - which is a great API. The speed may not be as fast as commercial engines, but you have to work out what matters most to you - a few less frames per second or a finished engine!

  • Phrantik

Yeah…

So, can you provide me some piece of your code, man ?
Just to take a look, make some step by step…

I ll not copy anything, just to get a look how you draw each object every frame.
I ll really appreciate that.

Thanks…

Sure… give me your email address and i’ll send you the terrain rendering code… I’ll warn you though, don’t expect to find much if you havn’t understood the code I posted above, it’s basically the same thing!!

  • Phrantik

Thanks Phrantik…
my mail is guivieira@brfree.com.br

if it’s possible send another topic codes that you consider its hard to understood.
)

anyway thanks…
[]'s

>if it’s possible send another topic codes >that you consider its hard to understood.

Don’t forget that 3D programming, as a whole, is hard to understand! I think that looking over others people’s source is important, sure. But nowhere near as important as writing your own, making mistakes, and then slowly learning enough from documentation to fix them. It’s a long process… after all, my limited knowledge came from working through Nehe’s tuts and then reading the redbook about 50 times! I’m sure you can understand that I get a little frustrated when people expect to learn everything staright away without putting in the hard work… OK, i’ve had my winge… =)

  • Phrantik

SURE !!!
I think as you think. When i said to send me others topics thats because i’m tired of reading and reading the same docs as you.
i’ve been proggraming on a four or five years ago and the way that i learned: hard work, alone, nights and nights but i always reached there. And opengl isn’t goind in the same way. So the last alternative are asking for others codes. Just to put my mind in movement, understand me ???

anyway again, thanks for your attention

Thanks Phrantik for the code sample.
I still don’t have time to try it.
but i ll test it as fast i could.

[]'s

[This message has been edited by Gelero (edited 06-28-2000).]

you are using delphi as me guys )
i have coded all of libraries i want to code but i can’t do collision detection because i have no think )

Hým i want to find the object which hits the others and object with being hit , hýmmm?

thanks