Java-Gaming.org
Java4K - to go         Javadoc:
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources or peek at the official java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Shaders written in GLSL?  (Read 1049 times)
0 Members and 1 Guest are viewing this topic.
Offline Chagma

JGO n00b
*

Posts: 36



« on: 2010-02-15 04:37:04 »

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?
Offline indexunknown

Jr. Member
**

Posts: 83
Medals: 1



« Reply #1 on: 2010-02-15 04:47:19 »

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

JGO n00b
*

Posts: 36



« Reply #2 on: 2010-02-15 04:54:02 »

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 (?).
Games published by our own members! Go get 'em!
Offline princec
« League of Dukes »

JGO Kernel
*****

Posts: 7800
Medals: 77


Eh? Who? What? ... Me?


« Reply #3 on: 2010-02-15 05:01:01 »

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

Cas Smiley

Offline xinaesthetic

Full Member
**

Posts: 204
Medals: 1



« Reply #4 on: 2010-02-15 05:26:18 »

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 (?).
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.
Offline Chagma

JGO n00b
*

Posts: 36



« Reply #5 on: 2010-02-15 05:28:35 »

Oh, can you be more specific?  What do you mean by "not to work reliably"?
Offline xinaesthetic

Full Member
**

Posts: 204
Medals: 1



« Reply #6 on: 2010-02-15 05:59:45 »

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.
Offline princec
« League of Dukes »

JGO Kernel
*****

Posts: 7800
Medals: 77


Eh? Who? What? ... Me?


« Reply #7 on: 2010-02-15 06:09:06 »

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 Smiley

Offline Chagma

JGO n00b
*

Posts: 36



« Reply #8 on: 2010-02-15 06:11:07 »

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.
Offline princec
« League of Dukes »

JGO Kernel
*****

Posts: 7800
Medals: 77


Eh? Who? What? ... Me?


« Reply #9 on: 2010-02-15 06:14:10 »

Yes, they work.

Cas Smiley

Games published by our own members! Go get 'em!
Offline gouessej

JGO Kernel
*****

Posts: 3433
Medals: 26


TUER


« Reply #10 on: 2010-02-15 06:16:35 »

Oh, can you be more specific?  What do you mean by "not to work reliably"?
On a few machines, you may have a noticeable performance hit by using GLJPanel rather than GLCanvas or a native window.

Julien Gouesse
Offline gouessej

JGO Kernel
*****

Posts: 3433
Medals: 26


TUER


« Reply #11 on: 2010-02-15 06:18:43 »

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 it works fine with JOGL. I used it some years ago Smiley

Julien Gouesse
Offline Chagma

JGO n00b
*

Posts: 36



« Reply #12 on: 2010-02-15 06:20:02 »

Yes, they work.

Cas Smiley

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?
Offline princec
« League of Dukes »

JGO Kernel
*****

Posts: 7800
Medals: 77


Eh? Who? What? ... Me?


« Reply #13 on: 2010-02-15 07:08:15 »

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 Smiley

Offline xinaesthetic

Full Member
**

Posts: 204
Medals: 1



« Reply #14 on: 2010-02-15 07:09:04 »

On a few machines, you may have a noticeable performance hit by using GLJPanel rather than GLCanvas or a native window.
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
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.132 seconds with 20 queries.