我正在尝试编写一个连续更改背景颜色的代码。当我启动窗口加载程序时,颜色工作正常,但我无法关闭、调整大小或单击它。 这是一个改变背景颜色的函数:
void colors(GLFWwindow* window) {
float a = 0, b = 0, c = 0;
float catDeRepede = 0.025;
for (a = 0; a < 1; a += catDeRepede) {
for (b = 0; b < 1; b += catDeRepede) {
glClearColor(a, b, c, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
//std::cout << " red:" << a << " green:" << b << " blue:" << c;
}
b = 0;
for (c = 0; c < 1; c += catDeRepede) {
glClearColor(a, b, c, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
//std::cout << " red:" << a << " green:" << b << " blue:" << c;
}
c = 0;
}
还有我的主要功能:
int main()
{
//initialize glfw
glfwInit();
//tell glfw what version is being used
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//tell glfw we use CORE profile so we have only modern functions
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//creates a winodw
GLFWwindow* window = glfwCreateWindow(800, 800, "NAME_OF_WINDOW", NULL, NULL);
//error to check if winodw doesent work initializing
if (window == NULL)
{
std::cout << "failed 2 create the windwo" << std::endl;
glfwTerminate();
return -1;
}
// introduce winodw in the current context
glfwMakeContextCurrent(window);
//load GLAD so it configures opengl
gladLoadGL();
//specify the viewport of opengl in the window
glViewport(0, 0, 800, 800);
//DESPRE BUFFERE
/*bufferele sunt cele 2 fameuri : care se vede pe ecran si urmatorul care este procesat in background.
pentru a accesa celalalt se foloseste swap_buffers*/
//specify color of background
glClearColor(0.07f, 0.13f, 0.17f, 1.0f);
//clean the back buffer and assign new color to it
glClear(GL_COLOR_BUFFER_BIT);
//swaps back buffer with front buffer
glfwSwapBuffers(window);
double a = 0, b = 0, c = 0;
//main while loop
while (!glfwWindowShouldClose(window))
{
colors(window);
//glfwWaitEvents();
glfwPollEvents();
}
//delete window
glfwDestroyWindow(window);
//terminate glfw
glfwTerminate();
return 0;
}