c - OpenGl 中的 glColor3f 亮度很小

标签 c opengl freeglut opengl-1.x

我的 OpenGl 代码有问题 我需要做一个游戏引擎。 我使用 freeglut 库。 我用旧的 Visual Studio 版本做了这个练习,我没有这个问题。但是在 Visual Studio 2017 中,属性 glColor3f 显示时亮度很小。为什么?

这是我用来显示文本的代码:

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);

更新:

This is the result of my code

亮度这么低,模型还是不错的。我将 glColor3f(0.0f, 1.0f, 1.0f); 放在新代码中,但结果是一样的。


更新2 这是我的 displayMe 函数:

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);

最佳答案

固定功能灯光模型也应用于文本。这将导致任意结果,具体取决于当前的灯光设置和当前的法 vector 属性。在绘制文本之前,您必须禁用照明。

glDisable(GL_LIGHTING);

你必须在绘制几何之前启用它

glEnable(GL_LIGHTING);

glColor3f 的参数必须是 [0.0, 1.0] 范围内的浮点值,

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

glColor3ub 相比,参数是 [0, 255] 范围内的整数值。

glColor3ub(0, 255, 255);

参见 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

关于c - OpenGl 中的 glColor3f 亮度很小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54011452/

相关文章:

c - 当本地函数的内存在堆栈上被清除时?

c - 使用带有 %i 的 scanf 捕获日期时出现问题 (mm dd yyyy)

opengl - 统一位置和统一索引的区别?

c++ - 为什么 mipmapping 对我的 3D 纹理不起作用? (opengl)

c++ - fatal error LNK1104 : cannot open . lib (glloaD)

c - 使用 SecItemImport 导入 PKCS12

c - 将 X 索引的内存复制到 C 中单个数组中的多个位置的最佳方法是什么?

c - 从另一个线程重绘opengl

c - 在 C 中显示 OpenGL 地形网格的问题

macos - 是否可以在 Mac OS X 上构建 FreeGLUT?