Open GL Lighting Problem

I’ve been working on the game engine for a month now, and I have completed the basic OpenGL material. However, one thing I can’t work with as I expect is lighting. (Note: this is the first time I've seriously worked with OpenGL)

What I want is proximity to realistic lighting modeling, where surfaces facing the light are illuminated more than those further away, etc. The main light should have position and color. Here's how I thought it could be implemented:

float lightv[4]; // populated with (0.6, 0.6, 0.6, 1)
float positionv[4]; // populated with (0, 10, 0, 1)
int lightID = GL_LIGHT0;
int attenuationType = GL_LINEAR_ATTENUATION;
float attenuationValue = 1;
glLightf(lightID, attenuationType, attenuationValue);
glLightfv(lightID, GL_DIFFUSE, lightv);
glLightfv(lightID, GL_POSITION, positionv);
glEnable(lightID);

Instead of doing what I expect from it, it gives me lighting, as if there was a light where the camera is! Each surface has the same lighting!

What am I doing wrong?

Thanks, I appreciate it.

+3
2

, , , - glEnable(GL_LIGHTING);. , , , , . , , . , , . , . , , , , Modelview, . , , - .

+2

GL_MODELVIEW, . "", .

0

Source: https://habr.com/ru/post/1772763/


All Articles