Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1.  
  2. import static org.lwjgl.opengl.GL11.*;
  3.  
  4. import java.awt.Color;
  5. import java.awt.Font;
  6.  
  7. import net.minecraft.client.Minecraft;
  8. import net.minecraft.client.gui.FontRenderer;
  9. import net.minecraft.util.ResourceLocation;
  10.  
  11. import org.newdawn.slick.*;
  12. import org.newdawn.slick.font.effects.ColorEffect;
  13.  
  14. public class UnicodeFontRenderer extends FontRenderer {
  15. private final UnicodeFont font;
  16.  
  17. @SuppressWarnings("unchecked")
  18. public UnicodeFontRenderer(Font awtFont) {
  19. super(Minecraft.getMinecraft().gameSettings, new ResourceLocation("textures/font/ascii.png"), Minecraft.getMinecraft().getTextureManager(), false);
  20.  
  21. font = new UnicodeFont(awtFont);
  22. font.addAsciiGlyphs();
  23. font.getEffects().add(new ColorEffect(Color.WHITE));
  24. try {
  25. font.loadGlyphs();
  26. } catch(SlickException exception) {
  27. throw new RuntimeException(exception);
  28. }
  29. String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
  30. FONT_HEIGHT = font.getHeight(alphabet) / 2;
  31. }
  32.  
  33. @Override
  34. public int drawString(String string, int x, int y, int color) {
  35. if(string == null)
  36. return 0;
  37. // glClear(256);
  38. // glMatrixMode(GL_PROJECTION);
  39. // glLoadIdentity();
  40. // IntBuffer buffer = BufferUtils.createIntBuffer(16);
  41. // glGetInteger(GL_VIEWPORT, buffer);
  42. // glOrtho(0, buffer.get(2), buffer.get(3), 0, 1000, 3000);
  43. // glMatrixMode(GL_MODELVIEW);
  44. // glLoadIdentity();
  45. // glTranslatef(0, 0, -2000);
  46. glPushMatrix();
  47. glScaled(0.5, 0.5, 0.5);
  48.  
  49. boolean blend = glIsEnabled(GL_BLEND);
  50. boolean lighting = glIsEnabled(GL_LIGHTING);
  51. boolean texture = glIsEnabled(GL_TEXTURE_2D);
  52. if(!blend)
  53. glEnable(GL_BLEND);
  54. if(lighting)
  55. glDisable(GL_LIGHTING);
  56. if(texture)
  57. glDisable(GL_TEXTURE_2D);
  58. x *= 2;
  59. y *= 2;
  60. // glBegin(GL_LINES);
  61. // glVertex3d(x, y, 0);
  62. // glVertex3d(x + getStringWidth(string), y + FONT_HEIGHT, 0);
  63. // glEnd();
  64.  
  65. font.drawString(x, y, string, new org.newdawn.slick.Color(color));
  66.  
  67. if(texture)
  68. glEnable(GL_TEXTURE_2D);
  69. if(lighting)
  70. glEnable(GL_LIGHTING);
  71. if(!blend)
  72. glDisable(GL_BLEND);
  73. glPopMatrix();
  74. return x;
  75. }
  76.  
  77. @Override
  78. public int func_175063_a(String string, float x, float y, int color) {
  79. return drawString(string, (int) x, (int) y, color);
  80. }
  81.  
  82. @Override
  83. public int getCharWidth(char c) {
  84. return getStringWidth(Character.toString(c));
  85. }
  86.  
  87. @Override
  88. public int getStringWidth(String string) {
  89. return font.getWidth(string) / 2;
  90. }
  91.  
  92. public int getStringHeight(String string) {
  93. return font.getHeight(string) / 2;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement