glColor3f in OpenGl have little brightness

1.5k Views Asked by At

I have a problem with my code in OpenGl I need to do a game engine. I use freeglut library. I did this practise with old Visual Studio versions and I don't have this problem. But with the Visual Studio 2017 the attribute glColor3f is showed with little brightness. Why?

This is the code that I use for to show the texts:

char instrucciones3[100];
sprintf_s(instrucciones3, "PULSA 'ESC' SI QUIERES SALIR");
char *res4 = instrucciones3;
glColor3f(0.0f, 1.0f, 1.0f); //This is the problem, I dont have alpha but the brightness is low.
glRasterPos3f(1.0f, 5.0f, 0.0f);
drawString(res4);

char instrucciones2[100];
sprintf_s(instrucciones2, "PULSA 'H' PARA COMENZAR PARTIDA ");
char *res3 = instrucciones2;
glColor3f(0.0f, 1.0f, 1.0f);
glRasterPos3f(-10.0f, 5.0f, 0.0f);
drawString(res3);

Update:

This is the result of my code

The brightness is so low, but the model is good. I put glColor3f(0.0f, 1.0f, 1.0f); in the new code but the result is the same.


Update2 This is my displayMe func:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0, 3, 15, 0, 0, 0, 0, 1, 0);

glRotatef(yaw, 0.0, 1.0, 0.0);
glRotatef(pitch, 1.0, 0.0, 0.0);
glRotatef(roll, 0.0, 0.0, 1.0);
GLfloat lightpos[] = { 5.0, 15., 5., 0. };
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
2

There are 2 best solutions below

4
On BEST ANSWER

The fixed function light model is applied on the text, too. This will cause arbitrary results, dependent on the current light settings ans current normal vector attribute. You have to disable lighting before you draw the text.

glDisable(GL_LIGHTING);

and you have to enable it before you draw the geometry

glEnable(GL_LIGHTING);

The parameters to glColor3f have to be floating point values in the range [0.0, 1.0],

glColor3f(0.0f, 1.0f, 1.0f);

in compare to glColor3ub, where the parameters are integral values in the range [0, 255].

glColor3ub(0, 255, 255);

See OpenGL Specification (Version 2.0) - 2.7. VERTEX SPECIFICATION; page 21

The commands to set RGBA colors are

void Color{34}{bsifd ubusui}( T components );
void Color{34}{bsifd ubusui}v( T components );

The Color command has two major variants: Color3 and Color4. The four value versions set all four values. The three value versions set R, G, and B to the provided values; A is set to 1.0.
[...] Versions of the Color and SecondaryColor commands that take floating-point values accept values nominally between 0.0 and 1.0.
[...]

GL        Type Conversion
ubyte     c/(2^8 − 1)
byte      (2c + 1)/(2^8 − 1)
ushort    c/(2 16 − 1)
short     (2c + 1)/(2^16 − 1)
uint      c/(2^32 − 1)
int       (2c + 1)/(2^32 − 1)
float     c
double    c
0
On

Do you use a texture somewhere? If so, try disabling texturing before drawing the other thing.