开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜