Skip to main content
GameDev.net gamedev.net
🔒 Locked

help for creating a 3D landscape like this one (OpenGL+Java)

Started by Nico_gamedev Dec 7, 2012 at 10:15 PM 6 replies 4.4k views
Original Post
Nico_gamedev
Nico_gamedev
Hi,
I'm an average Java coder, and now I want to learn OpenGL (in Java) to make a landscape like the one shown in the picture below (it's a Linux screensaver).

Actually, the color stuff is not what I'm interested in: what I would like to achieve is just the wireframe view of such a landscape (pretty basic thing in OpenGL, I imagine...)

So Big, Big, Big Thank You for providing me any piece of advice (or code) you have about what I should do in order to create a wireframe landscape!!!!!!!

PS: if your tips, lines of code or weblinks deal with C/C++/C#, no problem, I'll figure out how to make it work in Java, so feel free to post any piece of help (because I'm really starting from scratch on this one, and I really want to code it!). Thank you very much!

landscape.gif
fastcall22
fastcall22
EDIT:
I'm thinking of software rendering...
Jake S. C++
Jake S. C++
Do you want to load just a basic mesh and display it or do you want to do something cool and construct it from a heightmap or something? How are you using opengl in java is it JOGL or lwjgl or something else? If your using the heightmap way what you want to do is load a grayscale image in a way that you can address each pixel and ill give you some psuedocode:


int vertindex;
for(int x = 0; x < image.w; x++)
{
for(int y = 0; y < image.h; y++)
{
vertices[vertindex*3] = x; //vertex x-coordinate
vertices[1 + vertindex*3] = y; //vertex y-coordinate
vertices[2 + vertindex*3] = image.pixels[x][y]; //vertex z-coordinate
vertindex += 1;
}
}
glEnableClientState(GL_VERTEX_ARRAY);
unsigned int vBuffer;
glGenBuffers(1, &vBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
glBufferData(GL_ARRAY_BUFFER, vertindex * 3 * sizeof(float), vertices, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_LINES, 0, vertindex);


That's basically how you do it in psuedomodern opengl.

Legacy opengl is a bit easier but is reeeeaaaaly slow:


int vertindex;
glBegin(GL_LINES);

for(int x = 0; x < image.w; x++)
{
for(int y = 0; y < image.h; y++)
{
glVertex3f(x, y, image.pixels[x][y]);
}
}
glEnd();


attached is a sample heightmap
Nico_gamedev
Nico_gamedev
Thank you for your replies: it's much appreciated!

Actually, I thought about pure random/procedural generation (I'm fond of these things) for creating the landscape (so generating a heightmap is an actual option, yes).
The ultimate step would be to be able to generate an infinite terrain (and "fly" over it).

And for using OpenGL with Java, I haven't decided yet between JOGL or lwjgl (I'm looking for something that works in Android)

Thank you for your help!
larspensjo
larspensjo
For automatic generation of height data, have a look at simplex noise (similar to Perlin noise). In the "External Links" section to Stefan Gustavsson (http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf) , you will find another reference to a Java implementation of this.

You would use 2D simplex noise (using X and Y as argument) for height map generation. To get really interesting things, you can use 3D simplex noise for density. The density can be used for many things: Creating caves, used as a probability for vegetation, etc.
BraXi
BraXi
NeHe wrote nice tutorial about creating terrain from height maps, which was later ported to Java, you should probably read this:
http://nehe.gamedev.net/tutorial/beautiful_landscapes_by_means_of_height_mapping/16006/
Nico_gamedev
Nico_gamedev
Thank you for the link. I'll definitively look at it!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.