Hey guys, I'm lurking around for a while now but this is my first post, so big hello to you all! I'm just getting started with OpenGL and game development so please bear with me guys.So I've come to the point that I can create all the shapes what I want to, I can handle transformations, and know how to use textures.I thought that the next step will be 2D lights and shadows but I just can't get it working.I've read the articles and visited links featured on this forum about it, and I do understand that I should cast "rays" from my lighting spot to all the vertices and then mask away the non visible parts, my only problem is that I don't know how should I do that? Also I don't really understand how to make a lighting source which attenuates with distance.My thoughts about that is that I just render multiple circles with different opacity, but this sounds like a horrible idea.For my other problem (lighting and shadows) I've came up with my own crappy solution:What I do is that I render a light yellow circle with the radius of the light source and low alpha value, then I go through my vertices stored in an ArrayList and check if they're in the radius of the circle and if so then I do extend the vector with "remaining" length (which is getting calculated like this: I calculate the distance between the center of the rendered circle and the vertex and and I substract my radius with it) and I create a vertex at the casted spot (the crossing point of my ray and the vertex) and at the end of the extended vector. I do this with all of the vertices (per object) so I get a black polygon at the end. I know this is really bad solution, altough I've spent a lot of time to make it.Here's a picture presentating my method (and it's fault when I move light source too close):

I would really appreciate any help.Thank you all guys, have a nice day

Well, if I understand the code what you gave me correctly then this is exactly what I do right now:I have a radius to light up, calculate the dark areas and fill them in with polygons.My only problem is that as you can see on my second picture it's not perfect since the polygon doesn't have as much vertexes as my circle do, and even if it would work I wouldn't be really happy about the result (I kinda want that attenuation).Maybe I've messed up something, here's my code (it's getting runned for every vertex as you can see):

Box2dLights use similar solution. Lights are casting bunch of rays circularly around world and from collision data I make mesh that is rendered with triangle strips. Maybe you could look that code a bit for pointers.

Okay, so after some day I've come up with a solution for attenuation with a simple fragment shader. If anyone else thinking about creating 2D lighting check out my shader: http://glsl.heroku.com/e#5900.4Also I have to mention that I'm really newbie when it comes to shaders, I've started to learn them 3 hours ago so I'm pretty sure this could be improved, however, it's seems like a nice starting point.

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