我是 OpenGL 的新手,所以我尝试绘制一个带纹理的 2D 矩形。我不知道为什么,但这不起作用:
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, frameWidth, frameHeight);
GL11.glOrtho(0, 640, 0, 480, 0, 128);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, renderer.getTexture("/textures/menu/title.png"));
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex3f(-frameWidth/2, -frameHeight/2, -1);
GL11.glTexCoord2f(1, 0);
GL11.glVertex3f(+frameWidth/2, -frameHeight/2, -1);
GL11.glTexCoord2f(1, 1);
GL11.glVertex3f(+frameWidth/2, +frameHeight/2, -1);
GL11.glTexCoord2f(0, 1);
GL11.glVertex3f(-frameWidth/2, +frameWidth/2, -1);
GL11.glEnd();
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glCullFace(GL11.GL_BACK);
frameWidth 是窗口的宽度,frameHeight 是高度。