Jump to content

  • Log In with Google      Sign In   
  • Create Account

"Lighting" with OpenGL 2D graphics


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 barney1   Members   -  Reputation: 101

Like
0Likes
Like

Posted 06 February 2012 - 09:09 AM

Hello OpenGL/ graphics experts. I'm looking to add some artificial "lighting" textures to my 2d game. Does anyone have a simple explanation for how to do this? Here's what I mean:

I'm currently doing a 2d game by making simple calls to glDrawTexfOES to draw my sprites. Now, the sprites are pretty simple and mostly solid colors. What I want to do is make spots of the screen look like they are lit more than others. I have done some searching and it seems this could be done with a "flashlight" texture, which as I understand is just a circle in the middle of a texture with necessary transparency.

I'm not sure I understand how to do this? What part of the texture should be transparent? And how should I blend the texture after applying it?

Thanks for any help.

Sponsor:

#2 stevo86   Members   -  Reputation: 150

Like
0Likes
Like

Posted 11 February 2012 - 02:43 AM

I'm not sure exactly how you handle your textures, but if you're not already using PNG, I'd recommend using it as this will probably be easier if you do. Anyways...

To do flashlight lighting, you'd want to create a blank image (as in transparent background) in your paint program. Then just draw a spherical gradient from white to transparent in the center of the image. Save that as the light. In your code you then load the image and enable blending (glEnable(GL_BLEND)) and set the blending function to glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); and draw your light quad with the light texture on it. Probably want to set the transparency down on it too, maybe set glColor4f(1, 1, 1, 0.7f); or something so the things underneath it still show through.

I could be mistaken on the exact parameters for the blend func, I haven't played with it in a while and I haven't started implementing the lighting in my current project so I'm not totally up on it, but a quick Google on glBlendFunc can list the different choices and if you just plugin a few different combinations you'll find the one you're looking for.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS