Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (762)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (847)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Simplistic 2d lighting in lwjgl  (Read 4048 times)
0 Members and 1 Guest are viewing this topic.
Offline Magn

Senior Newbie





« Posted 2014-08-16 18:00:44 »

Greeting everyone.

I currently am preparing a port of my 2d plain java game to lwjgl. The game is tilebased and currently uses per-pixel rendering in pure java.
I have made a test version with lwjgl and everything seems to run pretty smooth.
Though I have encountered one problem(as I'm not that familiar with lwjgl and opengl) of porting the game. In the pure java version the game achieves lighting by adjusting the rgb value of each individual pixel as they are rendered.
The lighting is tile-based and each tile-light value is stored in array(which is only updated whenever a new lightsource is placed), from which the rgb values are adjusted.
Picture showing the lighting:

Here the light around the bonfire is slightly tinted. The rest is just the rgb values lowered(if it is an entity, the light value is based).
What would be a good way to implement such a 'simple' form of light in lwjgl?
Offline trollwarrior1
« Reply #1 - Posted 2014-08-16 18:12:44 »

The simplest way would be to just use shaders and apply lighting to every fragment you render. The correct way is to render lighting mask to a texture, and then blend the lighting texture to the scene, but that is a little bit more complex to do with LWJGL.
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 485
Exp: 7 years



« Reply #2 - Posted 2014-08-16 18:15:00 »

Simple way:

Store a 1x1 white square texture.
Render it at varying alphas and tint colors stretched over the tiles to be lit.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Rayvolution

« JGO Spiffy Duke »


Medals: 379
Projects: 2
Exp: 2 years


Resident Crazyman


« Reply #3 - Posted 2014-08-16 18:40:16 »

Simple way:

Store a 1x1 white square texture.
Render it at varying alphas and tint colors stretched over the tiles to be lit.

..and make sure to either:
- Position it with an int, not a float. (Although this can cause trouble if your other graphics are positioned with floats. Might look funny sometimes)
- Render all the lights as one FBO.

Reason being is when dealing with scaled artwork, sometimes you get a strange overlap problem with doing sub pixel movement, and you'll end up with bright "gridlines" around your light sources sometimes as the two tiles slightly overlap and double the alpha levels in that one spot..

- Raymond "Rayvolution" Doerr.
Retro-Pixel Castles - Now on Steam!
LIVE-STREAMING DEVELOPMENT: http://www.hitbox.tv/rayvolution
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 485
Exp: 7 years



« Reply #4 - Posted 2014-08-16 18:56:21 »

True. But I assume he'll have already figured out tiles, as that's what his game is.
Could also just have a 32x32 light mask or whatever size it needs to be.
Offline Magn

Senior Newbie





« Reply #5 - Posted 2014-08-16 20:20:26 »

Simple way:

Store a 1x1 white square texture.
Render it at varying alphas and tint colors stretched over the tiles to be lit.
Thanks. That would be perfect for the tiles!

But entities like trees should also have lighting applied(value based on what tile they are placed on).
Offline Magn

Senior Newbie





« Reply #6 - Posted 2014-08-16 20:33:41 »

The simplest way would be to just use shaders and apply lighting to every fragment you render. The correct way is to render lighting mask to a texture, and then blend the lighting texture to the scene, but that is a little bit more complex to do with LWJGL.
Thank you. I'm gonna go with shaders for now  Smiley
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (364 views)
2018-06-10 19:43:48

EgonOlsen (364 views)
2018-06-10 19:43:44

EgonOlsen (304 views)
2018-06-10 19:43:20

DesertCoockie (540 views)
2018-05-13 18:23:11

nelsongames (869 views)
2018-04-24 18:15:36

nelsongames (852 views)
2018-04-24 18:14:32

ivj94 (1303 views)
2018-03-24 14:47:39

ivj94 (424 views)
2018-03-24 14:46:31

ivj94 (1087 views)
2018-03-24 14:43:53

Solater (442 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!