开发者

How do I use the data from a .png packed in a .jar as a texture in LWJGL?

开发者 https://www.devze.com 2023-03-18 10:18 出处:网络
So I\'m making a basic game in Java开发者_StackOverflow社区 using LWJGL. I have a .png file packed in the .jar that obviously cannot be used for textures while it\'s still inside the .jar. The only wa

So I'm making a basic game in Java开发者_StackOverflow社区 using LWJGL. I have a .png file packed in the .jar that obviously cannot be used for textures while it's still inside the .jar. The only way I can think of getting the file out of the .jar is to create an Image object.

I've tried using getResource, but the way I currently have it set up is that it calls on the path to create a FileInputStream (I'm using a PNGDecoder class that takes the PNG's FileInputStream and directly creates the LWJGL Texture), and so it can't exactly read the .png from within the .jar.

Does anyone know how I can make the PNGDecoder happy, or have another way to convert the packed .png to a LWJGL texture?


PNGDecoder probably accepts any InputStream and not just a FileInputStream. Use getClass().getResourceAsStream(...) to directly get an InputStream of the .png file in the .jar, without the need to extract it first.

0

精彩评论

暂无评论...
验证码 换一张
取 消