Exemplo n.º 1
0
  public static void drawString(UIFont font, String s, int x, int y, Color color) {
    if (s == null || s.length() <= 0) return;

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, font.getFontTexture().id);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glColor4f(color.r, color.g, color.b, color.a);

    glBegin(GL_QUADS);
    {
      for (char c : s.toCharArray()) {
        if (c == '\n') y += font.getHeight();

        float width = font.charWidth(c);
        float height = font.getHeight();
        float u = 1f / font.getFontImageWidth() * font.getCharX(c);
        float v = 1f / font.getFontImageHeight() * font.getCharY(c);
        float u2 = u + 1f / font.getFontImageWidth() * width;
        float v2 = v + 1f / font.getFontImageHeight() * height;

        glTexCoord2f(u, v);
        glVertex2f(x, y);

        glTexCoord2f(u2, v);
        glVertex2f(x + width, y);

        glTexCoord2f(u2, v2);
        glVertex2f(x + width, y + height);

        glTexCoord2f(u, v2);
        glVertex2f(x, y + height);

        x += width;
      }
    }
    glEnd();

    glColor4f(1, 1, 1, 1);

    glDisable(GL_BLEND);
    glDisable(GL_TEXTURE_2D);
  }
Exemplo n.º 2
0
 public static void drawString(String s, int x, int y, Color color) {
   drawString(UIFont.getDefault(), s, x, y, color);
 }