Slick Forums

Discuss the Slick 2D Library
It is currently Fri May 24, 2013 3:04 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Glow effect
PostPosted: Mon Apr 30, 2012 10:57 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1315
Location: Italy
I know there is a lot of threads about that, but no one have a working example anymore, so again question: how to draw a "glow" effect using lwjgl and slick around simple shapes, like this circle?

Image
see: http://stackoverflow.com/questions/1037 ... ck-in-them


I know i must use GL functions to achieve this, but with no working code it's hard to understand the process.

Thanks in advance

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject: Re: Glow effect
PostPosted: Mon Apr 30, 2012 8:48 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
The easiest and most efficient way to do this is to bake the glow into your sprites (e.g. using Photoshop).

If you need the glow to be dynamic, then another common technique is to use a two-pass blur shader. This requires the following OpenGL extensions:
- GL_ARB_shader_objects or GL20
- GL_EXT_framebuffer_object or GL30

Easy way of doing it:
  1. Render your scene or "glow objects" to texture A
  2. Bind texture A, then using the horizontal shader, render a quad to texture B
  3. Bind texture B, then using the vertical shader, render a quad to texture A

The textures you're rendering to should be bigger than the image (otherwise the blur will be cut off abruptly), or simply the size of the screen for simplicity's sake. You should optimize this by only applying the effect to texture A when necessary (i.e. when glow needs updating).

The dev branch includes a ShaderProgram utility as well as two shader tests. ShaderTest is a simple invert shader (might help you get started with shaders). ShaderTestAdvanced is a blur shader, basically what is described above. It's a bit hackish, and needs a little cleaning up, but it should get you started.


Top
 Profile  
 
 Post subject: Re: Glow effect
PostPosted: Tue May 01, 2012 4:42 pm 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1315
Location: Italy
I've tried to build Share with slick but without any luck, can you provide a "hello world" eclipse project about that? So I can work on it

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject: Re: Glow effect
PostPosted: Wed May 02, 2012 6:17 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
"Hello world" on pulling source code? Sure, if I have some time I'll write a little tutorial for the wiki.


Top
 Profile  
 
 Post subject: Re: Glow effect
PostPosted: Thu May 03, 2012 7:16 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1315
Location: Italy
thanks!

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject: Re: Glow effect
PostPosted: Sun Jun 24, 2012 11:03 am 
Offline

Joined: Thu May 19, 2011 9:43 am
Posts: 50
davedes wrote:
The dev branch includes a ShaderProgram utility as well as two shader tests. ShaderTest is a simple invert shader (might help you get started with shaders). ShaderTestAdvanced is a blur shader, basically what is described above. It's a bit hackish, and needs a little cleaning up, but it should get you started.


Where is this "dev branch"?

I've been trying to find a Slick Shader tutorial for many months now.


Top
 Profile  
 
 Post subject: Re: Glow effect
PostPosted: Sun Jun 24, 2012 3:10 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
pekhe wrote:
davedes wrote:
The dev branch includes a ShaderProgram utility as well as two shader tests. ShaderTest is a simple invert shader (might help you get started with shaders). ShaderTestAdvanced is a blur shader, basically what is described above. It's a bit hackish, and needs a little cleaning up, but it should get you started.


Where is this "dev branch"?

I've been trying to find a Slick Shader tutorial for many months now.

http://slick.cokeandcode.com/wiki/doku. ... ent_branch


Top
 Profile  
 
 Post subject: Re: Glow effect
PostPosted: Sun Jul 08, 2012 10:25 am 
Offline

Joined: Thu May 19, 2011 9:43 am
Posts: 50
How to apply a shader to a specific image/texture only, and not to the whole scene?
I found a tutorial for render-to-texture ( Here ), but as far as I understand the ShaderTest.java in the newest build applies the shader to the whole screen.

Also, how to render it so that stuff behind and in front of the shader-texture won't get affected by the shader in any way?

EDIT
Okay, it seems to work just the way I wanted, not the way how I initially thought.
The shader is not applied to the whole scene, but rather only to those images that are drawn between the lines
program.bind();
and
program.unbind();

If I'm wrong please explain how it actually works.

EDIT 2

A shader test:
Image


Top
 Profile  
 
 Post subject: Re: Glow effect
PostPosted: Sun Jul 08, 2012 6:28 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Looks cool!

When a shader is bound, anything rendered will use that shader. So if you've got an invert colour shader (returning 1.0 - RGB) and you draw a white rectangle with g.drawRect, it will appear black as a result. Same goes for fonts and images.

The reason we blur the whole screen in the demo: if we only blurred the image, it would get abruptly cut off where the blur meets the edge of the image. To remove this, we need to blur a larger area than the image's bounds -- i.e. the full screen. In order to affect the whole screen with a shader, you need to first render everything as per usual into an image, and then bind your shader and render that "full screen image" onto the screen (thus making the shader affect the full screen image).

If you've got more questions, just ask.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group