Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

880187 Posts in 33024 Topics- by 24392 Members - Latest Member: mfroeschl

May 25, 2013, 11:51:48 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)OpenGL lighting
Pages: [1]
Print
Author Topic: OpenGL lighting  (Read 791 times)
gupta_shvm
Level 0
**


View Profile Email
« on: July 11, 2012, 04:34:18 AM »

Hi everyone. I'm new to OpenGL and I was just wondering if glLight is supposed to work in glOrtho mode. If not, any recommendations on how to do 2D lighting in OpenGL?

Also, if not is there anyway to set up gluPerspective() so that it uses pixel coords? By that I mean so that you can go glVertex3f(-50, -50, 0) instead of like glVertex3f(-0.2, -0.2, 0)?

Thanks in advance
Logged
zacaj
Level 3
***


void main()


View Profile WWW Email
« Reply #1 on: July 11, 2012, 04:41:25 AM »

2d lighting doesn't make sense physically. What are you trying to do? In perspective the scale changes with depth so there isn't a way to make it a certain pixel amount. You could calculate what depth would give a certain resolution, I guess....
Logged

My twitter: @zacaj_

Quote from: mcc
Well let's just take a look at this "getting started" page and see--
Quote
Download and install cmake
Noooooooo
gupta_shvm
Level 0
**


View Profile Email
« Reply #2 on: July 11, 2012, 08:28:13 AM »

hmm.. well that makes sense...
do you recommend using glOrtho or gluPerspective for 2d games?
before this I've only done SDL so I can't really wrap my head around how things like collision detection would happen if size varies with depth.. so I'm kinda confused..
Right now I'm thinking that I should stick to Orthogonal.. but then I guess I'd be stuck with static lighting. So I'm wondering how dynamic lighting can be done using glOrtho..
Logged
zacaj
Level 3
***


void main()


View Profile WWW Email
« Reply #3 on: July 11, 2012, 08:32:05 AM »

I'd recommend ortho. Like I said though, normal 3D lighting like opengl supports by default isn't for 2D. Enabling perspective won't change the fact that lighting doesn't work in 2D because traditional 2D world's aren't actually physically possible. You're going to be simulating how you think but would work somehow, so you'll need to explain how you think the lighting would work first
Logged

My twitter: @zacaj_

Quote from: mcc
Well let's just take a look at this "getting started" page and see--
Quote
Download and install cmake
Noooooooo
gupta_shvm
Level 0
**


View Profile Email
« Reply #4 on: July 11, 2012, 08:54:10 AM »

I was thinking something like the way lighting works in super meat boy.
Logged
zacaj
Level 3
***


void main()


View Profile WWW Email
« Reply #5 on: July 11, 2012, 11:59:31 AM »

I never noticed any lighting in SMB....

Logged

My twitter: @zacaj_

Quote from: mcc
Well let's just take a look at this "getting started" page and see--
Quote
Download and install cmake
Noooooooo
Sam
Level 3
***



View Profile WWW
« Reply #6 on: July 11, 2012, 12:34:44 PM »

I guess he means the shadows that appear on some levels. In which case I'll shamelessly link to a tutorial I wrote about 2d shadows on this very forum.

In that I talk about drawing the shadows as polygonal objects using Flash's graphics API. But you can write a vertex shader that'll correctly project the vertices making up a shadow shape, very similar to creating shadow volumes in the 3d shadowing technique made famous in Doom3.
Logged
gupta_shvm
Level 0
**


View Profile Email
« Reply #7 on: July 11, 2012, 07:57:09 PM »

Thanks for the tutorial on shadows but I was talking about the dynamic lighting on some levels like level 2 of world 1 for instance. Go play the level and you'll notice the lighting near the platform at the top of the wall. Let me know if you know how that was done. Thanks in advance.
Logged
quixoticproject
Level 0
*


just looking around


View Profile WWW
« Reply #8 on: July 12, 2012, 02:06:07 AM »

Orthographic projection is just another way to setup the projection matrix. The scene does not get "2D" it is just rendered with a different projection matrix. Therefore everything should just work as when using a "normal" perspective projection matrix.   
Logged

Sam
Level 3
***



View Profile WWW
« Reply #9 on: July 12, 2012, 02:23:03 AM »

I feel there's a lesson to be learnt in this thread on asking a clear question.

So, here's what I assume you mean from 1-2 in Super Meat Boy


I'm guessing you're referring to the way that part of the background is lit up and part not, with those areas separated by by the circled line?
The area to be illuminated is found using just the kind of technique described in that tutorial I linked, with the polygonal outline of solid platforms being shadow casters. The lighting effect itself is an overlaid (subtly animated, in the case of Super Meat Boy) quad (either screen sized or with SMB's small levels, level sized). It probably uses the stencil buffer as set by rendering shadow shapes to determine where should be illuminated. The lighting quad is rendered using some kind of additive and/or multiplicative blend mode so that it brightens the background.

Interestingly if you press F11 while in-game it will toggle rendering of the lighting effect so you can easily see exactly what it's doing.

If that isn't what you're asking about, you're really going to have to be more clear.
Logged
gupta_shvm
Level 0
**


View Profile Email
« Reply #10 on: July 12, 2012, 04:07:22 AM »

Yes this is what I was talking about. Thanks and sorry for the confusion. Will try to be clearer in my posts from now on.  Sad
Logged
Cheezmeister
Level 0
***



View Profile
« Reply #11 on: July 17, 2012, 06:53:45 PM »

It seems like you're not grokking the way OpenGL works on a fundamental level. It doesn't help that the vast majority of tutorial out there are still focusing on the FFP. If you're going for 3D, (or even if you're not, but want a solid foundation for 2D GL) I highly suggest reading this tutorial http://www.arcsynthesis.org/gltut/. For 2D, you can probably get away with an ortho projection, but it might make your life easier to start with SDL.
Logged

Procrastinating on: Nextris, Chromathud, Spheres of Influence | More at http://luchenlabs.com/projects
My heart goes out to you for asking a simple question and getting a million complicated answers; it's sort of how this forum works... -Evan Balster
gupta_shvm
Level 0
**


View Profile Email
« Reply #12 on: July 24, 2012, 03:18:05 AM »

It seems like you're not grokking the way OpenGL works on a fundamental level. It doesn't help that the vast majority of tutorial out there are still focusing on the FFP. If you're going for 3D, (or even if you're not, but want a solid foundation for 2D GL) I highly suggest reading this tutorial http://www.arcsynthesis.org/gltut/. For 2D, you can probably get away with an ortho projection, but it might make your life easier to start with SDL.

I've been vanilla SDL for a while now but wanted to start using OpenGL.. I understand how it works better now anyway..
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic