Jump to content
  • Advertisement
Sign in to follow this  
Nico_gamedev

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

This topic is 2045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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 Edited by ic0de

Share this post


Link to post
Share on other sites
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! Edited by Nico_gamedev

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!