Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glColor3i only drawing black

Why does this only draw black?

 glPushMatrix();
 // Check the current color
 glColor3i(255, 0, 255);
 GLint currentColor[4];
 glGetIntegerv(GL_CURRENT_COLOR, currentColor);
 //currentColor[0] = 254, 1 = 0, 2 = 254, 3 = doesn't matter

 glBegin(GL_QUADS);
 glLineWidth(1);
  glVertex2f(0, 0);
  glVertex2f(WINDOW_WIDTH * .1, 0);
  glVertex2f(WINDOW_WIDTH * .1, WINDOW_HEIGHT);
  glVertex2f(0, WINDOW_HEIGHT);
 glEnd();
 glPopMatrix();
like image 566
mike_haney Avatar asked Oct 24 '10 19:10

mike_haney


2 Answers

From memory, I think that glColor3i uses colour values that are scaled to cover the full integer range. Hence your 255 values are approximately equal to zero.....

Try 2147483647 instead.

like image 122
mikera Avatar answered Oct 14 '22 20:10

mikera


All typed integral gl entrypoints have this range behavior. Floating point variants use normalized values: 0.0 - 1.0. glColor sets the current vertex color which even affects the output during vertex array processing if glColorPointer is not enabled (if indeed your version of GL uses named vertex attributes and not generic as in OpenGLES 2.x and greater).

Common variants for glColor are glColor{3,4}{u,b} and glColor{3,4}f.

In your case you should stick to your 0xFF values and use glColor3ub(255, 0, 255) or perhaps easier glColor3f(1.0f, 0.0f, 1.0f).

Using an integral value of INT_MAX or ~2 billion in conjunction with glColor3i() doesn't read very well.

like image 43
user487158 Avatar answered Oct 14 '22 21:10

user487158