做一个当前上下文,创建一个createCapabilities
。
public static void main(String[] args) {
if (!glfwInit()) {
throw new IllegalStateException("Unable to initialize GLFW");
}
glfwDefaultWindowHints();
long window = glfwCreateWindow(640, 480, "My LWJGL Program", 0, 0);
if (window == NULL) {
throw new RuntimeException("Failed to create the GLFW window");
}
glfwShowWindow(window);
glfwMakeContextCurrent(window);//上下文
GL.createCapabilities();//createCapabilities
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
}
绘制一个矩形
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT);//清除缓冲区
glBegin(GL_QUADS);//绘制的形状(矩形)
glColor4f(1, 0, 0, 0);//颜色
glVertex2d(-0.5f, 0.5f);//第一个点
glVertex2d(0.5f, 0.5f);//第二个点
glVertex2d(0.5f, -0.5f);//第三个点
glVertex2d(-0.5f, -0.5f);//第四个点
glEnd();//结束
glfwSwapBuffers(window);//交换缓冲区
}