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. 

1 comment:

Joshua said...

"LWJGL 3: Texture Coords and Picking" How Games Discord delves into the fascinating world of texture coordinates and the art of object picking in LWJGL 3.

Post a Comment