|
| 1 | +package com.github.tommyettinger.textra; |
| 2 | + |
| 3 | +import com.badlogic.gdx.ApplicationAdapter; |
| 4 | +import com.badlogic.gdx.Gdx; |
| 5 | +import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; |
| 6 | +import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; |
| 7 | +import com.badlogic.gdx.graphics.Color; |
| 8 | +import com.badlogic.gdx.graphics.GL20; |
| 9 | +import com.badlogic.gdx.graphics.Pixmap; |
| 10 | +import com.badlogic.gdx.graphics.PixmapIO; |
| 11 | +import com.badlogic.gdx.graphics.g2d.SpriteBatch; |
| 12 | +import com.badlogic.gdx.graphics.glutils.ShaderProgram; |
| 13 | +import com.badlogic.gdx.math.MathUtils; |
| 14 | +import com.badlogic.gdx.math.RandomXS128; |
| 15 | +import com.badlogic.gdx.utils.Align; |
| 16 | +import com.badlogic.gdx.utils.IntArray; |
| 17 | +import com.badlogic.gdx.utils.ScreenUtils; |
| 18 | +import com.badlogic.gdx.utils.TimeUtils; |
| 19 | +import com.badlogic.gdx.utils.viewport.StretchViewport; |
| 20 | +import com.badlogic.gdx.utils.viewport.Viewport; |
| 21 | +import com.github.tommyettinger.textra.utils.ColorUtils; |
| 22 | +import com.github.tommyettinger.textra.utils.Palette; |
| 23 | +import com.github.tommyettinger.textra.utils.StringUtils; |
| 24 | + |
| 25 | +import java.nio.ByteBuffer; |
| 26 | + |
| 27 | +public class PreviewOpenMojiLineGenerator extends ApplicationAdapter { |
| 28 | + |
| 29 | + Font font; |
| 30 | + SpriteBatch batch; |
| 31 | + Viewport viewport; |
| 32 | + Layout layout = new Layout().setTargetWidth(1200); |
| 33 | + float x, y; |
| 34 | + long startTime; |
| 35 | + |
| 36 | + public static void main(String[] args){ |
| 37 | + Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); |
| 38 | + config.setTitle("Emoji Preview Generator"); |
| 39 | + config.setWindowedMode(1200, 675); |
| 40 | + config.disableAudio(true); |
| 41 | + ShaderProgram.prependVertexCode = "#version 110\n"; |
| 42 | + ShaderProgram.prependFragmentCode = "#version 110\n"; |
| 43 | +// config.enableGLDebugOutput(true, System.out); |
| 44 | + config.setForegroundFPS(Lwjgl3ApplicationConfiguration.getDisplayMode().refreshRate); |
| 45 | + config.useVsync(true); |
| 46 | + new Lwjgl3Application(new PreviewOpenMojiLineGenerator(), config); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public void create() { |
| 51 | + batch = new SpriteBatch(); |
| 52 | + viewport = new StretchViewport(1200, 600); |
| 53 | + |
| 54 | + Gdx.files.local("out/").mkdirs(); |
| 55 | +// font = KnownFonts.addOpenMoji(KnownFonts.getInconsolata().scaleTo(32, 32), false, -12f, -6f, 0f); |
| 56 | + font = KnownFonts.addOpenMoji(KnownFonts.getNowAlt(), false, 0f, 0f, 0f).fitCell(32, 32, true); |
| 57 | + layout.setBaseColor(Color.DARK_GRAY); |
| 58 | + StringBuilder sb = new StringBuilder(4000); |
| 59 | + sb.append("[%?whiten]"); |
| 60 | + RandomXS128 random = new RandomXS128(1, 42); |
| 61 | + font.mapping.remove('['); |
| 62 | + font.mapping.remove(']'); |
| 63 | + font.mapping.remove('{'); |
| 64 | + font.mapping.remove('}'); |
| 65 | + font.mapping.remove('\n'); |
| 66 | + font.mapping.remove('\r'); |
| 67 | + font.mapping.remove('\t'); |
| 68 | + font.mapping.remove(' '); |
| 69 | + IntArray keys = font.mapping.keys().toArray(); |
| 70 | + int ks = keys.size, ps = Palette.LIST.size; |
| 71 | + for (int y = 0; y < 18; y++) { |
| 72 | + for (int x = 0; x < 36; x++) { |
| 73 | +// sb.append("[richmost darker ").append(Palette.NAMES.get(random.nextInt(ps))).append(']'); |
| 74 | + StringUtils.appendUnsignedHex(sb.append("[#"), ColorUtils.darken(Palette.LIST.get(random.nextInt(ps)), 0.25f)).append(']'); |
| 75 | + sb.append((char)keys.get(random.nextInt(ks))); |
| 76 | + } |
| 77 | + sb.append('\n'); |
| 78 | + } |
| 79 | + font.markup(sb.toString(), layout); |
| 80 | + font.calculateSize(layout); |
| 81 | + System.out.println(sb); |
| 82 | + |
| 83 | + ScreenUtils.clear(0.75f, 0.75f, 0.75f, 1f); |
| 84 | + x = Gdx.graphics.getBackBufferWidth() * 0.5f; |
| 85 | + y = Gdx.graphics.getBackBufferHeight() - font.cellHeight * 3.5f; |
| 86 | + batch.begin(); |
| 87 | + font.enableShader(batch); |
| 88 | + font.drawGlyphs(batch, layout, x, y, Align.top); |
| 89 | + batch.end();// |
| 90 | + |
| 91 | + // Modified Pixmap.createFromFrameBuffer() code that uses RGB instead of RGBA |
| 92 | + Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1); |
| 93 | + final Pixmap pm = new Pixmap(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGB888); |
| 94 | + ByteBuffer pixels = pm.getPixels(); |
| 95 | + Gdx.gl.glReadPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), GL20.GL_RGB, GL20.GL_UNSIGNED_BYTE, pixels); |
| 96 | + // End Pixmap.createFromFrameBuffer() modified code |
| 97 | + |
| 98 | + PixmapIO.writePNG(Gdx.files.local("out/OpenMojiPreview.png"), pm, 2, true); |
| 99 | +// Gdx.app.exit(); |
| 100 | + startTime = TimeUtils.millis(); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public void render() { |
| 105 | + float bright = MathUtils.sin(TimeUtils.timeSinceMillis(startTime) * 3E-3f) * 0.25f + 0.4f; |
| 106 | + ScreenUtils.clear(bright, bright, bright, 1f); |
| 107 | + viewport.apply(true); |
| 108 | + batch.begin(); |
| 109 | + batch.setProjectionMatrix(viewport.getCamera().combined); |
| 110 | + font.enableShader(batch); |
| 111 | + font.drawGlyphs(batch, layout, x, y, Align.top); |
| 112 | + batch.end(); |
| 113 | + Gdx.graphics.setTitle(Gdx.graphics.getFramesPerSecond() + " FPS"); |
| 114 | + } |
| 115 | + |
| 116 | + @Override |
| 117 | + public void resize(int width, int height) { |
| 118 | + viewport.update(width, height, false); |
| 119 | + } |
| 120 | +} |
0 commit comments