Friday, August 11, 2017

LWJGL 3: Texture to GPU and back

Time Flies...

It's supposed to end with "when you're having fun" but that and a lot of other cliche sayings have all been in question lately. For one thing who ever said that "slept like a baby" was actually supposed to be mean waking up every two hours to feed and then fussing because you do not want to close your eyes. And since I'm a programmer I have fun when I am getting things done and there is time left over in the day. Not when I only get to sit down and do things for five minutes right before bed. And then you look down at the date on your computer and see that more than a month has gone by since your last post. Ridiculous!

What was accomplished?

So there is some small bit of progress... The hard part of actually doing things the way I wanted to do them... see I wanted to combine a bunch of textures as texture classes after they had been converted from BufferedImages and their contents transferred to the GPU. But how to do that was not entirely straight forward, or so I thought. 

See the BufferedImages were being loaded and in order to not be bothered with hashing out different methods of copying the images to the GPU based on different ColorFormats I simply rendered the image to a new BufferedImage whose format is ARGB but in OpenGL the complimentary image format is RGBA so yeah simple one would say just use the rotate assembly instruction and we are all set. ***BUZZER SOUND*** WRONG!!!! you cannot do that in Java. Thanks a bunch Jawa.  

So after fiddling and fiddling with it because I wanted to pull out all the pixels into an array instead of accessing them one by one through the BufferedImage object I present you with my silly idea of progress.


And then...

So once I got that to work properly and could stop fiddling with bits in Java which is not a fun process. I was able to generate a single texture from multiples and replace those multiples with SubTextures in the TextureManager. That all works now and that enabled me to externalize all my BlockTypes into a single json file which enables an editor that I will work on to add new blocks this is huge because editors can make adding content 10 times faster than editing a growing json file and 100 times faster and less error prone than adding new blocktypes in code.

Addendum


And here just to make this post complete is how the textures are loaded from an image in LWJGL 3.



And there you have it now on to bigger and better things. Like I also added movement in 4 directions WASD and fixed a bunch of odd things that were incorrect about displaying the textures and generated a Font texture and a number of other things but ya know other topics for another day. TTFN

No comments:

Post a Comment