How to create a First Perspective World

Hi, I am new here and have just started experimenting with Jogl. I must say I was quite surprised to see that there was a shortcut to Open GL from Java like this, and I hope it can start a new era of Java games using full 3d.

However, I am having problems getting started. I have created a simple RPG model with an autogenerated map that I now want to try to visualize using Jogl. Its a simple map with elevation information that I want to create first. This was fairly simple using triangles between the elevation points. I also figured out that it was easy to translate and rotate this data too using the opengl calls for that. I also learned how to do texture mapping from the samples posted here.

But I am not sure how I can create a view that is perspective corrected and allows me to move in the same plane as the landscape-object. Just like a first perspective game. Any simple tutorials on this would be great, preferrably using JOGL commands.

Finally, I have problems making the lights actually affect the object correctly. It seems to ambiently light every surface no matter which angle it has to the light.

Also is there a simple way of gouraud shading the textured triangles by having the system calculating the normals on the vertices that are shared between polygons. Is this something opengl can do for me?

Thank you for any pointers on this.

You can find most aswers to your question in the nehe tutorials: http://nehe.gamedev.net. The tutorials itself are in C++ but more or less functional jogl-versions are provided for most of the lessions.

I would recommend that you use a scene graph API like Xith3D, jME or Java3D. It’s a lot easier than calling OpenGL yourself, and it will take care of viewer, lighting etc. for you.

My own game engine is not stable yet, so I can’t recommend that at the moment :wink:

Thanks for the tips. The tutorials at nehe.gamedev.net seem to explain everything nicely. I’ve managed to create the landscape now and showing it perspectively corrected. Next is trying to get lights to work. :slight_smile:

It seems for the lights to work my triangle normals have to be set using the glNormal3f method for each triangle. Are there any mode where opengl can calculate these automatically based on the polygon vertices? Or are there a utility class I can use to calculate this normal?

There’s probably something in sun’s vecmath library.

Ok, I read up on some open gl tutorials and found out how to calculate these normals (and normalize them to unit vectors). This is my effort so far:

http://www.lonningdal.net/jc/DaGame.jpg

This is a direct translation of the landscape from the tile-based RPG engine I have been working on (randomly generated each time). I hope to use the underlying object model for any NPCs and monsters movement later too. This is just a test to see if I can render my world using 3d as well. For the 2d visualisation I might consider a 3d isometric view from above to get the light moving right over the landscape. The tiles arent exactly as they should be since the tile is supposed to have a certain elevation, and as you see in the screenshot the tile is between the elevation points (used directly as vertices). I havent yet figured out how I can translate this better to represent the tile based world.

The fog effect worked fine also, and the sky texture is rotated on the sky-polygon to make it look like it moves slowly.

I can also control the light so to simulate the suns path over the sky. Simulating the color of the light (and fog) as well as the sky going from night-dawn-day-dusk is also an interesting challenge. I guess I need to create the sky using two planes, one with the color of the hemisphere (blue in the day, black starry sky in the night) and one plane with the clouds (with transparency). And I guess I only need to move a polygon with a bright blurred circle to simulate the suns actual path (same coordinates as the light source). You might have guessed by now that I am a big fan of Morrowind. :slight_smile:

The next I want to do is find average normals for each vertex so that it is based on the sum of normals for each polygon it is used in. I guess this will smooth the edges somewhat making the landscape a bit more real.

And I need to figure out how to make the water a bit transparent as I wish to see the bottom also.

The fog seems to have a problem if I am using linear mode. It wont fog the sea level polygon right, but everything else looks fine, and is the preferred method since it allows me to control the distance from/to of the fog (these settings doesnt seem to work for the two other modes, exp and exp2). Maybe I need to split the water polygon into many quads?

The tutorials at NeHe has helped me out a lot. So if the author is around here, thanks a lot. Its fun meddling with 3d again after all these years (back when I spent most of the time making fast gouraud shaded textured polygons using both pipelines of the pentium). :slight_smile:

Hey, it seems the linear fog mode works brilliantly on my GeForce3 Ti500. I only tried it on an old GeForce MX 440 before, which seems to fail on big polygons like the sea.

I’ve also averaged the surface normals to calculate vertex normals and get smooth results. Here is a screenshot:

http://www.lonningdal.net/jc/DaGame3.jpg

The total scene has around 5000 triangles and on my GeForce3 Ti500 / AMD XP2000 the fps drops to around 50 fps on fullscreen 1280x1024. So a total of 25000 single texture shaded polygons (+linear fog) per second. I dont know if this is about what I can expect from JOGL on my card? I assume I should get the same throughput on a windowed GLCanvas compared to full screen?

[quote]I dont know if this is about what I can expect from JOGL on my card?
[/quote]
It depends on technique you’re using to render the world. Are you using display lists or VBO´s or just plain immediate mode rendering (plain GL-commands)?

I’m using plain immediate mode where the vertices, texture info and normals are stored in float arrays and pushed using gl commands every frame.

But it seems that from the 1 normal per triangle to the 3 normals per triangle (per vertex) the speed dropped somewhat. Indicating that the shading is more complex and needs more work. I use backface culling also.

Especially with JOGL, you will find a major boost to performance when using displays lists (or VBOs for example) over immediate mode. This is partly because of the JNI-overhead that is caused by JOGL calling the underlying native OpenGL-functions. So, as a thumb rule, less OpenGL calls means less overhead caused by JNI calls.

Thanks for the tip. I’ll try out display lists soon. Its been a while since I’ve been coding a 3d application and there is a lot of good information out there.

I want to read up more on effectively rendering a large number of trees and grass to make a lush vegetation. Seems like there are some tricks that can be used, like billboards that fade into full 3d-models. I’ve read a paper on billboard slices which seems to be quite effective maintaining details especially on trees. As for grass I am not yet sure how to do it.