user500944
user500944

Reputation:

glGetFloatv with GL_CURRENT_COLOR does not work

I have some code that looks like this:

GLfloat c[4];
glGetFloatv(GL_CURRENT_COLOR, c);

I expect the current RGBA color to be written in array c after the call to glGetFloatv. However, the values in the array do not change at all (i.e. it contains the same garbage value both before and after the call to glGetFloatv).

Obviously I'm either misunderstanding the meaning of GL_CURRENT_COLOR (get the color that was previously set by a call to glColor4f) or doing something wrong...

P.S.: Also, this procedure might be called before any calls to glColor4f happen, but in that case I assume it should return (1.0, 1.0, 1.0, 1.0), right?

Edit: A call to glGetError after trying to obtain the color returns 0.

Upvotes: 4

Views: 2166

Answers (1)

genpfault
genpfault

Reputation: 52085

Workin' fine here:

#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;
}

Output:

Default color: 1 1 1 1
Should be red: 1 0 0 1

P.S.: Also, this procedure might be called before any calls to glColor4f happen, but in that case I assume it should return (1.0, 1.0, 1.0, 1.0), right?

"The initial value for the current color is (1, 1, 1, 1)."

Upvotes: 1

Related Questions