Note that there are some explanatory texts on larger screens.

plurals
  1. POLighting issues in OpenGL
    primarykey
    data
    text
    <p>I have a triangle mesh that has no texture, but a set color ( sort of blue ) and alpha ( 0.7f ). This mesh is run time generated and the normals are correct. I find that with lighting on, the color of my object changes as it moves around the level. Also, the lighting doesn't look right. When i draw this object, this is the code:</p> <pre><code>glEnable( GL_COLOR_MATERIAL ); float matColor[] = { cur-&gt;GetRed(), cur-&gt;GetGreen(), cur-&gt;GetBlue(), cur-&gt;GetAlpha() }; float white[] = { 0.3f, 0.3f, 0.3f, 1.0f }; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matColor); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white); </code></pre> <p>Another odd thing i noticed is that the lighting fails when i disable GL_FRONT_AND_BACK and use just GL_FRONT or GL_BACK. Here is my lighting set up ( done once at beginning of renderer ):</p> <pre><code>m_lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; m_lightSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; m_lightPosition[] = { 0.0f, 1200.0f, 0.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, m_lightAmbient); glLightfv(GL_LIGHT0, GL_SPECULAR, m_lightSpecular); glLightfv(GL_LIGHT0, GL_POSITION, m_lightPosition); </code></pre> <p>EDIT: I've done a lot to make the normals "more" correct ( since i'm generating the surface myself ), but the objects color still changes depending where it is. Why is this? Does openGL have some special environment blending i don't know about? EDIT: Turns out the color changing was because a previous texture was on the texture stack, and even though it wasn't being drawn, glMaterialfv was blending with it.</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.
 

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