c++ - openGL - understanding colors changes due to lightning -
i writing software in c, render yellow , brown cube. once programmed light, colors changes light blue. explain me why colors changed? , how can prevent such extreme change?
this code used light:
glfloat color1 = {0.633, 0.237, 0.170}; \\ changed blue void initlight() { glfloat red[] = {1.0,0.0,0.0,1.0}; glfloat white[] = {1.0,1.0,1.0,1.0}; glfloat bluegreen[] = {0.0,0.4,1.0,1.0}; gllightmodelfv(gl_light_model_ambient, white); gllightfv(gl_light0,gl_ambient,white); gllightfv(gl_light0,gl_diffuse,bluegreen); glmaterialf(gl_front,gl_shininess,127.0); glenable(gl_light0); }
based on fact you're using immediate mode, assume wrote looks setting vertices?
glbegin(gl_triangles); glvertex3f(/*...*/); glcolor3f(/*...*/); /*...*/ glend();
when add lighting scene, renderer no longer considers color values proposed individual vertices, , instead substitutes in white or grey (causing light turn faces blueish-green). fix that, need tell renderer treat vertex colors material colors. code should sufficient:
glenable(gl_color_material);
this is, of course, reason why really, really should not using opengl's immediate mode or fixed function pipeline rendering, causes problems this. recommend tutorial found here learning modern opengl.
edit: fixed typo
double edit combo:
alright, there's few other things you'll need take account.
glfloat lp0[] = {4.0,4.0,3.0,0.0};
generally speaking, position vectors should have w
component (the last one) set 1, not 0. may want change to
glfloat lp0[] = {4.0,4.0,3.0,1.0};
beyond that, you'll want try playing around position, particularly using things matrix adjustments. again; yet reason not use ffp, , in case, it's because it's difficult tell light being positioned relative objects. putting @ <4,4,3>
in worldspace makes sense if know position being translated modelview , projection matrices correctly, , @ least in code i'm seeing, doesn't appear case.
Comments
Post a Comment