在这里工作得很好:
#include <GL/glut.h>
#include <iostream>
using namespace std;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
GLfloat color[4];
glGetFloatv(GL_CURRENT_COLOR, color);
cout << "Default color: ";
for( size_t i = 0; i < 4; i++ )
cout << color[i] << " ";
cout << endl;
glColor3ub( 255,0,0 );
glGetFloatv(GL_CURRENT_COLOR, color);
cout << "Should be red: ";
for( size_t i = 0; i < 4; i++ )
cout << color[i] << " ";
cout << endl;
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(200,200);
glutCreateWindow("Color");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
输出:
Default color: 1 1 1 1
Should be red: 1 0 0 1
PS:另外,这个过程可能会在调用 glColor4f 之前被调用,但在这种情况下,我假设它应该返回 (1.0, 1.0, 1.0, 1.0),对吧?
“当前颜色的初始值为 (1, 1, 1, 1)。”