所以我想使用 VAO 和 VBO 繪制一個形狀,我認為我做的一切都是正確的,但是每當我運行我的代碼時,我都會得到帶有清晰顏色的窗口。在調用創建功能之前嘗試初始化三角形時,我遇到了一個問題,我是否缺少一些開始繪圖的函數?這是我的代碼:int vaoId, vboId, vertexCount;float[] vertices = { // Left bottom triangle -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f,};private void init() { if (!glfwInit()) { throw new IllegalStateException("Failed to Initialize GLFW!"); } int width = 1000; int height = 1000; glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); window = glfwCreateWindow(width, height, "App", NULL, NULL); if (window == 0) { throw new IllegalStateException("Failed to create Window!"); } GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (videoMode.width() - width) / 2, (videoMode.height() - height) / 2); // Make the OpenGL context current glfwMakeContextCurrent(window); // Enable v-sync glfwSwapInterval(1); glfwShowWindow(window);}private void loop() { // This line is critical for LWJGL's interoperation with GLFW's // OpenGL context, or any context that is managed externally. // LWJGL detects the context that is current in the current thread, // creates the GLCapabilities instance and makes the OpenGL // bindings available for use. GL.createCapabilities(); initTriangle(); // Run the rendering loop until the user has attempted to close // the window or has pressed the ESCAPE key. while (!glfwWindowShouldClose(window)) { glClear(GL_COLOR_BUFFER_BIT); // clear the framebuffer glBindVertexArray(vaoId); glEnableVertexAttribArray(0); glDrawArrays(GL_TRIANGLES, 0, vertexCount); glDisableVertexAttribArray(0); glBindVertexArray(0); glfwSwapBuffers(window); // swap the color buffers // Poll for window events. The key callback above will only be // invoked during this call. glfwPollEvents(); }}希望大家幫幫忙,萬分感謝。
添加回答
舉報
0/150
提交
取消