[LWJGL][Slick2d] How can I combine the forces?

Rayvolution has found a nice way to get the best of both worlds when it comes to LWJGL and Slick2D. How can you combine LWJGL with Slick2D? How can you use the simplicity of slick with LWJGL?

I’d like to keep the simplicity of Slick rendering to an extent but have the extra features that LWJGL brings to the table. Is that possible?

If you have a project setup in eclipse with slick, just type “import org.” and the autocomplete shows all the lwjgl packages. They’re included with slick, you use them like anything else. Why is this a question?

I honestly didn’t know. :stuck_out_tongue: Does any of it interact with say the Image class in slick? I figure since slick is built on lwjgl it will work but…

When you’re in eclipse and you select what to “import”, just make sure you pick slick’s Image library, and not LWJGL’s. As far as using both Slick and LWJGL’s side by side in the same class, I’m honestly not sure how you’d go about that. (But I’m also not entirely sure why you’d want to. :stuck_out_tongue: )

(EDIT: Just realized I’m a dummy, LWJGL doesn’t have an Image class in the first place, so this situation would never happen. My guess is the closest LWJGL equiv. is probably one of the “Texture” classes, but I’m unsure.)

Really though most of the stuff you’d want to access in LWJGL is probably the static getters/setters like GL11.glBlendFunc() and Display.getWidth()/Height(), Slick does a pretty decent job of wrapping everything else LWJGL does (for 2D games anyway).

I’d be careful though, because you may find yourself doing things directly in LWJGL that Slick can already handle, and while there’s really nothing wrong with doing it, it may make your code really confusing if you have several classes mixing and matching LWJGL and Slick2d together. I really try to avoid using LWJGL directly as much as I can personally. I only go to LWGJL if I absolutely can’t do it in slick2d, like my resizable window (while the game is running) that Slick doesn’t support for some odd reason.

My advice would be to exhaust all options of doing it in Slick2d before you go to LWJGL, you’ll be surprised to find out that Slick (as well as LibGDX) can handle a lot of very specific aspects of LWJGL. Of course, I guess the plus side is learning LWJGL instead is probably massively more beneficial than Slick2d or LibGDX in the long run. But most of what you’ll be doing is LWJGL is just boilerplate stuff Slick/Lib do anyway.

Ok to be honest, all I want to do is 2D lighting and shadows and those sexy blendy things that puppygames does. How and what do I use to do that?

Google around for “lwjgl 2d shadows” and “lwjgl additive blending.” We have told you these terms before.

That’s where GL11 comes in. This code doesnt support colored lighting, it’s just for basic alphamap lighting, but it’ll get you going in the right direction.

It’s a blend of Slick2d and LWJGL.


	g.clearAlphaMap(); //Clear the AlphaMap in Slick2d
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); //Set drawing suitable for alpha maps
	lightSky.draw(0,0,lightLevel); //Huge black image that covers your entire screen, lightLevel is a Color() that changes alpha levels (IE: Color(1f,1f,1f,0.5f) is half opacity);
	//LIGHTS YOU WANT TO RENDER HERE. All lights should be BLACK where you want the light to be and TRANSPARENT everywhere else
	GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_DST_ALPHA);
	g.fillRect(0, 0, Display.getWidth(), Display.getHeight()); //Cover the whole screen with a black rectangle
	g.setDrawMode(Graphics.MODE_NORMAL); //draw mode reset in Slick2d.

Note: under fillRect you probably want to make your own int variables that are set to Display.getWidth/Height instead. That’d be a more proper way of doing it.

I’m mainly using lwjgl. Could I download the full slick2d jar and use the gamestates, along with the lwjgl rendering? That would make certain tasks very easy.

Yes.

Hell, you could probably use LibGDX and Slick2d together if you wanted (why, I have no idea).

REALLY! I had no idea. I thought lwjgl was just lwjgl and you could only use slick_util textures. Thanks a bunch! ;D

LWJGL is just openGL + java to interface with it, slick and libGDX are both LWJGL + more stuff on top.
(Technically libGDX also has a JOGL backend, but LWJGL is usually preferred)

Could I use slick to load images by doing somthing like

img = new Image("res/theimg.png");

?
Can I also use the gamestates from slick when coding in lwjgl?

yes, and yes.

Although I personally feel you should use one or the other, using both is kinda awkward. Really, even though Slick2D is “dated” people have the misinformation that makes it inferior (I blame the young mentality of “It’s old so it’s junk, only new things are good!”). Keep in mind though, you can’t just slap LibGDX on top of Slick and make an awesome game. If anything, that will just over complicate the process and make things worse for you.

That would be like trying to make a car run with a diesel and gasoline engine at the same time. Can you do it? Probably with enough work… but why would you? Just pick the one that has the benefits you want (Lib’s More native Android support, or Slick’s StateBasedGame support for example) and go with it!

My reasoning for sticking with slick is I know enough programming to force slick to do what I want anyway, and I love it’s StateBaseGame system. I also have no plans what so ever to get into the mobile market, so Lib’s native android support is irrelevant to me.