Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Nico_gamedev   Members   -  Reputation: 109

Like
0Likes
Like

Posted 07 December 2012 - 04:15 PM

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!

Posted Image

Sponsor:

#2 fastcall22   Crossbones+   -  Reputation: 2978

Like
0Likes
Like

Posted 07 December 2012 - 04:47 PM

EDIT:
I'm thinking of software rendering...

Edited by fastcall22, 07 December 2012 - 04:49 PM.


#3 ic0de   Members   -  Reputation: 798

Like
1Likes
Like

Posted 07 December 2012 - 05:16 PM

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

Attached Thumbnails

  • perlin.png

Edited by ic0de, 07 December 2012 - 05:31 PM.

you know you program too much when you start ending sentences with semicolons;


#4 Nico_gamedev   Members   -  Reputation: 109

Like
0Likes
Like

Posted 07 December 2012 - 05:42 PM

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, 07 December 2012 - 05:44 PM.


#5 larspensjo   Members   -  Reputation: 1525

Like
0Likes
Like

Posted 08 December 2012 - 03:14 AM

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.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#6 Nico_gamedev   Members   -  Reputation: 109

Like
0Likes
Like

Posted 08 December 2012 - 04:39 AM

Thank you for the links :)

#7 BraXi   Members   -  Reputation: 187

Like
0Likes
Like

Posted 09 December 2012 - 09:08 AM

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/

#8 Nico_gamedev   Members   -  Reputation: 109

Like
0Likes
Like

Posted 15 December 2012 - 03:36 AM

Thank you for the link. I'll definitively look at it!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS