【发布时间】:2015-04-17 22:42:12
【问题描述】:
我尝试使用 VAO、VBO 和 DrawArrays() 渲染一个 Rectangle。现在我已经用 GLFW 设置了我的窗口,并出现了一个窗口。即使我更改了清除颜色并调用 glClear(),窗口也始终为白色。
我的窗口创建代码:
public static long createWindow(int width, int height, String title){
long window;
window = GLFW.glfwCreateWindow(width, height, title, MemoryUtil.NULL, MemoryUtil.NULL);
if (window == MemoryUtil.NULL) {
GLFW.glfwTerminate();
System.out.println("Couldn't create window");
System.exit(-1);
}
GLFW.glfwMakeContextCurrent(window);
GLFW.glfwSwapInterval(1);
GLFW.glfwShowWindow(window);
GLContext.createFromCurrent();
GL11.glClearColor(0.0f, 0.0f, 0.5f, 1.0f);
GLFW.glfwSwapInterval(1);
GLFW.glfwShowWindow(window);
System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION));
return window;
我的主循环:
public class Mainloop {
public static void mainloop(int vaoID,int vboID, int vertexCount, long window, ShaderProgram Shader){
//Setup Before Rendering
GL11.glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GLFW.glfwPollEvents();
//Bind Arrays
GL30.glBindVertexArray(vaoID);
GL20.glEnableVertexAttribArray(0);
//Bind Shader
Shader.start();
//Render
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexCount);
//Clean-up Shader
Shader.stop();
//Clean-up Array
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);
}
}
【问题讨论】:
标签: java opengl window lwjgl glfw