I have a main package like so:
// 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();
}
}
(The //
comments show omitted code).
I expect the output "window" to be a black window with a red rectangle in the middle, but what I'm getting is a window with a white background.
At first, I suspected it was the glClearColor
line messing up (because it sets the default colour to be cleared, and maybe that was white). I tried editing the glClearColor
line (I fiddled around with the alpha values, as well as the RGB), but they all resulted in the same white background.
Any help is appreciated!
So, I tried running your code and I was getting a NullPointerException on
glfwShowWindow(window);
So, try putting
if (!glfwInit()) {
System.err.println("GLFW Failed to initialize!");
System.exit(1);
}
before you create your window. This worked for me. Hope this helped!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.