Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes glBegin has any effect on lighting?
    primarykey
    data
    text
    <p>I'm working on a project using opengl (I'm a beginner) and I'm having trouble with lighting.</p> <p>I got 2 drawing methods: one for rendering and an other for picking facets. The rendering method seems ok since it's working properly when I comment the picking one. I tried a few things and found that it's the glBegin() call (in the "picking method") which provokes the issue: Does glBegin has any kind of effect on ligthing ?</p> <p>I set the lights like this:</p> <pre><code>void GLView::createLight(int LightID, const Vector3 &amp;Position, const Vector3 &amp;Color, const float* ambient) { glLightfv(LightID,GL_AMBIENT, ambient); glLightfv(LightID,GL_POSITION,&amp;Position.v[0]); glLightfv(LightID,GL_DIFFUSE,&amp;Color.v[0]); glEnable(LightID); } void GLView::setLights() { float diffuse[]={1,1,1,1}; float lmodel_ambient[4] = {0.5f, 0.5f, 0.5f, 0.5f}; float ambient_0[] = {0.0f,0.0f,0.0f,1.0f}; glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,&amp;diffuse[0]); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1); createLight(GL_LIGHT0,Vector3(0,0.3,1),Vector3(0.7,0.7,0.7),&amp;ambient_0[0]); createLight(GL_LIGHT1,Vector3(-1,0,0.3),Vector3(0.4,0.2,0),&amp;ambient_0[0]); createLight(GL_LIGHT2,Vector3(1,-0.2,0.1),Vector3(0,0.05,0.15),&amp;ambient_0[0]); } </code></pre> <p>Drawing methods:</p> <pre><code>void GLView::draw(TRenderStyle RenderStyle) { int W=width(); int H=height(); float WW=W/2; float HH=H/2; float Zoom=camera-&gt;Zoom*std::min(width(),height()); float Lens=HH/tan(FieldOfView/360*acos(-1)); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glDisable(GL_FOG); glDisable(GL_BLEND); glDisable(GL_LIGHTING); glColorMask(true,true,true,true); switch (RenderStyle) { case rsScene:{ //rendering } break; case rsMouseWindow: //for picking facets case rsMouseAction:{ glBegin(GL_TRIANGLES); //it's working fine if I comment these 2 lines glEnd(); } break; } } </code></pre> <p>I'm aware it's a vague question, but it really looks like glBegin is affecting lighting and I don't know what to do about it.</p> <p>Thanks for your help.</p> <p>***Edit: The problem is when glBegin() is called only the last initialized light is working.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload