Hi, I ran into a problem and I’m wondering what would be the best solution to employ here…
I need to pass a command to Opengl (working in C++) in the form of:
glLightfv(GL_LIGHT0, GL_POSITION, float array[4]);
My Light class has an int glLightIndex, which holds the value specifying which light is it in opengl light number designation.
than I have a Scene object which has an array of 8 lights.
Now, I need to find a way so that I can pass proper light number to the above command.
For instance, say I have Light* lt. In the lightarray[] it is in index 0 and is therefore GL_LIGHT0 (and the glLightIndex is also set to 0). Therefore when I called the glLightfv, the first parameter would be GL_LIGHT0. If the light was a third light, index 2, then the command would be called with GL_LIGHT2, ok?
The problem I have is how can I do this?
My first thought was enum, like this:
enum GLlight { GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7};
and say light’s glLightIndex = 3, then Gllight[3] would return be GL_LIGHT3 and I could call the above function like:
glLightfv(Gllight[lt->glLightIndex], GL_POSITION, float array[4]);
but obviously enums don’t work that way.
Second tought was to use some function that would concatenate ‘GL_LIGHT’ + glLightIndex, but that would have to return a string or char*, so that’s no good either…
I guess I have no idea as to what type GL_LIGHT is and how I could dynamically call it.
Of course the easiest solution would be to create a switch statement with 8 glLightfv(…_ versions, but that’s pretty ugly coding imho… so… is there a better way?
Thank you,
Luke