【发布时间】:2020-06-24 16:20:36
【问题描述】:
几个月前,我写了一个简单的代码来显示 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;
}
【问题讨论】:
-
我不知道您所说的“颜色开始变化”是什么意思——但是,通常
glColor3f()调用会在定义顶点之前出现。 -
它已经回答了,但是对象 1 有颜色 2,对象 2 有颜色 3,等等。
标签: c++ opengl glfw opengl-compat