Thursday, July 6, 2017

Playing with LWJGL 3

Recap & Update

I have been very busy lately. Got a new job, moved, had a kid, ya know the usual life stuff. I must admit blogging has never been something I have been good at. As is evident by my infrequent posting and sporadic change in directions. I have ultimately discovered that my personal projects that I talk about here, work on for a little while and then abandon are my method of learning. I am not sure whether this is indicative of us as human beings or if its just me. I can never stick with any of my "fun" side projects very long. Perhaps I have not put enough effort in or none have reached a good enough point to be released creating a sense of responsibility to continue working on it.

It is probably one of the reasons some of my more useful programs stay unreleased since I do not want to have to support them and can just use them for the purpose they were created for. For instance I have made at least 3 different tilemap makers, and a small image editor that I use often. Perhaps another reason is that most of them were made with Java Swing and those apps are not particularly fun to modify after a while or pleasing to utilize.

now on to the goodies...

LWJGL 3 and Vertex Arrays

So navigating the options available to different opengl versions is almost nightmareish. So the basics are pretty simple for working with these arrays. You gen the array glGenBuffers you bind the gen'd buffer glBindBuffer. Then you fill the buffer with your data, from using JOGL for this and switching to LWJGL I must say having only to send a FloatBuffer object to the glBufferData call is kind of nice. The included screenshot is rendered from a single vertex array with a single texture array for the 3d geometry. As you can see by the render quads though that is the texture used to render the individual blocks. Yes omg another block game, whatever man its a good way to expirement and learn so sue me if I generated a 100x10x100 block world and culled 76832 blocks that are not open to the sky or surrounded by others leaving 23168 blocks to generate a buffer of 10008576 floats. 


For the geometry I am using 36 vertices per cube (108 floats) and rendering without culling (omg I know, but hey I was debugging). I am using a glsl shader with a simple projection * view * model matrix multiplication to transform the three dimensional coordinates to the camera 2D plane. Currently I am using the nice JOML library for the projection but quaternions for the camera.

Triangle Strips

Now as for the 4 quads...ooops the heading gave it away. They are rendered as triangle strips in a single vertex/texture and index buffer. In order to get them to be rendered as triangle strips I used GL_PRIMITIVE_RESTART setting the restart index glPrimitiveRestartIndex. I had to use 0xFF to set the short constant in java as well as enable the behavior using glEnable(GL_PRIMITIVE_RESTART). There are a lot of optimizations to be made here.


Next I want to get up a decent FPS counter to track the effectiveness of the optimizations. Also put in a number of performance tracking logs.

Thats all for now...

1 comment:

Joshua said...

Dive into the realm of game development, graphics, and interactivity as we embark on a journey to create captivating experiences. How Play Game Bring your gaming visions to life with LWJGL.

Post a Comment