我編寫了在屏幕上繪制矩形的應用程序。我想在 z 軸上移動這個矩形,但它不起作用。它消失了。我不知道如何修復它。代碼:package game;import org.lwjgl.opengl.GL;import static org.lwjgl.glfw.GLFW.*;import static org.lwjgl.opengl.GL11.*;public class Main { public static void main(String[] args) { glfwInit(); System.out.println("Hello World!"); long window = glfwCreateWindow(1280 ,720,"Title",0,0); glfwMakeContextCurrent(window); glfwSwapInterval(1); GL.createCapabilities(); /////////////////////////////// glTranslatef(0,0,5); /////////////////////////////// while(!glfwWindowShouldClose(window)){ glfwPollEvents(); glBegin(GL_QUADS); glVertex2f(-0.5f,0.5f); glVertex2f(-0.5f,-0.5f); glVertex2f(0.5f,-0.5f); glVertex2f(0.5f,0.5f); glEnd(); System.out.println(z); glfwSwapBuffers(window); } System.exit(0 ); }}
1 回答

Helenr
TA貢獻1780條經驗 獲得超4個贊
默認情況下,僅顯示立方體內 x、y、z 坐標為 -1 到 1 的內容。由于glTranslatef
在代碼的開頭,您有效地在坐標處渲染了一個正方形
(-0.5f,0.5f,5), (-0.5f,-0.5f,5), (0.5f,-0.5f,5), (0.5f,0.5f,5)
它位于立方體之外,因此未顯示。
要更改渲染內容的坐標,我建議查看glOrtho
和glFrustum
。您還glFrustum
可以在 3D 透視圖中看到事物。
添加回答
舉報
0/150
提交
取消