I am working on a "game engine" and right now Im trying to implement the part of it that is handeling lights.
Im using openGL, and in order to create a light in openGL you do this, where lightID is the total amount of lights currently in the scene:
Right now I am keeping lightID as a global and increment it every time I create a new light. It works, but I would prefer to avoid using globals. Also, if I delete a light, there is no way of telling that that id is now free.
glEnable(GL_LIGHT0 + lightID)
glLightfv(GL_LIGHT0 + m_lightID, OpenGLoptionFlag, yourdata);
Im thinking of changing it to work like this:
* Directional and ambient are derived from Light.
public DirectionalLight* createDirectionalLight(/*parameters*/);
public AmbientLight* createAmbientLight(/*parameters*/);
public void deleteLight(Light* light);
typedef std::pair<unsigned int, bool> LightID;
* When the initialise function is called, it will populate the m_lights array with IDs that can be used for the lightID that is passes to openGL.
* If a light is created, the std:air changes to be true, if it is deleted, it changes to false(can be used for creating a new light)
* the destructor for the lights are private and the lights are friends of the factory, so the factory can call the destructor.
* the factory holds pointers to all the lights created, so that It can delete them if the factory itself is destroyed.
Is this a good way of doing it, or am I walking down the wrong road here?