0
\$\begingroup\$

I have a very weird behavior of openGL's glColor right now.

I've wasted hours to detect why my line colors acting so weird until I found out that 0.0 rgb values is zero intensity and 5.0 lead to full intensity (yes NOT 1.0 it's not clamping!)

If I color a line with 1.0, 1.0 1.0 I get very dark grey instead of white. If I color a line with 5.0, 5.0 5.0 I get white. Here is my code:

gl.glDisable(GL2.GL_BLEND);
gl.glDisable(GL2.GL_TEXTURE_2D);

/* We need to disable any shaders to get colored lines */
gl.glUseProgramObjectARB(0);

gl.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE );
gl.glEnable(GL2.GL_COLOR_MATERIAL);

gl.glBegin(GL2.GL_LINES);
for (int lineIndex = 0; lineIndex < lineSegments.getNumberOfLines(); lineIndex++) {
  gl.glColor3d(5, 0, 0);
  //gl.glColor3dv(lineSegments.getLineColor(lineIndex).data(), 0);
  gl.glVertex3fv(lineSegments.getLineStartPoint(lineIndex).floatData(), 0);
  gl.glVertex3fv(lineSegments.getLineEndPoint(lineIndex).floatData(), 0);
}
gl.glEnd();

gl.glEnable(GL2.GL_TEXTURE_2D);
gl.glEnable(GL2.GL_BLEND);

Why is OpenGL acting so weird on glColor? Did I miss a gl state or something? I could scale up the colors so I bypass this, but I want to find out whats wrong here.

(The code example leads to a line that ist 100% red)

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You seem to use GL_AMBIENT_AND_DIFFUSE, what are your ambient and diffuse settings? \$\endgroup\$
    – Kromster
    Sep 27, 2016 at 17:50
  • \$\begingroup\$ I didn't set anything. I just added this glColorMaterial and enable COLOR_MATERIAL because I thought the glColor got ignored (I wasn't aware color was set because i tested it with (1,0,0) which is almost black). I just removed both glColorMaterial and enable COLOR_MATERIAL for testing and the behavior is exactly the same. \$\endgroup\$
    – Piranha
    Sep 27, 2016 at 18:01

1 Answer 1

2
\$\begingroup\$

I had to set gl.glDisable(GL2.GL_LIGHTING);

Now its working as expected.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .