【发布时间】:2016-02-09 17:48:48
【问题描述】:
glfw 有个小问题。
我的代码很简单,我只想创建一个空窗口。
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
int main(void) {
// initialise the windows
GLFWwindow *window;
if (!glfwInit()) {
return -1;
}
// create a windows
window = glfwCreateWindow(640, 480, "Test", NULL, NULL);
if (!window) {
fprintf(stderr, "Failed to initialize GLFW\n");
glfwTerminate();
return -1;
}
// make the window's current context
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
// loop until the window close
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// swap back and front buffers
glfwSwapBuffers(window);
// poll the events
glfwPollEvents();
}
std::cout << "finished ";
glfwTerminate();
return 0;
}
这段代码可以编译,但是当我运行它时,我只有一个白色的窗口。窗口的标题是正确的,但里面的一切都是白色的...... 我尝试像这样使用 glClearColor
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 1, 0, 0);
但我的窗户仍然是白色的...... 我使用 Visual Studio 2015。
如何获得黑窗?
编辑:
我忘了添加这个: glfwMakeContextCurrent(window);
【问题讨论】:
-
用
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);替换glClearColor(1.0f, 1.0f, 1.0f, 1.0f);可能吗? -
您可以将其放在答案中并关闭主题。 @Skarwim