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…
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!
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);
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.
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!
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!!
>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… =)
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 ???