Home arrow Multimedia arrow Page 3 - Basic Lighting in OpenGL and SDL Game Programming

Lighting Model - Multimedia

Lighting is one of the components of a game that can provide an immersive reality to the player -- or be so distracting that playing becomes difficult. To ease working with lighting, OpenGL provides simplified API. The focus of this discussion will be on the basics of using lighting API provided by OpenGL. This article is the latest part in a multi-part series on game programming with OpenGL and SDL.

TABLE OF CONTENTS:
  1. Basic Lighting in OpenGL and SDL Game Programming
  2. Implementing Lighting, Step by Step
  3. Lighting Model
  4. Lighting in the Real World
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 3
December 09, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The final step is to choose a lighting model. The lighting model determines two things. First, it determines whether the user is viewing the scene from an infinite distance or locally. If the user is considered to be viewing from an infinite distance, the angle of light and that of the viewer is ignored. The result
will be unrealistic lighting. Secondly, the lighting model determines whether or not the front and back surface calculations for an object need to be done separately.

To choose a lighting model, the glLightModel*() method is used. This method, or command as it is known in OpenGL, is used to set the amount of global ambient light that will be cast on the objects on the scene.

One of the variants of glLightModel*() is glLightModelfv(). It takes a parameter telling OpenGL that global ambient light needs to be set, and the array defining the color of global ambient light. For example, to set the global ambient light with the color having values of 0.5f, 0.5f, 0.5f and 1.0f, the statements will be:

Glfloat global_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);

That completes the steps necessary for implementing basic lighting in an application or game. In the next section, basic lighting will be added to the existing framework.



 
 
>>> More Multimedia Articles          >>> More By A.P.Rajshekhar
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

MULTIMEDIA ARTICLES

- Basic Lighting in OpenGL and SDL Game Progra...
- Working with Colors in OpenGL for Game Progr...
- Animation in OpenGL for Game Programming usi...
- Game Programming with SDL: Getting Started w...
- Using OpenGL with SDL for Game Programming
- Learning Sound for Game Programming using SDL
- Game Programming using SDL: Raw Graphics and...
- Game Programming using SDL: Getting Started
- Network Radio With Icecast
- Learning To SMILe

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: