can't see lighting in openGL -


i'm new opengl , drew cube, place camera inside cube. i'm trying achieve lighting cube. how tried:

void draw(glfwwindow* window) {     glenable(gl_lighting);     glenable(gl_light0);      // create light components     glfloat ambientlight[] = { 0.2f, 0.2f, 0.2f, 1.0f };     glfloat diffuselight[] = { 0.8f, 0.8f, 0.8, 1.0f };     glfloat specularlight[] = { 0.5f, 0.5f, 0.5f, 1.0f };     glfloat position[] = { -1.5f, 1.0f, -1.0f, 1.0f };      // assign created components gl_light0     gllightfv(gl_light0, gl_ambient, ambientlight);     gllightfv(gl_light0, gl_diffuse, diffuselight);     gllightfv(gl_light0, gl_specular, specularlight);     gllightfv(gl_light0, gl_position, position);      int width, height;     glfwgetframebuffersize(window, &width, &height);      glviewport(0, 0, width, height);     glclear(gl_color_buffer_bit | gl_depth_buffer_bit);      glm::mat4 projection = glm::perspective(pi / 4, 1.f / 1.f, 1.0f, 10.0f);     glm::mat4 view = glm::lookat(glm::vec3(0.0f, 0.0f, -1.3f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));     glm::mat4 model = glm::rotate(glm::mat4(1.f), pi, glm::vec3(0.0f, 1.0f, 0.0f)); .... .... } 

but don't see lightings

but don't see lightings

welcome world of old-and-busted fixed function pipeline. you're using opengl done 20 years ago. mode of illumination you're using doing lighting calculations @ vertex locations , blends resulting color on triangles (or quads). won't work if there's lot of change in illumination on span of single triangle.

in case light source close cube, that's not going work. should address ditching fixed function pipeline (ffp) , use shaders. seriously, ffp has been out of fashion 13 years (first glsl capable gpus arrived on market in 2003). ffp has been emulated shaders created in-situ ever since.

also (judging other questions related drawing cube) don't supply face normals. normals essential doing illumination calculations, you'll have supply well.


Comments