为什么我的 LEGACY OPENGL 颜色反转了?

Why are my LEGACY OPENGL colors inverted?

本文关键字:颜色 我的 LEGACY OPENGL 为什么      更新时间:2023-10-16

几个月前,我写了一个简单的代码来显示3个多边形。一切都很好。然后颜色突然开始变化...

我在VISUAL STUDIO 2019中。

我试过了:

  • 修复 VS 可再发行组件。
  • 制作一个新项目。

有什么线索吗?

#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
//idk what is going on
glBegin(GL_POLYGON);
glVertex2f(0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.5f, -0.5f);
glColor3f(1.0f, 0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.7f, 0.7f);
glVertex2f(-0.7f, 0.7f);
glVertex2f(-0.7f, -0.7f);
glVertex2f(0.7f, -0.7f);
glColor3f(1.0f, 1.0f, 1.0f);
glEnd();

/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}

glVertex2f指定顶点坐标之前,必须设置颜色属性(glColor(:

glBegin(GL_POLYGON);

glColor3f(1.0f, 0.5f, 0.5f);
glVertex2f(0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.5f, -0.5f);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex2f(0.7f, 0.7f);
glVertex2f(-0.7f, 0.7f);
glVertex2f(-0.7f, -0.7f);
glVertex2f(0.7f, -0.7f);
glEnd();

请注意,glColor设置当前颜色,当调用glVertex时,当前颜色、法线和纹理坐标与顶点相关联。