How to get vertex color ?

I’m looking for some simple method to get color of a given vertex without reading [LEFT][/LEFT]pixels. I mean, color of a vertex in smooth shading that take into account all light sources and material properties.

Well, there isn’t one (in general). Information in OpenGL flows in one direction: from the user to the screen, in accord with the OpenGL rendering pipeline. You can’t interrupt this process and have OpenGL spit out some arbitrary values for you.

To be fair, via image load/store, SSBOs or transform feedback, you can coerce OpenGL into spitting out data of various kinds. But none of these are a “simple method”; they require shader logic. Well, except for TF, which can work in the fixed-function pipeline. That would probably be your best bet, but even then, it’s hardly “simple”.

If you’re using the fixed-function pipeline, you can use glRenderMode(GL_FEEDBACK). Note that this applies after culling; no data will be returned for culled polygons. Polygons and quads may be decomposed to triangles.

The modern equivalent is transform-feedback mode (glBeginTransformFeedback() etc).

Thanks for replies ! I see, it isn’t so simple as I thought.

I’ll try GL_FEEDBACK, but probably, it will be easier to compute vertex colors by myself.
So another related question: How can I get all the relevant data about the lighting ( position of all light sources and their parameters ) ?

In theory you should now them, because your application has to set them at some point. To query them from OpenGL you can use glGetLight. Lighting normally operates on the colors specified by the current material (query settings with glGetMaterial), unless you enable GL_COLOR_MATERIAL to make use of the per-vertex color instead (see glColorMaterial).

In any case recreating the entire lighting calculations (especially if you need them to be correct for all kinds of state combinations) is also quite some work, although the formulae are all documented. Perhaps there is a different way to do what you want?