我想通过切换到 2D 场景然后切换回 3D 在我的屏幕上渲染 2D 四边形。除了 LWJGL,我不想使用任何外部库。
这是我到目前为止得到的:
private static void renderLetter(char c, float x, float y) {
int character = c+1;
GL11.glPushMatrix();
setOrthoOn();
GL11.glTranslatef(x, y, 0);
float[] xy = game.getResourceManager().getSpriteSheets().get(fontSheet).getXYForCell(character);
float cellx = game.getResourceManager().getSpriteSheets().get(fontSheet).getCell_sizeX();
float celly = game.getResourceManager().getSpriteSheets().get(fontSheet).getCell_sizeY();
float xx = xy[0];
float yy = xy[1];
GL11.glBindTexture(GL11.GL_TEXTURE_2D, game.getResourceManager().getTextures().get(game.getResourceManager().getSpriteSheets().get(fontSheet).getTextureID()));
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(xx, yy);
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(xx+cellx, yy);
GL11.glVertex2f(fontSize,0);
GL11.glTexCoord2f(xx+cellx, yy+celly);
GL11.glVertex2f(fontSize,fontSize);
GL11.glTexCoord2f(xx, yy+celly);
GL11.glVertex2f(0,fontSize);
GL11.glEnd();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
setOrthoOff();
GL11.glPopMatrix();
}
public static void setOrthoOn()
{
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glClearDepth(1);
GL11.glViewport(0,0,1360,768);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 1360, 768, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
}
public static void setOrthoOff()
{
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(game.getFieldOfView(), 1360f/768f, 0.1f, 1000);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
}
第一种方法是渲染一个字母。我想做的是通过调用 setOrthoOn 切换到 2D 渲染然后渲染四边形然后调用 setOrthoOff 切换回 3D。
当我运行它时,这段代码对我没有任何作用。我做错了什么?