Friday, September 15, 2017

Flip a coin!

Building a game is tough work. There are so many things that need to be put in-place. Each time I work on a game project, I always get a little closer to having something more closely resembling a game. So I feel like I'm on the right track. Got a good idea for something I want to play. I've been building many of the pieces of this game throughout the years.

So the way the project started most of the code was like in a single class and as that approached a point of tough to manage I split it up, modularizing it and picking some of the best design I could. Only time will tell if that pays off or not.

I also spent some time cleaning up a ton of clutter left around from various points of experimentation and rework. As well as demo and other types of codes that had been used to debug the opengl learning I was redoing over the years. It's been a literal on and off with OpenGL and OpenGLES. I used to do a lot of DirectX work many years ago did some XNA stuff for a little while too back when I was using Windows. These days are pretty much spent with Linux and not really any thought of turning back.

So, I added sounds and light levels to the combined block texture. I separated out the PlayerController class, built up a World class that is handling all the blocks. Currently working on a Parcel (i.e. chunk, partition) system to allow for a larger number of sections of the world to be generated on the fly. Things are working out well so far. Their building up nicely, got a couple of bugs to fix as is normal. Currently focusing on some movement code, adding gravity and stuff with simple collisions, jumping etc.

Oh I also added ray picking and removing of blocks. It happens instantaneously and since there isn't an inventory or item system yet, there are no tool requirements. I will have to blog about the picking at some point. It works quiet well and is exceptional at using all the GPU memory available since I have not added code to clean up old vertex and texture buffers that are left behind. Just add that to the list of things I need to do.

This time around I am trying to work off of a list of items, a todo list/backlog. I just keep it in a simple document and X off things when their finished no dates or targets yet but maybe I'll add something like that. I mean I would probably just want a number of days since it's been modified with the goal being to keep that number low. I think I'll add a simple one item inventory with a tool requirement for breaking blocks.

Some current screenshots with a few missing blocks, the sides are not really well defined because another backlog item is being able to change the light level for each side. The textures need a lot of work their just placeholders for now until it becomes a playable game and then they will need to change.

















Ttfn...

Monday, August 21, 2017

LWJGL 3: Texture Coords and Picking

So instead of catching up on facebook and looking for nice videos and photographs of the 2017 solar eclipse, I decided to do an update on what I have been working on.

Ray Cube Intersection...Picking

It works but it needs a bit of debugging. It doesn't always work when I think it should, may be it has something to do with the direction of the ray or the way the ray is used in the algorithm.

But as you can see I checkered test cubes with left, right, top, bottom, front, back images which are generated on the fly as test BufferedImage's and then added to a single final texture which is generated for all blocktypes and their respective side images that are specified in a single json file and referenced by name in the code.

There are lots of optimizations to made later down the road that will improve performance dramatically but already a good number of blocks can be displayed on pretty old hardware so it shouldn't be a problem to begin building the gameplay out and experimenting with different mechanics.

Also notice I added the cross-hairs. That is coming from a font texture that is procedurally generated using the Graphics2D object into a BufferedImage and then converted to a Texture. So atm just building some very basic capabilities into the code that will help to build the overall pieces of the game. There is a lot of stuff to get done though and its no small task.

The Glorious Test Cube

Inside the test cube atm...no lighting of textures yet.
It was much easier to tell the issues with the faces and texture coordinates once I had these helpful textures generated.

Also generating them using code was much easier than generating them with an image editing program. I didn't have to worry about them being misaligned or a little bit off, not that they need to look uniform but it was just easier to create and algorithm that loops through each element of an array of strings a add the Textures to the TextureManager than it would have been to Open -> Edit (drawing drawing drawing) -> Save -> Open -> Edit (...) -> Save and then name the files put them on the class path. Ugh but I guess that is why I am a programmer.





Ah the simplicity of being a cube, what a life...
The other blocks are test grass blocks with different textures for the top, and bottom, and another texture for the left, right, front, back. I do not have a block editor just yet but adding new blocks is simple enough, create the textures and add the new block to the json file. It's not entirely decided how I will do world generation but it will be epic. Nah amazing, ok it's going to be really fun if any thing.

So far this has been a lot of fun to create and see the different things come together and hopefully even though it is seeming a bit like Minecraft the end result will be its own unique experience.

I had tried to do these sort of things with a engine like Unity and contemplated doing it in something like Unreal Engine. But both of those engines would have made the procedural texture generation and cube lighting a nightmare. Especially with attempting to control the way those engines utilize buffer objects and other aspects of the GPU. Though having most of these types of things done for you already can save a lot of time obviously. Still I believe the end result ends up suffering from performance and smoothness issues unless you really cater to the types of pipelines those engines were made to do well. But it also means an incredible amount of work for me to do. But like I said I'm having fun so as long as thats happening things are good. This isn't like my day job or anything so it's a good off the clock activity to help keep my programming skills sharp and exercise coding I do not get the opportunity to do with my day job.