views:

40

answers:

2

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();
+4  A: 

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.

mikera
you're right, and my opengl book is wrong
rocity
Yep, if you want to use the 0-255 range, use glColor3ub(255, 0, 255);
Justin W
+1  A: 

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.

this is also a good solution
rocity