Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (498)
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  
  OpenGL and top down 2d lighting?  (Read 539 times)
0 Members and 1 Guest are viewing this topic.
Offline Dxu1994
« Posted 2013-10-10 02:31:15 »

Hey JGO,

I was wondering if anyone here knows how to do a "fake lighting" effect in OpenGL?

At the moment I'm raycasting rays in all directions from the centre of the player, making a list of the hit vertexes and drawing a TriangleFan with those vertexes.

I was wondering if anyone knew a better approach to this?

Thanks in advance!

Offline wessles

JGO Ninja

Medals: 49
Projects: 4
Exp: 3 years

Coding with bad posture since 2011... Nonstop.

« Reply #1 - Posted 2013-10-10 02:49:05 »

Well, off the top of my head (but never tried), there is a HUGE page on just this here on JGO. It is great! It looks pretty complex though, but if you are up for the challenge: here.

You don't know nerdiness yet; you haven't even met me!
Offline opiop65

JGO Kernel

Medals: 123
Projects: 7
Exp: 3 years

Team Alluminum

« Reply #2 - Posted 2013-10-10 02:58:59 »

You should most likely use box2D.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel

Medals: 212
Projects: 11
Exp: 2 years

If it wasn't Awesome, it wasn't me.

« Reply #3 - Posted 2013-10-10 03:29:57 »

This is quite a nice technique, and can be done without complex raycasting.

Offline Abuse

JGO Coder

Medals: 10

falling into the abyss of reality

« Reply #4 - Posted 2013-10-10 04:32:33 »

Funnily, I've just implemented an algorithm to do this in Java2d Smiley

Though I'm rewriting it atm to change the way the level is represented, so it'll be simpler to procedurally generate level data.

I doubt it'll be of much use if you're using ogl, but if you like I can post the code once I've refactored & neatened everything up a bit.

A quick overview of the algo:

- map defined as a maze of interconnected convex polygons
- lights are arcs (mathematical 'sector'), with an origin, radius, start & end angles.
- lights are rendered as gradient fill circles (pre-rendered to an image if you want extra speed), and are drawn through a polygon clip.
- the polygon clip is constructed by:
   - cast 1 ray out from light origin along start angle, looking for edge intersection with the polygon currently containing the light.
   - If the intersected edge is a wall (rather than a doorway into another polygon), add the intersection point as a vertex to your clip polygon.
   - walk around polygon's vertices, adding each as a vertex to your clip polygon.
   - once you reach a vertex that that lies beyond the light's end angle, cast a 2nd ray to find the intersection point
   - for each edge you walk around that is a doorway into another convex polygon (and is inside the radius of the light), process it recursively using the same algorithm.

Computationally it's very cheap; my initial implementation could render 1000+ clipped light sources @ 60fps.

There are of course limitations; no spot effect (focal point), no smooth transitions at the start/end of the light arc (sector), no surface specific lighting.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.


Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (15 views)
2014-04-15 18:08:23

BurntPizza (13 views)
2014-04-15 03:46:01

UprightPath (27 views)
2014-04-14 17:39:50

UprightPath (12 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (51 views)
2014-04-10 04:04:31

BurntPizza (110 views)
2014-04-08 23:06:04

tom_mai78101 (211 views)
2014-04-05 13:34:39

trollwarrior1 (179 views)
2014-04-04 12:06:45

CJLetsGame (185 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20 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‑
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!