2017-05-24 65 views
1

當我運行這個時,窗口彈出,我看到了這個。 (When I run the game, I see this)LWJGL 3:​​OpenGL Quad中的隨機(0,0)點

如果你只是做一個新的Java項目,進口的OpenGL,GLFW和LWJGL,與當地人一起,然後複製這個代碼可以重現(刪除包)

package net.nathanthesnooper.timetraveller; 

import static org.lwjgl.glfw.GLFW.*; 
import static org.lwjgl.opengl.GL11.*; 
import org.lwjgl.opengl.GL; 

public class Game { 

    public static void main (String[] args) { 

     if(glfwInit() != true) { 
      System.err.println("GLFW Failed to initialize!"); 
      System.exit(1); 
     } 

     long window = glfwCreateWindow(640,480,"Game", 0, 0); 

     glfwShowWindow(window); 

     glfwMakeContextCurrent(window); 
     GL.createCapabilities(); 

     while(!glfwWindowShouldClose(window)) { 

      glfwPollEvents(); 

      glClear(GL_COLOR_BUFFER_BIT); 

      glBegin(GL_QUADS); 

      glVertex2d(-0.5,0.5); 
      glVertex2d(0.5,0.5); 
      glVertex2d(-0.5,-0.5); 
      glVertex2d(0.5,-0.5); 

      glEnd(); 

      glfwSwapBuffers(window); 

     } 

     glfwTerminate(); 

    } 

} 

回答

0

你以錯誤的順序繪製四邊形的頂點。嘗試

glVertex2d(0.5,0.5); 
glVertex2d(-0.5,0.5); 
glVertex2d(-0.5,-0.5); 
glVertex2d(0.5,-0.5); 

你通常畫在逆時針順序爲面向您四(或三角形)(這就是所謂的「纏繞」),順時針爲一個是背向您。就你而言,你已經將它們畫成了一個無效的字母「Z」。

+0

謝謝,這有幫助!我想我以爲它會自動解決自己:) – nathanthesnooper