Few questions about Slick

Hi,

Would have posted this on the Slick forums, but tried to register and it threw up an error that it couldn’t connect to the mail server to send me the email. (actually wrote this yesterday but then JGO was unreachable - seems like everything I touch at the moment is breaking! :persecutioncomplex: )

I’ve just started experimenting with Slick. I’m thinking of using it as the starting point for a hardware accelerated video/image pipeline in my Praxis software. However, I’ve got a few questions I wondered if anyone on here could offer some advice on.

  • The current software pipeline uses premultiplied alpha for all transparent images. As I need to have this software pipeline available as a fallback, I’d like to use images with premultiplied alpha in Slick. This will make getting data in to (and occassionally out of) textures much easier. I’ve also read various things that suggest blending is more accurate using premultiplied alpha, particularly for blending between transparent surfaces. Has anyone done anything similar with Slick? I’m thinking I’ll need to subclass Image and create a wrapper to the Graphics that reimplements blend modes, color, etc. I wondered if there are any pointers or gotchas I should be aware of doing this?

  • The software pipeline has its data stored in int arrays as RGB or ARGB_PRE. I’m new to this OpenGL lark, so I wondered what people would advise as the best performing way to get this data into a texture? Currently for the ARGB data I’ve experimented with glTexSubImage2D, using a bytebuffer with little endian ordering, and pushing it up as BGRA. This was mentioned on the Slick forum somewhere, but I wondered if this is the best way to do it?

  • Am I right in thinking that textures on images need to be explicitly released, and they’re not just released when the Texture object is unused or GC’d? I was experimenting (rather naively) at first with setting a new texture to the image every frame, and it almost brought my computer to its knees. Adding a line to release the texture before setting the new one at least seemed to stop things falling over. However, there are various places in the Slick source code where the texture seems to be changed without releasing the old one. Am I missing something?

Thanks in advance for all and any help, Neil

Yeah, you releasing a texture will clean up the texture object on the graphics card side. However, what you’d usually do is load a bunch of Textures upfront, and then refer to them from various parts of your code. I’m not sure exactly how Slick handles this, but you’ll have something like TextureStore.getTexture(String id) which will return the same Texture object to different places you use it from.

So you shouldn’t be creating/releasing Textures all that often - generally, once per each image you’re using. And so, releasing them all isn’t necessary - since by the time you “should”, you’re exiting the program anyway. It’d only be an issue if you’re unloading/loading subsets of your Textures fairly often due to memory constraints - such as say specific textures for a level in a game.

I’m not sure what you mean by “setting a new texture to the image every frame” but that doesn’t sound like something you’d want to be doing in the first place :slight_smile: