我有一个像这样的主要包:
// Imports and package stuff
public class Main {
public static void main(String[] args) {
// Initialisation code
long window = glfwCreateWindow(800, 600, "Hello World", 0, 0);
// Initialisation code
glfwShowWindow(window);
glfwMakeContextCurrent(window);
GL.createCapabilities();
glClearColor(0, 0, 0, 1);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor4f(1, 0, 0, 1);
glVertex2f(0.5f, 0.5f);
glVertex2f(0.5f, -0.5f);
glVertex2f(-0.5f, -0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glfwSwapBuffers(window);
}
glfwTerminate();
}
}
(//
注释显示省略的代码。)
我希望输出"窗口"是一个黑色的窗口,中间有一个红色的矩形,但我得到的是一个白色背景的窗口。
起初,我怀疑它是glClearColor
线弄乱了(因为它设置了要清除的默认颜色,也许是白色)。我尝试编辑glClearColor
行(我摆弄了alpha值以及RGB),但它们都产生了相同的白色背景。
感谢任何帮助!
答案 0 :(得分:-1)
所以,我尝试运行你的代码,我在
上得到一个NullPointerExceptionglfwShowWindow(window);
所以,试试
if (!glfwInit()) {
System.err.println("GLFW Failed to initialize!");
System.exit(1);
}
在创建窗口之前。这对我有用。希望这有帮助!