box2dLights

Present your own projects here, be they WIPs, betas or finished products. Get feedback from others and help each other out with some lovely testing.

Re: box2dLights

Postby kalle_h » Wed Nov 14, 2012 11:33 pm

Box2dlights use framebuffer for rendering lights and then blurring that and blitting to screen. This problem is caused that you then have two framebuffers bind in same time.
To fix this problem unbind your framebuffer before drawing lights and bind it before lightmap class actually renders the lights but after all lights are rendered to framebuffer.

You need to edit code at render() method.
just add your framebuffer begin at start of that block.
http://code.google.com/p/box2dlights/so ... htMap.java


Another solution is use disable lightmap flag but this can look ugly and prevent shadows to work at android,
kalle_h
 
Posts: 666
Joined: Thu Dec 29, 2011 9:50 pm

Re: box2dLights

Postby Gooni » Thu Nov 15, 2012 8:15 pm

Thanks for your answer, i got it working perfectly now.
Please allow me to share the following considerations:
I started out with the idea of creating a class MyRayHandler that just extends your RayHandler.
If I am not mistaken it would have been enough to just overwrite the rendering method.
However the member LightMap (and most others) are private so I can't do that.
Now I am copyying all your sources but that means I have to do so in every update of your code (if there are any).
Maybe it would be better to make most members protected for user modding? (Just asking.)
Please understand this as a question/proposal, not as a complaint!
Thank you so much!
Gooni
 
Posts: 66
Joined: Sat Oct 08, 2011 10:54 am

Re: box2dLights

Postby kalle_h » Fri Nov 16, 2012 9:32 am

Good to hear its working now.
It's always tricky to open classes for inheritance because that then lock certain aspects of inner structure.
eg. I can't be sure that I don't break users code even if I don't change public API.
But current state of box2dlights is feature complete. There are certain advanced usage problems but those are usually easier to solve by modding the sources than with inheritance because in either way any change may lead rewriting certain parts.

But thanks for your input. I appreciate it.
kalle_h
 
Posts: 666
Joined: Thu Dec 29, 2011 9:50 pm

Re: box2dLights

Postby Magnesus » Sat Feb 16, 2013 8:09 pm

How do you tell box2DLights where and with which size to draw the lights when box2d coordinates are diffferent than the game or screen coordinates?

For example I have 1920x1080 viewport with approximately 19x10 box2D world. The screen might be translated or even zoomed in (camera of the stage).
Magnesus
 
Posts: 1574
Joined: Sun Sep 25, 2011 3:50 pm

Re: box2dLights

Postby kalle_h » Mon Feb 25, 2013 7:59 pm

You provide matrix stack for rendering. That handle transform and projection to screen. Just use same matrix that work with box2d debug renderer and you are set.
kalle_h
 
Posts: 666
Joined: Thu Dec 29, 2011 9:50 pm

Re: box2dLights

Postby Magnesus » Mon Feb 25, 2013 8:33 pm

How do you provide matrix to box2dLights?
I have different sizes and coordinates in box2D and stage (I use multiplier to get coordinates and sizes into the range that box2d "likes") but if I could provide matrix for box2dlights it should be easy to make one multiplied to match exactly the screen position and size.
Magnesus
 
Posts: 1574
Joined: Sun Sep 25, 2011 3:50 pm

Re: box2dLights

Postby Magnesus » Tue Feb 26, 2013 9:37 am

OK. I managed to get it to work. I somehow missed the tip about the debugrenderer. :)

edit: everything works great now!
Magnesus
 
Posts: 1574
Joined: Sun Sep 25, 2011 3:50 pm

Re: box2dLights

Postby Magnesus » Sun Apr 14, 2013 7:32 pm

PS. Seems to not work with latest nightly of libGDX:

Code: Select all
04-14 21:29:36.223: E/AndroidRuntime(31700): java.lang.NoSuchMethodError: com.badlogic.gdx.graphics.Color.set
04-14 21:29:36.223: E/AndroidRuntime(31700):    at box2dLight.RayHandler.setAmbientLight(RayHandler.java:472)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.drawLevel(LHGame.java:1173)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.execute(LHGame.java:3327)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.onceTouched(LHGame.java:887)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.touch(LHGame.java:870)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.render(LHGame.java:971)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.lib.MaApp.render(MaApp.java:249)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHApp.render(LHApp.java:105)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:487)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Magnesus
 
Posts: 1574
Joined: Sun Sep 25, 2011 3:50 pm

Re: box2dLights

Postby johnrico2000 » Mon Apr 15, 2013 11:51 am

Magnesus wrote:PS. Seems to not work with latest nightly of libGDX:

Code: Select all
04-14 21:29:36.223: E/AndroidRuntime(31700): java.lang.NoSuchMethodError: com.badlogic.gdx.graphics.Color.set
04-14 21:29:36.223: E/AndroidRuntime(31700):    at box2dLight.RayHandler.setAmbientLight(RayHandler.java:472)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.drawLevel(LHGame.java:1173)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.execute(LHGame.java:3327)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.onceTouched(LHGame.java:887)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.touch(LHGame.java:870)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHGame.render(LHGame.java:971)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.lib.MaApp.render(MaApp.java:249)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at magory.heroes.LHApp.render(LHApp.java:105)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:487)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
04-14 21:29:36.223: E/AndroidRuntime(31700):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)


I'm having the problem, too.
johnrico2000
 
Posts: 3
Joined: Thu Apr 11, 2013 8:11 pm

Re: box2dLights

Postby Magnesus » Mon Apr 15, 2013 9:43 pm

Workaround I've found: use setAmbientLight(new Color(r,g,b,a,)); instead of setAmbientLight(r,g,b,a). The Color.set(r,g,b,a) method is broken for some reason - I couldn't find how yet, but I'm still investigating - while Color.set(Color) works.
Magnesus
 
Posts: 1574
Joined: Sun Sep 25, 2011 3:50 pm

PreviousNext

Return to Showcase

Who is online

Users browsing this forum: No registered users and 6 guests