@SuppressWarnings("unchecked") public void addFont(String key, String file, int size, boolean bold, boolean italic, Effect [] effects) throws SlickException { try { AssetManager.ASSETS_TO_LOAD++; UnicodeFont uni = new UnicodeFont(file, size, bold, italic); uni.addAsciiGlyphs(); uni.addGlyphs(400, 600); uni.getEffects().add(new ColorEffect(Color.WHITE)); uni.getEffects().addAll(Arrays.asList(effects)); uni.loadGlyphs(); if((fonts != null) && (uni != null)) { fonts.put(key, uni); AssetManager.ASSETS_LOADED++; System.out.println(String.format("Font Loaded: %s", key)); } } catch(Exception ex) { ex.printStackTrace(); System.out.printf("ERROR: Font \"%s\" could not be loaded!\n", file); } }
/** * Initializes all fonts. * @throws SlickException if ASCII glyphs could not be loaded * @throws FontFormatException if any font stream data does not contain the required font tables * @throws IOException if a font stream cannot be completely read */ public static void init() throws SlickException, FontFormatException, IOException { float fontBase = 12f * GameImage.getUIscale(); Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Constants.FONT_NAME)); Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3)); DEFAULT = new UnicodeFont(font); BOLD = new UnicodeFont(font.deriveFont(Font.BOLD)); XLARGE = new UnicodeFont(font.deriveFont(fontBase * 3)); LARGE = new UnicodeFont(font.deriveFont(fontBase * 2)); MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2)); MEDIUMBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase * 3 / 2)); SMALL = new UnicodeFont(font.deriveFont(fontBase)); SMALLBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase)); ColorEffect colorEffect = new ColorEffect(); loadFont(DEFAULT, colorEffect); loadFont(BOLD, colorEffect); loadFont(XLARGE, colorEffect); loadFont(LARGE, colorEffect); loadFont(MEDIUM, colorEffect); loadFont(MEDIUMBOLD, colorEffect); loadFont(SMALL, colorEffect); loadFont(SMALLBOLD, colorEffect); }
@SuppressWarnings("unchecked") public UnicodeFontRenderer(Font awtFont) { super(Minecraft.getMinecraft().gameSettings, new ResourceLocation("textures/font/ascii.png"), Minecraft.getMinecraft().getTextureManager(), false); font = new UnicodeFont(awtFont); font.addAsciiGlyphs(); font.getEffects().add(new ColorEffect(Color.WHITE)); try { font.loadGlyphs(); } catch (SlickException exception) { throw new RuntimeException(exception); } String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; FONT_HEIGHT = font.getHeight(alphabet) / 4; }
@SuppressWarnings("unchecked") @Override public void init(GameContainer gc, StateBasedGame sbg) throws SlickException { missing = new Image("res/imgs/units/missing.png"); loading = new String[18]; f = sd.getFont(); f = f.deriveFont(Font.PLAIN, gc.getScreenHeight() / loading.length - 5); UnicodeFont uf = new UnicodeFont(f); uf.getEffects().add(new ColorEffect(java.awt.Color.white)); uf.addAsciiGlyphs(); uf.loadGlyphs(); panel = new Panel(0, 0, gc.getWidth(), gc.getHeight()); labels = new Label[loading.length]; for (int i = 0; i < labels.length; i++) { labels[i] = new Label(0, i * (gc.getScreenHeight() / loading.length - 5), uf); panel.add(labels[i]); } mapd = sd.getMap(); units = new Image[1025][4]; }
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException { Image imagesBG[] = new Image[]{ new Image("Assets/Graphics/Game Over/Frames/GO0000.png"), new Image("Assets/Graphics/Game Over/Frames/GO0001.png"), new Image("Assets/Graphics/Game Over/Frames/GO0002.png"), new Image("Assets/Graphics/Game Over/Frames/GO0003.png"), new Image("Assets/Graphics/Game Over/Frames/GO0004.png"), new Image("Assets/Graphics/Game Over/Frames/GO0005.png"), new Image("Assets/Graphics/Game Over/Frames/GO0006.png"), new Image("Assets/Graphics/Game Over/Frames/GO0007.png"), new Image("Assets/Graphics/Game Over/Frames/GO0008.png"), new Image("Assets/Graphics/Game Over/Frames/GO0009.png"), }; coordsIndicator = new Coordinate[]{ new Coordinate(537, 595), new Coordinate(537, 680), }; animateBG = new Animation(imagesBG, 200); fontStats = new UnicodeFont("Assets/Fonts/Disposable Droid/DisposableDroidBB.ttf", 24, false, false); fontStats.getEffects().add(new ColorEffect(java.awt.Color.white)); fontStats.addAsciiGlyphs(); fontStats.loadGlyphs(); fontWinningPlayer = new UnicodeFont("Assets/Fonts/Disposable Droid/DisposableDroidBB.ttf", 32, false, false); fontWinningPlayer.getEffects().add(new ColorEffect(java.awt.Color.white)); fontWinningPlayer.addAsciiGlyphs(); fontWinningPlayer.loadGlyphs(); try { scoreTallySFX = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("Assets/Sound Effects/Score Tally SFX.ogg")); } catch (IOException e) { e.printStackTrace(); } }
public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException { fontCombo = new UnicodeFont("Assets/Fonts/Disposable Droid/DisposableDroidBB.ttf", 48, false, false); fontCombo.getEffects().add(new ColorEffect(java.awt.Color.white)); fontCombo.addAsciiGlyphs(); fontCombo.loadGlyphs(); fontTime = new UnicodeFont("Assets/Fonts/Disposable Droid/DisposableDroidBB.ttf", 34, false, false); fontTime.getEffects().add(new ColorEffect(java.awt.Color.white)); fontTime.addAsciiGlyphs(); fontTime.loadGlyphs(); fontResources = new UnicodeFont("Assets/Fonts/Disposable Droid/DisposableDroidBB.ttf", 20, false, false); fontResources.getEffects().add(new ColorEffect(java.awt.Color.white)); fontResources.addAsciiGlyphs(); fontResources.loadGlyphs(); imageBG = new Image("Assets/Graphics/Game Proper/Game Proper BG.png"); imagesNotes = new Image[]{ new Image("Assets/Graphics/Game Proper/Note Red.png"), new Image("Assets/Graphics/Game Proper/Note Green.png"), new Image("Assets/Graphics/Game Proper/Note Blue.png"), new Image("Assets/Graphics/Game Proper/Note Yellow.png") }; imagesPressedHitbox = new Image[]{ new Image("Assets/Graphics/Game Proper/Pressed Hitbox Red.png"), new Image("Assets/Graphics/Game Proper/Pressed Hitbox Green.png"), new Image("Assets/Graphics/Game Proper/Pressed Hitbox Blue.png"), new Image("Assets/Graphics/Game Proper/Pressed Hitbox Yellow.png") }; }
@SuppressWarnings("unchecked") public UnicodeFontRenderer(Font awtFont) { super(Minecraft.getMinecraft().gameSettings, new ResourceLocation("textures/font/ascii.png"), Minecraft.getMinecraft().getTextureManager(), false); font = new UnicodeFont(awtFont); font.addAsciiGlyphs(); font.getEffects().add(new ColorEffect(Color.WHITE)); try { font.loadGlyphs(); } catch(SlickException exception) { throw new RuntimeException(exception); } String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; FONT_HEIGHT = font.getHeight(alphabet) / 2; }
@SuppressWarnings("unchecked") //loads the fonts for the game including different font sizes. public static void loadFonts() { int arrayLength = GameConstants.GAME_FONT.length; try { for(int i = 0; i < arrayLength; i++) { UnicodeFont font = new UnicodeFont(FONT_LOCATION, (int) ((16+10*i)/GameConstants.WINDOW_SCALE), false, false); font.addAsciiGlyphs(); font.getEffects().add(new ColorEffect()); font.loadGlyphs(); GameConstants.GAME_FONT[i] = font; } } catch(Exception e) { e.printStackTrace(); } }
private static void loadFonts() { font = new UnicodeFont(new java.awt.Font("Times New Roman", java.awt.Font.PLAIN, 24)); font.getEffects().add(new ColorEffect(java.awt.Color.white)); font.addAsciiGlyphs(); try { font.loadGlyphs(); } catch (SlickException e) { e.printStackTrace(); } }
@SuppressWarnings("unchecked") @Override public void init(GameContainer container, StateBasedGame game) throws SlickException { this.game = game; Font font = new Font(Font.MONOSPACED, Font.PLAIN, 60); ufont = new UnicodeFont(font); ufont.addAsciiGlyphs(); ufont.addGlyphs(32, 127); ufont.getEffects().add(new ColorEffect(Color.WHITE)); ufont.loadGlyphs(); }
public TTFRenderer(String fontName, int fontType, int size, float kerning) { this.fontName = fontName; this.fontType = fontType; this.size = size; this.unicodeFont = new UnicodeFont(new Font(fontName, fontType, size)); this.kerning = kerning; this.unicodeFont.addAsciiGlyphs(); this.unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE)); try { this.unicodeFont.loadGlyphs(); } catch(Exception e) { e.printStackTrace(); } for(int i = 0; i < 32; i++) { int shadow = (i >> 3 & 1) * 85; int red = (i >> 2 & 1) * 170 + shadow; int green = (i >> 1 & 1) * 170 + shadow; int blue = (i >> 0 & 1) * 170 + shadow; if(i == 6) { red += 85; } if(i >= 16) { red /= 4; green /= 4; blue /= 4; } this.colorCodes[i] = (red & 255) << 16 | (green & 255) << 8 | blue & 255; } }
@Override public void entered() { java.awt.Font awtFont = new java.awt.Font("Arial", java.awt.Font.PLAIN, 24); font = new UnicodeFont(awtFont); font.getEffects().add(new ColorEffect(java.awt.Color.RED)); font.addAsciiGlyphs(); font.loadGlyphs(); }
public Fonts() { // vani12 = new UnicodeFont(new java.awt.Font ("Vani", Font.BOLD, 12)); vani12.getEffects().add(new ColorEffect(java.awt.Color.white)); vani12.addNeheGlyphs(); // try { // vani12.loadGlyphs(); // } catch (SlickException e) { // e.printStackTrace(); // } }
private void initFont() { font = new UnicodeFont(new java.awt.Font ("Vani", Font.BOLD, 12)); font.getEffects().add(new ColorEffect(java.awt.Color.white)); font.addNeheGlyphs(); try { font.loadGlyphs(); } catch (SlickException e) { e.printStackTrace(); } }
/** * Initializes all fonts. * @throws SlickException if ASCII glyphs could not be loaded * @throws FontFormatException if any font stream data does not contain the required font tables * @throws IOException if a font stream cannot be completely read */ public static void init() throws SlickException, FontFormatException, IOException { float fontBase = 12f * GameImage.getUIscale(); Font javaFontMain = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_MAIN)); Font javaFontBold = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_BOLD)); Font javaFontCJK = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_CJK)); Font fontMain = javaFontMain.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3)); Font fontBold = javaFontBold.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3)); Font fontCJK = javaFontCJK.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3)); DEFAULT = new UnicodeFont(fontMain); BOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD)); XLARGE = new UnicodeFont(fontMain.deriveFont(fontBase * 3)); LARGE = new UnicodeFont(fontMain.deriveFont(fontBase * 2)); MEDIUM = new UnicodeFont(fontMain.deriveFont(fontBase * 3 / 2)); MEDIUMBOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD, fontBase * 3 / 2)); SMALL = new UnicodeFont(fontMain.deriveFont(fontBase)); SMALLBOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD, fontBase)); ColorEffect colorEffect = new ColorEffect(); loadFont(DEFAULT, colorEffect, new UnicodeFont(fontCJK)); loadFont(BOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD))); loadFont(XLARGE, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 3))); loadFont(LARGE, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 2))); loadFont(MEDIUM, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 3 / 2))); loadFont(MEDIUMBOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD, fontBase * 3 / 2))); loadFont(SMALL, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase))); loadFont(SMALLBOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD, fontBase))); }
public DamageRenderer(Font font) throws SlickException { Font f = font.deriveFont(Font.BOLD, 10); uf = new UnicodeFont(f); uf.getEffects().add(new ColorEffect(java.awt.Color.white)); uf.addAsciiGlyphs(); uf.loadGlyphs(); }
public UnitRenderer(Image[][] units, Font font) throws SlickException { this.units = units; Font f = font.deriveFont(Font.PLAIN, 10); uf = new UnicodeFont(f); uf.getEffects().add(new ColorEffect(java.awt.Color.white)); uf.addAsciiGlyphs(); uf.loadGlyphs(); }
public MainHUD(Font font, int width) throws SlickException { Font f = font.deriveFont(Font.BOLD, 20); uf = new UnicodeFont(f); uf.getEffects().add(new ColorEffect(java.awt.Color.white)); uf.addAsciiGlyphs(); uf.loadGlyphs(); hudWidth = (int) (width*0.4f); hudPosX = (int) (width/2 - width*0.2f); }
@SuppressWarnings("unchecked") //nothing we can do about this warning because it is a problem of Slick2D public SimpleFont(Font font, Color color) throws SlickException { ufont = new UnicodeFont(font); ufont.getEffects().add(new ColorEffect(color)); ufont.addAsciiGlyphs(); ufont.loadGlyphs(); }
@SuppressWarnings("unchecked") //nothing we can do about this warning because it is a problem of Slick2D public SimpleFont(String name, int size, Color color){ try { ufont = new UnicodeFont(name, size, false, false); ufont.getEffects().add(new ColorEffect(color)); ufont.addAsciiGlyphs(); ufont.loadGlyphs(); } catch (SlickException e) { e.printStackTrace(); } }
@SuppressWarnings("unchecked") public void setColor(Color color) throws SlickException{ ufont.getEffects().clear(); ufont.clearGlyphs(); ufont.getEffects().add(new ColorEffect(color)); ufont.addAsciiGlyphs(); ufont.loadGlyphs(); }
static public void init(){ font = new UnicodeFont(new Font("Times New Roman", Font.BOLD, 14)); font.addAsciiGlyphs(); font.addGlyphs(400, 600); font.getEffects().add(new ColorEffect(java.awt.Color.WHITE)); // FIXME ? try { font.loadGlyphs(); } catch (SlickException e) { e.printStackTrace(); } }
public void addFont(String key, String file, int size, boolean bold, boolean italic) throws SlickException { addFont(key, file, size, bold, italic, new Effect[] { new ColorEffect(Color.WHITE) }); }
private void initializeFonts() throws SlickException { fontHeader = new UnicodeFont("Assets/Fonts/Disposable Droid/DisposableDroidBB.ttf", 50, false, false); fontHeader.getEffects().add(new ColorEffect(java.awt.Color.white)); fontHeader.addAsciiGlyphs(); fontHeader.loadGlyphs(); }
@SuppressWarnings("unchecked") @Override public void init(GameContainer gc, StateBasedGame sbg) throws SlickException { errorImage = Main.loadImage("res/error2.png"); lastMouseX = gc.getInput().getAbsoluteMouseX(); lastMouseY = gc.getInput().getAbsoluteMouseY(); gc.setMouseCursor(Main.CURSOR_IMAGES.getSprite(1, 0), 16, 16); FONT = new UnicodeFont("res/Anonymous_Pro.ttf", 12, false, false); FONT.addAsciiGlyphs(); FONT.getEffects().add(new ColorEffect()); FONT.loadGlyphs(); coin = Main.loadImage("res/coin.png"); EditorKeyListener listener = new EditorKeyListener(this); gc.getInput().addKeyListener(listener); tiles = new SpriteSheet(Main.loadImage("res/tiles.png"), 32, 32); play = new MouseOverArea(gc, Main.USEFUL_BUTTONS.getSprite(0, 1), 4, gc.getHeight() - 40); play.setMouseDownImage(Main.USEFUL_BUTTONS.getSprite(1, 1)); stop = new MouseOverArea(gc, Main.USEFUL_BUTTONS.getSprite(0, 2), 44, gc.getHeight() - 40); stop.setMouseDownImage(Main.USEFUL_BUTTONS.getSprite(1, 2)); help = new MouseOverArea(gc, Main.BIG_BUTTON.getSprite(0, 0), 84, gc.getHeight() - 40); help.setMouseDownImage(Main.BIG_BUTTON.getSprite(0, 1)); failed = new MouseOverArea(gc, Main.USEFUL_BUTTONS.getSprite(0, 3), gc.getWidth() / 2 - 16, gc.getHeight() / 2 + 40); failed.setMouseDownImage(Main.USEFUL_BUTTONS.getSprite(1, 3)); pause = new MouseOverArea(gc, Main.USEFUL_BUTTONS.getSprite(0, 0), 8, 8); pause.setMouseDownImage(Main.USEFUL_BUTTONS.getSprite(1, 0)); menu = new MouseOverArea(gc, Main.BIG_BUTTON.getSprite(0, 0), gc.getWidth() / 2 - 64, gc.getHeight() / 2 + 16); menu.setMouseDownImage(Main.BIG_BUTTON.getSprite(0, 1)); SpriteSheet sheet = new SpriteSheet(Main.loadImage("res/tweet.png"), 128, 32); tweet = new MouseOverArea(gc, sheet.getSprite(0, 0), gc.getWidth() / 2 - 64, gc.getHeight() / 2 + 56); tweet.setMouseDownImage(sheet.getSprite(0, 1)); scores = new MouseOverArea(gc, Main.BIG_BUTTON.getSprite(0, 0), gc.getWidth() / 2 - 64, gc.getHeight() / 2 + 96); scores.setMouseDownImage(Main.BIG_BUTTON.getSprite(0, 1)); coins = 0; arrow = Main.loadImage("res/arrow.png"); }
public Hiero () throws SlickException { super("Hiero v2.0 - Bitmap Font Tool"); Splash splash = new Splash(this, "splash.jpg", 2000); try { initialize(); } catch (SlickException ex) { dispose(); throw ex; } splash.close(); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { // stop slick2d event loop; maybe slick2d should use awt timer for that: // http://www.pushing-pixels.org/2008/07/17/awt-shutdown-and-daemon-threads.html canvasContainer.setVisible(false); dispose(); } }); prefs = Preferences.userNodeForPackage(Hiero.class); java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000")); backgroundColorLabel.setIcon(getColorIcon(backgroundColor)); renderingBackgroundColor = new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()); fontList.setSelectedValue(prefs.get("system.font", "Arial"), true); fontFileText.setText(prefs.get("font.file", "")); java.awt.Color foregroundColor = EffectUtil.fromString(prefs.get("foreground", "ffffff")); colorEffect = new ColorEffect(); colorEffect.setColor(foregroundColor); effectsListModel.addElement(colorEffect); effectsListModel.addElement(new GradientEffect()); effectsListModel.addElement(new OutlineEffect()); effectsListModel.addElement(new OutlineWobbleEffect()); effectsListModel.addElement(new OutlineZigzagEffect()); effectsListModel.addElement(new ShadowEffect()); new EffectPanel(colorEffect); setVisible(true); gamePanel.add(canvasContainer); gamePanel.setVisible(false); canvasContainer.start(); }
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { G3D.init(800, 600); Display.setResizable(true); setLighting(); Model m = OBJLoader.loadModel(new File("res/bunny.obj")); int[] vbos = OBJLoader.createVBO(m); int vboVertexHandle = vbos[0]; int vboNormalHandle = vbos[1]; glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle); glVertexPointer(3, GL_FLOAT, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle); glNormalPointer(GL_FLOAT, 0, 0); EulerCamera cam = new EulerCamera((float)Display.getWidth() / Display.getHeight(), -2.19f, 1.36f, 11.45f); cam.setFieldOfView(70); cam.invertY(true); cam.applyPerspectiveMatrix(); ShaderProgram sp = ShaderProgram.createFromResource("vbospecular.vert", "vbospecular.frag"); Font awtfont = new Font("Times New Roman", Font.BOLD, 18); UnicodeFont font = new UnicodeFont(awtfont); font.getEffects().add(new ColorEffect(Color.WHITE)); font.addAsciiGlyphs(); font.loadGlyphs(); G3D.loop(30, () -> { if (Mouse.isGrabbed()) { cam.processMouse(1, 80, -80); } cam.processKeyboard(16, 1, 1, 1); if (Mouse.isButtonDown(0)) { Mouse.setGrabbed(true); } else if (Mouse.isButtonDown(1)) { Mouse.setGrabbed(false); } G3D.setPerspective(70, 0.1f, 100); setLighting(); cam.applyTranslations(); glLight(GL_LIGHT0, GL_POSITION, floats(cam.x(), cam.y(), cam.z(), 1)); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); sp.use(); glDrawArrays(GL_TRIANGLES, 0, m.getFaces().size() * 3); sp.stop(); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); G2D.setOrthogonal(); glLoadIdentity(); font.drawString(10, 10, String.format("%.2f; %.2f; %.2f;", cam.x(), cam.y(), cam.z())); glDisable(GL_TEXTURE_2D); glColor4f(1f, 1f, 1f, 1f); G2D.fillRect(100, 100, 100, 100); G2D.drawRect(200, 200, 100, 100); glEnable(GL_TEXTURE_2D); }); }