Shaders written in GLSL?

Is it possible with either JOGL or LWGL to use shaders written in the OpenGL shading language GLSL? If not, how do you write shaders for use in Java/OpenGL software?

http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/opengl/basicshaders

Wow, thanks for the quick response!

Do you know if such a thing is also possible in JOGL? I am probably going to have to use JOGL because I need my game to be able to run inside a JPanel and I don’t think LWJGL can do that (?).

Yes, it can (see AWTGLCanvas or Display.setParent() in the LWJGL APIs).

Cas :slight_smile:

I’d be sceptical about using JOGL to render a game in a JPanel… it tends to be slow, unless you use the OpenGL Swing pipeline, in which case it tends not to work reliably.

Oh, can you be more specific? What do you mean by “not to work reliably”?

See this demo, for example:
http://weblogs.java.net/blog/campbell/archive/2006/10/easy_2d3d_mixin.html

The OpenGL pipeline enabled version doesn’t work on my laptop with a decent-ish graphics card, up to date drivers and JRE etc. I just tried it now, and the window appears white (resizing causes the newly exposed parts of the panel to appear black). I’m sure I’ve other examples using a similar method, none of which worked. So, I’d trust that technique about as far as I can throw it. Maybe someone will come to its defence.

On the other hand, the version without Java2D OpenGL pipeline wasn’t as slow as I feared; about 30-40 fps with the window at its default size, dropping to 10 when maximised to 1920x1080. That might be usable enough after all.

The main issue is the way the GL renders to a buffer and then the buffer has to be rendered into the JPanel, it being a lightweight component. You can solve this by doing away with lightweight components and going straight to a Canvas but you’ll run in to a few glitches if you overlay any other lightweight components on it. In practice, this almost is never a problem until you use a JMenu of some sort, which you have to work around by specifying that it’s heavyweight. The problem is allegedly completely fixed in JDK7 which will allow proper layering of lightweight and heavyweight components, and I’m sure I spotted something in the latest 6_018 update to do with this as well…

Cas :slight_smile:

OK, thanks for the info. I also cannot get any demo of the Java2D/OpenGL pipeline to work on a couple of machines.

Anyway, my original question stands: can GLSL shaders be used with JOGL? We have established that it can be done with LWJGL but I’d like to know the situation with JOGL too.

Yes, they work.

Cas :slight_smile:

On a few machines, you may have a noticeable performance hit by using GLJPanel rather than GLCanvas or a native window.

Yes it works fine with JOGL. I used it some years ago :slight_smile:

I have to say I am impressed with the speed and quality of responses in this forum!

So are they implemented in basically the same way as with LWJGL?

Pretty much, yes. In fact neither of the two bindings actually “implement” anything, they just pass it through to the driver with the minimum of overhead and fuss.

Cas :slight_smile:

The trouble is if you specify OpenGL pipeline (to get higher performance rendering due to not having to copy buffers the whole time) sometimes rather than a performance hit, you get a complete failure to render any graphics. So unless it’s acceptable for the application to only work on specific machines, that’s one to avoid. The new compositing stuff sounds promising.

op: If you take a look in the JOGL demos I’m sure there’s some examples with GLSL.

If only all threads got such a positive response :wink: