About lighting and material on GL >= 3

I tried to see about this question on the wiki, and on google, but I didn’t find any information about this. If it was obvious, forgive me…

My interrest is about OpenGL 3 and above versions, and lighting and materials.

For doing lighting in GL, I use glEnable (GL_LIGHTING), glMaterialfv and so on to enable lighting calculations.
I actually do the same whether I use shaders or not.

However with shaders, I think it is possible to go beyond the OpenGL light number limitation, with sending uniforms, although I never did so. I hope I’m not wrong since here…

What I would like to know, is that if for GL 3 and above versions, we should still use glLight, glMaterial or if we should prefer to do it some other ways, for example, what I have in mind is the following:

. Use uniforms to enable some lights.
. Use vertex attributes to set materials.
. Use the previous in vertex/fragment shaders to do lighting calculations.

My main regard about this topic is to know if these functions (mainly lighting and material functions) are still up to date functions, if I can expect them to have a long future, or if my previous supposition (mainly about sending lights with uniforms and materials with vertex attributes) would/should become the way to manage lighting under GL.

From what I understood, nothing prevents me to send uniforms for lighting. However, I’m really unsure about this all and how to behave correctly.

What do you think about it ?

Compatibility mode (GL<3.0) will be around for a long time, so you don’t have to worry about their removal. There are examples on the web which show how to emulate the fixed-function lighting via shaders. The tutorial you would be interested in is titled “Recreating OpenGL’s Fixed Function Pipeline using Cg”.

Compatibility mode (GL<3.0)

Compatibility mode is not GL versions less than 3.0. Compatibility contexts are OpenGL contexts that implement the compatibility profile instead of the core profile. The compatibility profile retains the fixed-function pipeline and so forth, compared to the core profile.

Sorry, but this was not the answers I was expected. I know all about fixed pipeline, I do shaders since several years (even if old-style shaders)…

So, to try to be more simple, are there people here using shaders and lighting within shaders and who don’t use glLightfv, glMaterialfv and so on ? If yes are you doing it the way I thought ?

I don’t use glLightfv and glMaterialfv. I use GL 2.0.

For ambient, diffuse, specular, shininess, I use uniforms. You can use vertex attributes if you want.

I don’t enable lighting in my shaders. I have different shaders to do different lights. I try to avoid if/else as much as possible.

However with shaders, I think it is possible to go beyond the OpenGL light number limitation

You can have unlimited numbers of lights in opengl per scene. You just have to render with multiple passes and blend the results in the frame buffer.

V-man: OK, I see. Thank you.

dukey: thanks too, but I think I’ll try to avoid multipass as much as possible, only for lighting.