Sunland Villagers (was: Learning OpenGL/LWJGL)

It’s now on sourceforge:

There isn’t much yet, really. A main class, the OpenGL map renderer and some utility classes. If you notice bugs, problems mistakes or anything else strange with my code, please let me know. Since I’m quite new to LWJGL I assume that there are quite some things that could be done better.

Old usually means well tested, widely available and less bugs. I think I made good progress so far. To get a new display engine up from the ground in about 2 days is quite fast I think. Back when I coded C++, and I started using a new display library like SDL or Allegro, it wasn’t much faster, let alone learning an API like GDI for Windows or X11 for Unix.

What I have problems with is the projection matrix, and the sequence of translate and rotate commands. This is due to my bad understanding of vector math, and something I’ll have to learn some day.

Since I don’t think that hobby project can or should try to compete in graphics quality with professional projects, I rather want to invest my time into the games features. I know for many the big task seem to be to build the “engine”, but for me the most difficult task is to build the game upon the engine. I’m quite sure that once I have the besic display in place, the real problems will start for me - the questions how to make things fun to the player, how to keep the player motivated, how to make the game easily accessible to new players. From this point of view a “richer toolset” for the graphics pipleine isn’t something that I feel a big need for nor something that will pose a problem for me if I decide that I should need it at some point. It’s just that at the moment I think it’s not needed for my plans, since I aim for a graphics detail level that was seen in games about 15 years ago. While this was a challenge back then, todays tools make it easy, and I thinks that’s what is good for swift progress :slight_smile:

I’ve added code to draw paths on the map (Settlers II style). I have no real maps though, just randomly created ones, so the screenshot shows a random mesh of paths. Still missing is the handling of normals for the paths, but that shouldn’t be much of a problem.

I think I have now all graphical elements that Settlers II had - ground textures, paths and objects on the map.

New:

  • Normals for paths
  • Textures depend on map height (needs more in-between textures though)

Things about which I haven’t made up my mind yet:

  • How hilly should the landscape be?
  • Which relation of triangles to map object size should I choose?

The latter has the restriction that a map object’s (like a house) “width” and “depth” need to fit onto a group of triangles, so there must be some sort of non-fractional relation. But this is a very soft constraint.

I’ve been trying to improve the landscape generation a little (valley bottoms are more flat now, and hills more pointy), and added some in-between textures. Not looking too great, but it works.

Next will be to get the calculation mouse position -> vertex so that the user can interact with the map. And I must decide how to build in-game menues (AWT popups, pure OpenGL code, UI besides/below the map display).

Proooobably it’s overkill, and it depends on your skill whether you’d be able to code that, but what about masking the two textures on the edges. It’s actually quite easy.

Since you’ve only got triangles, you only have 1 single mask texture. You can rotate and invert this texture to get any mask texture you need. (by rotate I mean switch the texture coords)

Then you only need a simple shader (It looks like you’ve already got one, where you calculate the light…) and…

voila!

The shading is a feature of OpenGL itself, if you supply normals for the triangle corners. I’m somewhat confident that I can make the texture transitions look alright in the final version, but I haven’t worked on that yet. The textures themselves need more work, too.

A big step forward is that I can handle mouse input now. I mean to transform the mouse x/y coordinate to a vertex or triangle of the map. So I can start to build a UI now to control the game.

Since it’s an AWT frame it seems I can use all AWT components, but a quick test with JPanels and JLabels seemed to tell that I can use Swing components too. Next steps will be to give the player tool menues to place buildings and create paths.

Thanks for the medal, matheus23 :slight_smile:

You deserved it :slight_smile:

But… somehow… I wanted to give the medal to the post before the one I medal’ed… strange thing… I SWEAR I have’t even seen that post :open_mouth:

EDIT: On-topic:
You should try doing the shading in the Fragment shader.
Really, there is almost no hardware out there, which doesn’t support OpenGL 2.1.

And in the end GLSL isn’t too hard either. You only have to write yourself some utility classes like a Class for compiling shader-programs (or better: call opengl, to compile the GLSL shader), or just find on on the internet. I really have to say, that lwjgl-basics is a pretty good project by davedes. I’ve contibuted to it myself, and it really helped me a lot since then.

The speed of how fast you throw out new stuff frightens me.

What happend to your gardening simulator, abandoned?

I’ll look into shaders, you’re right they quite powerful tools. Thanks also for the link, next week I should have some time again to study code :slight_smile:

;D

I can draw from some older projects of mine, also there is a lot of helpful stuff on the web. And I assume I just put a lot of time into it. Almost worked last night through because I wanted to put together a first demo.

That’s my bane. My interest in my projects comes and goes in kind of short runs … usually they sleep a while, then I get some new ideas and I work on them for a few weeks, then they sleep again while I work on another project. I’m trying not to let my project list grow too much so that each sees some updates a year. It’s kind of project ADHS.

The gardening simulation is on hold currently because planting and watching plants grow felt a bit boring, and I haven’t made up my mind yet how to make it better. A faint idea is to allow some multi-player features, like sharing selfmade plants, but I’m not quite decided on the path to go. So it waits till I have new ideas again.

For today, I have put together a little demo. It’s mostly to see if the code runs on other systems but mine, too, and also to get a little bit of feedback, although there surely isn’t much to comment on but if zooming and panning works, and the like.

You can get the demo from here:

https://sourceforge.net/projects/sunlands/files/v0.01/

So far I’ve only taken care about windows and supplied a “star.bat” which starts the Java runtime with the right parameters. Some day I hope to have a better startup system which works on Linux and MacOS, too. I assume you could copy the start.bat, and transform it into a start.sh which does about the same thing for Linux, but right now I have no Linux system to test that.

I’ve got a basic game actions framework in place now and added two actions to build paths and place buildings. Both functions will be needed in the game, but at the moment it’s just proof of concept work.

To make construction a bit easier, there is a helper function to display a little flag on each vertext where an element can be placed:

The strange sand-colored triangle is the map vertex pointer, i.e. the place of which the code thinks you are pointing to with the mouse.

You can get the new demo from here:

https://sourceforge.net/projects/sunlands/files/v0.02/

Works for me!

There was only a white square where the map should be, at the first launch. But after launching it a second time everything worked perfectly. (Assuming that you are only allowed to build a 1 by 1 path at a time)

Nothing in the error log besides:

<?xml version="1.0" encoding="windows-1252" standalone="no"?> <?xml version="1.0" encoding="windows-1252" standalone="no"?> <?xml version="1.0" encoding="windows-1252" standalone="no"?>

Thanks for the quick test :slight_smile: Path building only works step by step currently, that’s right. A bit odd that the display did not initialise correctly for the first try, but at least it worked in the second. Thanks again!

Path building was refined a bit, and a basic UI to chosse from several buildings to build is now in place too. The big building is borrowed from the Widelands project.

I’ve been trying to make the world an island. The water texture was made in a hurry, but I can make a better one later. Also I have kind of proof-of-concept code now to make a decorated border and panel backgrounds.

Moved to WIP :point:

Thanks :slight_smile:

Very, Very good progress… reminds me of me, when I was coding a game of a genre I really loved… :slight_smile:

Also, this looks much more like a game now! Well done!

Thanks! And yes, at the moment I’m really eager to bring my idea alive. On the other hand, it will be much slower to work on the games logic and better graphics. Particularly the logic will need a lot of planning.

Looks very good, i loved the settlers :smiley:
Maybe you should add some more triangles, because those hexagons at the sides of the island dont look to well.