C++ OpenGL lighting only lights certain walls -
i lighting scene in opengl , there 4 walls, 2 of them beingness lit. think wrong normals not sure.
this lighting code:
glshademodel(gl_smooth); //glenable(gl_cull_face); glenable(gl_lighting); glenable(gl_light0); glenable(gl_light1); glfloat lightpos0[] = {-5, 1, 0, 0.}; glfloat ambientlight0[] = {0.2, 0.2, 0.2,1.0}; glfloat diffuselight0[] = {0.8, 0.8, 0.8,1.0}; glfloat specularlight0[] = {1.0, 1.0, 1.0,1.0}; gllightfv(gl_light0, gl_position, lightpos0); gllightfv(gl_light0, gl_ambient, ambientlight0); gllightfv(gl_light0, gl_diffuse, diffuselight0); gllightfv(gl_light0, gl_specular, specularlight0); glfloat lightpos1[] = {5, 1, 0, 0}; glfloat ambientlight1[] = {0.2, 0.2, 0.2,1.0}; glfloat diffuselight1[] = {0.8, 0.8, 0.8,1.0}; glfloat specularlight1[] = {1.0, 1.0, 1.0,1.0}; gllightfv(gl_light1, gl_position, lightpos1); gllightfv(gl_light1, gl_ambient, ambientlight1); gllightfv(gl_light1, gl_diffuse, diffuselight1); gllightfv(gl_light1, gl_specular, specularlight1);
this code drawing 4 walls.
//north glbegin(gl_quads); glnormal3f(1.0,0,0); glvertex3f(-10,0,-10); glvertex3f( 10,0,-10); glvertex3f( 10,5,-10); glvertex3f(-10,5,-10); glend(); //south glbegin(gl_quads); glnormal3f(-1.0, 0, 0); glvertex3f(-10,0, 10); glvertex3f( 10,0, 10); glvertex3f( 10,5, 10); glvertex3f(-10,5, 10); glend(); //east glbegin(gl_quads); glnormal3f(0,0, -1.0); glvertex3f( 10,0,-10); glvertex3f( 10,0,10); glvertex3f( 10,5,10); glvertex3f( 10,5,-10); glend(); //west glbegin(gl_quads); glnormal3f(0,0,1.0); glvertex3f( -10,0,-10); glvertex3f( -10,0,10); glvertex3f( -10,5,10); glvertex3f( -10,5,-10); glend();
if helps, here's , image of whats happening: http://i.stack.imgur.com/xrgvl.png
it seems pass wrong normal vector walls.
if wall got z = -10 points (wall parallel x), must have normal vector directed in positive direction of z: (0,0,1). same true directions.
try this:
glbegin(gl_quads); glnormal3f(0,0,1); glvertex3f(-10,0,-10); glvertex3f( 10,0,-10); glvertex3f( 10,5,-10); glvertex3f(-10,5,-10); glend(); //south glbegin(gl_quads); glnormal3f(0, 0, -1); glvertex3f(-10,0, 10); glvertex3f( 10,0, 10); glvertex3f( 10,5, 10); glvertex3f(-10,5, 10); glend(); //east glbegin(gl_quads); glnormal3f(-1,0, -0); glvertex3f( 10,0,-10); glvertex3f( 10,0,10); glvertex3f( 10,5,10); glvertex3f( 10,5,-10); glend(); //west glbegin(gl_quads); glnormal3f(1, 0, 0); glvertex3f( -10,0,-10); glvertex3f( -10,0,10); glvertex3f( -10,5,10); glvertex3f( -10,5,-10); glend();
c++ opengl lighting
No comments:
Post a Comment