Thread: Lighting in OpenGL

  1. #1
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190

    Lighting in OpenGL

    Hi everybody,
    I'm writing a 2d game in OpenGL. Every object is a textured quad. These object are stored in an array and then applied on top of eachother (I'm using GL_MODELVIEW). Now I want to implement some lighting. I don't want to use GL_LIGHTING 'cause it's too expensive (and number of light sources is limited).

    Does anyone has any idea of how i can implement lighting without GL_LIGHT-s?

    thnx



    PS!
    I've already thought of editing textures (and lighten the screen pixel by pixel), but that's even more expensive than GL_LIGHTING (think of assigning textures to 2500 quads 30 times a second!).
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    What kind of lighting effects are you looking for? Spot lights? Directional lighting? If you doing a 2D game I don't think you're going to see a huge framerate problem due to opengl lighting. You might want to try it out and then evaluate if you need to do your own specialized lighting.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    OpenGL gives you up to Eight light sources Per Polygon. Just use one and reset its attributes to the nearest light source to whatever poly you are drawing.

    You could darken your entire scene and draw blended lightmaps on top.

    Or, even better, you could draw your light maps first, Im pretty sure you can setup the blend function to draw a pixel at an intensity based on what the pixel contains. Blend in any polys that are near light sources (they will be brighter where the light map was brighter), and then draw the rest at a dim level like glColor3f(0.2f,0.2f,0.2f). Thats how I would try to do it, but it depends on what exactly you want to get out of it and what would be the most practical based on your current implementation.

  4. #4
    I agree with MrWizard. Just use OpenGL's lighting. I mean, if full 3D games can use it, than I am sure your 2D game can use it

  5. #5
    Banned
    Join Date
    May 2004
    Posts
    129
    Have you ever done 3D? The reason I ask is that you say you are doing a 2D game, but in order to do your own lighting routines the mathematics for that is all in 3D, and you would probably just soon realize that it isn't worth the hassle.

  6. #6
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Like the others, I don't see why you are trying to avoid GL_LIGHTs for those reasons. But if you really want to, you can simply blend your textures with a black background.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shininess lighting GLUT OpenGL
    By Zishaan in forum Game Programming
    Replies: 1
    Last Post: 04-22-2007, 08:30 PM
  2. OpenGL lighting
    By Zishaan in forum Game Programming
    Replies: 6
    Last Post: 04-21-2007, 03:24 PM
  3. OpenGL lighting
    By BabyG in forum Game Programming
    Replies: 3
    Last Post: 08-29-2004, 09:58 AM
  4. OpenGL lighting problems
    By sirSolarius in forum Game Programming
    Replies: 0
    Last Post: 12-01-2003, 09:11 PM
  5. need help with opengl lighting!!
    By genghis37 in forum Game Programming
    Replies: 1
    Last Post: 06-22-2002, 12:28 AM