private void DrawPreview() { Dictionary <char, int> charsToBytes; lock (_charsToIndices) charsToBytes = ExpandCollectionArray(_charsToIndices); string text = Dispatcher.Invoke(() => PreviewTextBox.Text); GLRectangle rectangle = new GLRectangle { Height = 23 }; using (GLService.AcquireContext(GLControlElement.WindowInfo)) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); using (GLShaders.PalettedTexture.Use(_texture, _palette, _currentPalette)) _texture.Draw(0, 0, 0); for (int i = 0; i < _charactersWidths.Length; i++) { rectangle.X = (i % 21) * 24; rectangle.Y = (i / 21) * 24; rectangle.Width = _charactersWidths[i] * 2; if (i == _currentIndex) { rectangle.DrawSolid(SelectedColor); } else { rectangle.DrawBorder(GridColor); } } float x = 0; float y = _texture.Height + 24; using (GLShaders.PalettedTexture.Use(_texture, _palette, FF8TextTagColor.White - FF8TextTagColor.Disabled)) { foreach (char ch in text) { if (ch == '\r') { continue; } if (ch == '\n') { x = 0; y += 24; continue; } int index; if (charsToBytes.TryGetValue(ch, out index)) { index -= 32; const float h = 23; float w = _charactersWidths[index] * 2; _texture.Draw(x, y, 0, (index % 21) * 24f, (index / 21) * 24, w, h); x += w; } } } GL.Disable(EnableCap.Blend); } }