public static Texture2D createTexture(string text, Font font, uint argb) { int width = font.GetTextWidth(text, 0, text.Length); int height = font.Metrics.Height; var image = new Image(ImageMode.Rgba, new ImageSize(width, height), new ImageColor(0, 0, 0, 0) ); image.DrawText(text, new ImageColor((int)((argb >> 16) & 0xff), (int)((argb >> 8) & 0xff), (int)((argb >> 0) & 0xff), (int)((argb >> 24) & 0xff)), font, new ImagePosition(0, 0) ); Texture2D texture; if (Thread.CurrentThread != Game.GAME_INSTANCE.getMainThread()) { LoadableTexture txt = new LoadableTexture(width, height, image); txt.loadNow(); texture = txt.getTexture(); } else { texture = new Texture2D(width, height, false, PixelFormat.Rgba); texture.SetPixels(0, image.ToBuffer(), 0, 0, width, height); } image.Dispose(); return(texture); }
private static void generateBuffers() { if (Chat.fb != null) { return; } Chat.fb = new ThreadSafeFrameBuffer(); Chat.db = new ThreadSafeDepthBuffer(150, 150); DisplayManager.getDisplayManager().addThreadSafeDepthBufferToMake(Chat.db); while (Chat.db.getDepthBuffer() == null) { continue; } Chat.bufferTexture = new LoadableTexture(Chat.db.getWidth(), Chat.db.getHeight()); bufferTexture.loadNow(); Chat.fb.setLoadableTextureToBind(Chat.bufferTexture); Chat.fb.setThreadSafeDepthBufferToBind(Chat.db); DisplayManager.getDisplayManager().addThreadSafeFrameBufferToMake(Chat.fb); while (Chat.fb.getFrameBuffer() == null) { continue; } }