Sign in to follow this  
Nico_gamedev

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

Recommended Posts

Nico_gamedev    109
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!

[img]http://img819.imageshack.us/img819/3917/landscape.gif[/img]

Share this post


Link to post
Share on other sites
ic0de    1012
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:

[CODE]
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);
[/CODE]

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

Legacy opengl is a bit easier but is reeeeaaaaly slow:

[CODE]
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();
[/CODE]

attached is a sample heightmap Edited by ic0de

Share this post


Link to post
Share on other sites
Nico_gamedev    109
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
larspensjo    1561
For automatic generation of height data, have a look at [url="http://en.wikipedia.org/wiki/Simplex_noise"]simplex noise[/url] (similar to Perlin noise). In the "External Links" section to Stefan Gustavsson ([url="http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf"]http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf[/url]) , 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: [url="http://ephenationopengl.blogspot.se/2012/05/making-caves-from-simplex-noise.html"]Creating caves[/url], used as a probability for vegetation, etc.

Share this post


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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
    • By C0dR
      I would like to introduce the first version of my physically based camera rendering library, written in C++, called PhysiCam.
      Physicam is an open source OpenGL C++ library, which provides physically based camera rendering and parameters. It is based on OpenGL and designed to be used as either static library or dynamic library and can be integrated in existing applications.
       
      The following features are implemented:
      Physically based sensor and focal length calculation Autoexposure Manual exposure Lense distortion Bloom (influenced by ISO, Shutter Speed, Sensor type etc.) Bokeh (influenced by Aperture, Sensor type and focal length) Tonemapping  
      You can find the repository at https://github.com/0x2A/physicam
       
      I would be happy about feedback, suggestions or contributions.

    • By altay
      Hi folks,
      Imagine we have 8 different light sources in our scene and want dynamic shadow map for each of them. The question is how do we generate shadow maps? Do we render the scene for each to get the depth data? If so, how about performance? Do we deal with the performance issues just by applying general methods (e.g. frustum culling)?
      Thanks,
       
  • Popular Now