private void PrintComment(QFont font, string comment, QFontAlignment alignment, ref float yOffset, QFontRenderOptions opts) { yOffset += 20; var pos = new Vector3(30f, Height - yOffset, 0f); var dp = new QFontDrawingPrimitive(font, opts ?? new QFontRenderOptions()); dp.Print(comment, pos, new SizeF(Width - 60, -1), alignment); yOffset += dp.Measure(comment, new SizeF(Width - 60, -1), alignment).Height; _drawing.DrawingPrimitives.Add(dp); }
private void PrintCommentWithLine(QFont font, string comment, QFontAlignment alignment, float xOffset, ref float yOffset, QFontRenderOptions opts) { yOffset += 20; var dp = new QFontDrawingPrimitive(font, opts); dp.Print(comment, new Vector3(xOffset, Height - yOffset, 0f), new SizeF(Width - 60, -1), alignment); _drawing.DrawingPrimitives.Add(dp); var bounds = font.Measure(comment, new SizeF(Width - 60, float.MaxValue), alignment); yOffset += bounds.Height; }
public static void DrawText(string text, QFont font, RectangleF bounds, StringAlignment vAlign, StringAlignment hAlign, QFontRenderOptions options) { if (!Freetype6Loaded) { return; } var textSize = font.Measure(text, bounds.Size, QFontAlignment.Left); textSize.Height += 2; var textPos = Vector2.Zero; switch (hAlign) { case StringAlignment.Near: textPos.X = bounds.X; break; case StringAlignment.Far: textPos.X = bounds.Right - textSize.Width; break; case StringAlignment.Center: textPos.X = bounds.Left + ((bounds.Width - textSize.Width) / 2f); break; } switch (vAlign) { case StringAlignment.Near: textPos.Y = bounds.Y; break; case StringAlignment.Far: textPos.Y = bounds.Y + bounds.Height - textSize.Height; break; case StringAlignment.Center: textPos.Y = bounds.Y + ((bounds.Height - textSize.Height) / 2f); break; } textPos.Y = ViewSize.Y - textPos.Y; var dp = new QFontDrawingPrimitive(font, options); dp.Print(text, new Vector3(textPos.X, textPos.Y, 0f), bounds.Size, QFontAlignment.Left); TextRenderer.DrawingPrimitives.Add(dp); }
private void PrintWithBounds(QFont font, string text, RectangleF bounds, QFontAlignment alignment, ref float yOffset) { var maxWidth = bounds.Width; var height = font.Measure(text, new SizeF(maxWidth, -1), alignment).Height; var dp = new QFontDrawingPrimitive(font); dp.Print(text, new Vector3(bounds.X, Height - yOffset, 0), new SizeF(maxWidth, float.MaxValue), alignment); _drawing.DrawingPrimitives.Add(dp); yOffset += height; }
public static void DrawText(string text, QFont font, Color color, RectangleF bounds, StringAlignment vAlign = StringAlignment.Near, StringAlignment hAlign = StringAlignment.Near) { var textSize = font.Measure(text, bounds.Size, QFontAlignment.Left); textSize.Height += 2; var textPos = Vector2.Zero; switch (hAlign) { case StringAlignment.Near: textPos.X = bounds.X; break; case StringAlignment.Far: textPos.X = bounds.Right - textSize.Width; break; case StringAlignment.Center: textPos.X = bounds.Left + ((bounds.Width - textSize.Width) / 2f); break; } switch (vAlign) { case StringAlignment.Near: textPos.Y = bounds.Y; break; case StringAlignment.Far: textPos.Y = bounds.Y + bounds.Height - textSize.Height; break; case StringAlignment.Center: textPos.Y = bounds.Y + ((bounds.Height - textSize.Height) / 2f); break; } textPos.Y = ViewSize.Y - textPos.Y; var dp = new QFontDrawingPrimitive(font, new QFontRenderOptions() { Colour = color, LockToPixel = true }); dp.Print(text, new Vector3(textPos.X, textPos.Y, 0f), bounds.Size, QFontAlignment.Left); TextRenderer.DrawingPrimitives.Add(dp); }
public override void Update(double time, bool focused = false) { // Update total elapsed time _totalTime += time; if (InputSystem.NewKeys.Contains(Key.Escape)) { Exit(); } _player.Update(time); _centerPolygon.Update(time, false); DoGUI(); // Update next if needed if (_selectedItemChanged) { // Reset elapsed time _totalTime = 0; _menuFontDrawing.DrawingPrimitives.Clear(); _menuFDP = new QFontDrawingPrimitive(_menuFont.Font, _menuRenderOptions); _menuFDP.Print(_selectedMenuItemText.ToUpper(), Vector3.Zero, QFontAlignment.Centre); _menuFontDrawing.DrawingPrimitives.Add(_menuFDP); _selectedItemChanged = false; } // Pulse text var size = _menuFont.Font.Measure(_selectedMenuItemText.ToUpper()); var selectedSide = GetSelectedSide(); var newPos = new PolarVector(selectedSide * _centerPolygon.AngleBetweenSides + _centerPolygon.AngleBetweenSides * 0.5f, _player.Position.Radius + _player.Width + size.Height * 0.9); var extraRotation = (selectedSide >= 0 && selectedSide < 3) ? (-Math.PI / 2.0) : (Math.PI / 2.0); var extraOffset = (selectedSide >= 0 && selectedSide < 3) ? (0) : (-size.Height / 4); newPos.Radius += extraOffset; var cart = newPos.ToCartesianCoordinates(); var mvm = Matrix4.CreateTranslation(0, size.Height / 2, 0) * Matrix4.CreateScale(0.90f + (float)Math.Pow(Math.Sin(_totalTime * 3), 2) * 0.10f) * Matrix4.CreateRotationZ((float)(newPos.Azimuth + extraRotation)) * Matrix4.CreateTranslation(cart.X, cart.Y, 0); _menuFDP.ModelViewMatrix = mvm; }
private void PrintCommentWithLine(QFont font, string comment, QFontAlignment alignment, float xOffset, ref float yOffset, QFontRenderOptions opts) { yOffset += 20; var dp = new QFontDrawingPrimitive(font, opts); //if (doSpacing) // dp.Options.CharacterSpacing = 0.05f; dp.Print(comment, new Vector3(xOffset, Height - yOffset, 0f), new SizeF(Width - 60, -1), alignment); drawing.DrawingPrimitives.Add(dp); var bounds = font.Measure(comment, new SizeF(Width - 60, float.MaxValue), alignment); //GL.Disable(EnableCap.Texture2D); //GL.Begin(BeginMode.Lines); //GL.Color4(1.0f, 0f, 0f, 1f); GL.Vertex2(0f, 0f); //GL.Color4(1.0f, 0f, 0f, 1f); GL.Vertex2(0f, bounds.Height + 20f); //GL.End(); yOffset += bounds.Height; }
private void PrintWithBounds(QFont font, string text, RectangleF bounds, QFontAlignment alignment, ref float yOffset) { float maxWidth = bounds.Width; float height = font.Measure(text, new SizeF(maxWidth, -1), alignment).Height; //gl.begin(beginmode.lineloop); //gl.vertex3(bounds.x, bounds.y, 0f); //gl.vertex3(bounds.x + bounds.width, bounds.y, 0f); //gl.vertex3(bounds.x + bounds.width, bounds.y + height, 0f); //gl.vertex3(bounds.x, bounds.y + height, 0f); //gl.end(); var dp = new QFontDrawingPrimitive(font); dp.Print(text, new Vector3(bounds.X, Height - yOffset, 0), new SizeF(maxWidth, float.MaxValue), alignment); drawing.DrawingPrimitives.Add(dp); yOffset += height; }
/// <summary> /// Called when it is time to render the next frame. Add your rendering code here. /// </summary> /// <param name="e">Contains timing information.</param> protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _drawing.ProjectionMatrix = _projectionMatrix; _frameCount++; float yOffset = 0; if (_currentDemoPage != _previousPage) { _previousPage = _currentDemoPage; // we have to rebuild the stuff _drawing.DrawingPrimitives.Clear(); switch (_currentDemoPage) { case 0: { yOffset += _drawing.Print(_heading1, "ModernQuickFont", new Vector3((float)Width / 2, Height, 0), QFontAlignment.Centre, _heading1Options).Height; yOffset += _drawing.Print(_heading2, "Introduction #0", new Vector3(20, Height - yOffset, 0), QFontAlignment.Left, _heading2Options) .Height; yOffset += _drawing.Print(_mainText, _modernQuickFontIntro, new Vector3(30, Height - yOffset, 0), new SizeF(Width - 60f, -1), QFontAlignment.Left).Height; PrintCode(_modernIntroCode, ref yOffset); break; } case 1: { yOffset += _drawing.Print(_heading1, "QuickFont", new Vector3((float)Width / 2, Height, 0), QFontAlignment.Centre, _heading1Options).Height; yOffset += _drawing.Print(_heading2, "Introduction", new Vector3(20, Height - yOffset, 0), QFontAlignment.Left, _heading2Options) .Height; yOffset += 20f; _drawing.Print(_mainText, _introduction, new Vector3(30, Height - yOffset, 0), new SizeF(Width - 60f, -1), QFontAlignment.Justify); break; } case 2: { yOffset += _drawing.Print(_heading2, "Easy as ABC!", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, _heading2Options).Height; PrintComment(_usingQuickFontIsSuperEasy, ref yOffset); PrintCode(_loadingAFont1, ref yOffset); PrintComment(_andPrintWithIt, ref yOffset); PrintCode(_printWithFont1, ref yOffset); PrintComment(_itIsAlsoEasyToMeasure, ref yOffset); PrintCode(_measureText1, ref yOffset); PrintComment(oneOfTheFirstGotchas, ref yOffset); PrintCode(_loadingAFont2, ref yOffset); break; } case 3: { yOffset += _drawing.Print(_heading2, "Alignment", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, _heading2Options).Height; PrintCommentWithLine(_whenPrintingText, QFontAlignment.Left, 20f, ref yOffset); PrintCode(_printWithFont2, ref yOffset); PrintCommentWithLine(_righAlignedText, QFontAlignment.Right, 20f, ref yOffset); yOffset += 10f; PrintCommentWithLine(_centredTextAsYou, QFontAlignment.Centre, Width * 0.5f, ref yOffset); break; } case 4: { // in this stage force redraw and recreation of VBO every time: just divert last page _previousPage = -1; yOffset += _drawing.Print(_heading2, "Bounds and Justify", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, _heading2Options).Height; yOffset += 20; yOffset += _drawing.Print(_controlsText, "Press [Up], [Down] or [Enter]!", new Vector3(Width * 0.5f, Height - yOffset, 0f), QFontAlignment.Centre, _controlsTextOpts).Height; float boundShrink = (int)(350 * (1 - Math.Cos(_boundsAnimationCnt * Math.PI * 2))); yOffset += 15; PrintWithBounds(_mainText, _ofCourseItsNot, new RectangleF(30f + boundShrink * 0.5f, yOffset, Width - 60 - boundShrink, 350f), _cycleAlignment, ref yOffset); string printWithBounds = "myFont.Print(text, position, maxSize, QFontAlignment." + _cycleAlignment + ");"; yOffset += 15f; PrintCode(printWithBounds, ref yOffset); break; } case 5: { yOffset += _drawing.Print(_heading2, "Your own Texture Fonts", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, _heading2Options).Height; PrintComment(_anotherCoolFeature, ref yOffset); PrintCode(_textureFontCode1, ref yOffset); PrintComment(_thisWillHaveCreated, ref yOffset); break; } case 6: { yOffset += _drawing.Print(_heading2, "Your own Texture Fonts", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, _heading2Options).Height; PrintComment(_ifYouDoIntend, ref yOffset); PrintCode(_textureFontCode2, ref yOffset); PrintComment(_actuallyTexturing, ref yOffset); PrintCode(_textureFontCode3, ref yOffset); break; } case 7: { // in this stage force redraw and recreation of VBO every time: just divert last page _previousPage = -1; // store this primitive to remember QFontDrawingPrimitive dp = new QFontDrawingPrimitive(_heading2) { Options = { DropShadowActive = true, DropShadowOffset = new Vector2(0.1f + 0.2f * (float)Math.Sin(_cnt), 0.1f + 0.2f * (float)Math.Cos(_cnt)) } }; yOffset += dp.Print("Drop Shadows", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left).Height; _drawing.DrawingPrimitives.Add(dp); PrintComment(_asIhaveleant, ref yOffset); PrintCode(_dropShadowCode1, ref yOffset); PrintComment(_thisWorksFine, ref yOffset); PrintCode(_dropShadowCode2, ref yOffset); PrintComment(_onceAFont, ref yOffset); //mainText.Options.DropShadowActive = false; break; } case 8: { yOffset += _drawing.Print(_heading2, "Monospaced Fonts", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, _heading2Options).Height; QFontRenderOptions monoSpaceCondensed = _monoSpacedOptions.CreateClone(); monoSpaceCondensed.CharacterSpacing = 0.05f; PrintComment(_monoSpaced, _hereIsSomeMono, QFontAlignment.Left, ref yOffset, monoSpaceCondensed); PrintCode(_monoCode1, ref yOffset); PrintComment(_monoSpaced, _theDefaultMono, QFontAlignment.Left, ref yOffset, monoSpaceCondensed); PrintCommentWithLine(_monoSpaced, _mono, QFontAlignment.Left, 20f, ref yOffset, monoSpaceCondensed); yOffset += 2f; PrintCommentWithLine(_monoSpaced, _mono, QFontAlignment.Right, 20f, ref yOffset, monoSpaceCondensed); yOffset += 2f; PrintCommentWithLine(_monoSpaced, _mono, QFontAlignment.Centre, Width * 0.5f, ref yOffset, monoSpaceCondensed); yOffset += 2f; PrintComment(_monoSpaced, "As usual, you can adjust character spacing with myPrimitive.Options.CharacterSpacing.", QFontAlignment.Left, ref yOffset, monoSpaceCondensed); break; } case 9: { // in this stage force redraw and recreation of VBO every time: just divert last page _previousPage = -1; yOffset += _drawing.Print(_heading2, "Preprocessed Text", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left).Height; yOffset += 20f; _stopwatch = Stopwatch.StartNew(); yOffset += _drawing.Print(_mainText, _processedText, new Vector3(20, Height - yOffset, 0)).Height; _stopwatch.Stop(); long preprocessed = _stopwatch.Elapsed.Ticks; _stopwatch = Stopwatch.StartNew(); yOffset += _drawing.Print(_mainText, _nonPreProcessed, new Vector3(20, Height - yOffset, 0), new SizeF(Width - 40f, -1), QFontAlignment.Left) .Height; _stopwatch.Stop(); long notpreprocessed = _stopwatch.Elapsed.Ticks; if (_frameCount > 60) { _benchResult = string.Format(("{0} {1}\nPreprocessed was {2} ticks faster"), preprocessed, notpreprocessed, notpreprocessed - preprocessed); _frameCount = 0; } _drawing.Print(_benchmarkResults, _benchResult, new Vector3(Width * 0.5f, Height - yOffset, 0), QFontAlignment.Centre, Color.White); break; } case 10: { yOffset += _drawing.Print(_heading2, "In Conclusion", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, _heading2Options).Height; PrintComment(_thereAreActually, ref yOffset); break; } case 11: { yOffset += _drawing.Print(_heading2, "Different installed fonts", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, _heading2Options).Height + 20; foreach (var qFont in _installedFonts) { yOffset += _drawing.Print(qFont, "This text is printed with " + qFont.FontName, new Vector3(20f, Height - yOffset, 0), QFontAlignment.Left, Color.White).Height + 10; } break; } } _drawing.RefreshBuffers(); } // Create controlsDrawing every time.. would be also good to vary ProjectionMatrix with * Matrix4.CreateTranslation() ! // this would save buffer work for OpenGL _controlsDrawing.DrawingPrimitives.Clear(); _controlsDrawing.ProjectionMatrix = _projectionMatrix; if (_currentDemoPage != _lastPage) { var dim = _controlsText.Measure("Press [Right] ->"); Vector3 pos = new Vector3(Width - dim.Width / 2 - 16 * (float)(1 + Math.Sin(_cnt * 4)), _controlsText.Measure("P").Height + 10f, 0f); var dp = new QFontDrawingPrimitive(_controlsText, _controlsTextOpts); dp.ModelViewMatrix = Matrix4.CreateTranslation(0, dim.Height / 2, 0) * Matrix4.CreateRotationZ((float)MathHelper.DegreesToRadians(Math.Sin(_cnt * 4) * 15)) * Matrix4.CreateTranslation(pos); _controlsDrawing.DrawingPrimitives.Add(dp); dp.Print("Press [Right] ->", Vector3.Zero, QFontAlignment.Centre); } if (_currentDemoPage != 0) { var pos = new Vector3(10 + 16 * (float)(1 + Math.Sin(_cnt * 4)), _controlsText.Measure("P").Height + 10f, 0f); _controlsDrawing.Print(_controlsText, "<- Press [Left]", pos, QFontAlignment.Left, _controlsTextOpts); } _controlsDrawing.RefreshBuffers(); _controlsDrawing.Draw(); _drawing.Draw(); SwapBuffers(); }
public override void Draw(double time) { _optionsDrawing.DrawingPrimitives.Clear(); float lineStep = Math.Max(_optionsFont.MaxLineHeight, _valueFont.MaxLineHeight); float height = lineStep * _options.Count; float currentY = height / 2.0f; float unselectedValueScale = 0.8f; foreach (var op in _options) { var settingColour = Color4.Black; if (_options[_currentlySelectedOption] != op) { settingColour = Color.Black; settingColour.A = 0.50f; } var dp = new QFontDrawingPrimitive(_optionsFont.Font, new QFontRenderOptions { Colour = (Color)settingColour }); dp.Print(op.FriendlyName + ":", Vector3.Zero, QFontAlignment.Centre); dp.ModelViewMatrix = Matrix4.CreateTranslation(0, _optionsFont.MaxLineHeight * 0.5f, 0) * Matrix4.CreateTranslation(-WindowWidth * 0.15f, currentY, 0); _optionsDrawing.DrawingPrimitives.Add(dp); dp = new QFontDrawingPrimitive(_valueFont.Font, new QFontRenderOptions { Colour = (Color)settingColour }); var valueSize = dp.Print(op.GetValue(), Vector3.Zero, QFontAlignment.Centre); dp.ModelViewMatrix = Matrix4.CreateTranslation(0, _valueFont.MaxLineHeight * 0.5f, 0) * Matrix4.CreateTranslation(WindowWidth * 0.15f, currentY, 0); _optionsDrawing.DrawingPrimitives.Add(dp); if (op.CanMoveForward()) { dp = new QFontDrawingPrimitive(_valueFont.Font, new QFontRenderOptions { Colour = (Color)settingColour }); dp.Print(op.GetNextValue(), Vector3.Zero, QFontAlignment.Left); dp.ModelViewMatrix = Matrix4.CreateScale(unselectedValueScale) * Matrix4.CreateTranslation(WindowWidth * 0.15f + valueSize.Width * 1.25f, currentY + _valueFont.Font.MaxLineHeight * 0.5f * unselectedValueScale, 0); _optionsDrawing.DrawingPrimitives.Add(dp); } if (op.CanMoveBackward()) { dp = new QFontDrawingPrimitive(_valueFont.Font, new QFontRenderOptions { Colour = (Color)settingColour }); dp.Print(op.GetPrevValue(), Vector3.Zero, QFontAlignment.Right); dp.ModelViewMatrix = Matrix4.CreateScale(unselectedValueScale) * Matrix4.CreateTranslation(WindowWidth * 0.15f - valueSize.Width * 1.25f, currentY + _valueFont.Font.MaxLineHeight * 0.5f * unselectedValueScale, 0); _optionsDrawing.DrawingPrimitives.Add(dp); } currentY -= lineStep; } _optionsDrawing.RefreshBuffers(); _optionsDrawing.Draw(); }
public void Draw(double time) { _qfontDrawing.DrawingPrimitives.Clear(); var col = Color4.White; if (_fileSystemEntries.Count > 0) { var s = _selectedFont.Font.Measure(_fileSystemEntries[_directoryBrowserEntryIndex].Name); _parentManager.DrawTextLine(_fileSystemEntries[_directoryBrowserEntryIndex].Name, new Vector3(0, s.Height / 2.0f, 0), Color4.White, QFontAlignment.Centre, _selectedFont.Font); float startY = _unselectedFont.MaxLineHeight * (_halfEntryDrawCount) + s.Height * 0.5f + _unselectedFont.MaxLineHeight * 0.5f; for (int i = _directoryBrowserEntryIndex - (_halfEntryDrawCount); i < _directoryBrowserEntryIndex + _halfEntryDrawCount; i++) { if (i >= 0 && i < _fileSystemEntries.Count && i != _directoryBrowserEntryIndex) { _parentManager.DrawTextLine(_fileSystemEntries[i].Name, new Vector3(0, startY, 0), col, QFontAlignment.Centre, _unselectedFont.Font); } if (i == _directoryBrowserEntryIndex) { startY -= s.Height + _unselectedFont.MaxLineHeight * 1.5f; } if (i != _directoryBrowserEntryIndex) { startY -= _unselectedFont.MaxLineHeight; } } } // Draw file systems var size = _parentManager.DrawTextLine(_currentFileSystem.FriendlyName, new Vector3(0, (_parentManager.Height / 2), 0), Color4.White, QFontAlignment.Centre, _selectedFont.Font); int currentFSIndex = _fileSystemCollection.IndexOf(_currentFileSystem); // Draw two file systems on either side float unselectedFsScale = 0.9f; col = Color4.White; col.A = 1.0f; var dp = new QFontDrawingPrimitive(_selectedFont.Font, new QFontRenderOptions { Colour = (System.Drawing.Color)col }); // Draw next fs on right dp.Print( _fileSystemCollection[(currentFSIndex + 1 + _fileSystemCollection.Count) % _fileSystemCollection.Count].FriendlyName, Vector3.Zero, QFontAlignment.Left); dp.ModelViewMatrix = Matrix4.CreateTranslation(new Vector3(0, size.Height * 2.0f, 0)) * Matrix4.CreateScale(unselectedFsScale) * Matrix4.CreateTranslation(new Vector3(size.Width * 0.75f, _parentManager.Height / 2 - size.Height * 2.0f, 0)); _qfontDrawing.DrawingPrimitives.Add(dp); dp = new QFontDrawingPrimitive(_selectedFont.Font, new QFontRenderOptions { Colour = (System.Drawing.Color)col }); // Draw previous fs on left dp.Print( _fileSystemCollection[(currentFSIndex - 1 + _fileSystemCollection.Count) % _fileSystemCollection.Count].FriendlyName, Vector3.Zero, QFontAlignment.Right); dp.ModelViewMatrix = Matrix4.CreateTranslation(new Vector3(0, size.Height * 2.0f, 0)) * Matrix4.CreateScale(unselectedFsScale) * Matrix4.CreateTranslation(new Vector3(-size.Width * 0.75f, _parentManager.Height / 2 - size.Height * 2.0f, 0)); _qfontDrawing.DrawingPrimitives.Add(dp); _qfontDrawing.RefreshBuffers(); _qfontDrawing.Draw(); var searchString = string.Format("Search: {0}", _searchString); _parentManager.DrawTextLine(searchString, new Vector3(0, -(_parentManager.Height / 2) + _searchFont.MaxLineHeight, 0), Color4.White, QuickFont.QFontAlignment.Centre, _searchFont.Font); }
/// <summary> /// Called when it is time to render the next frame. Add your rendering code here. /// </summary> /// <param name="e">Contains timing information.</param> protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); drawing.ProjectionMatrix = _projectionMatrix; frameCount++; float yOffset = 0; //mainText.Begin(); //GL.Begin(BeginMode.Quads); //GL.Color3(1.0f, 1.0f, 1.0); GL.Vertex2(0, 0); //GL.Color3(0.9f, 0.9f, 0.9f); GL.Vertex2(0, Height); //GL.Color3(0.9f, 0.9f, 0.9f); GL.Vertex2(Width, Height); //GL.Color3(0.9f, 0.9f, 0.9f); GL.Vertex2(Width, 0); //GL.End(); //mainText.End(); if (currentDemoPage != _previousPage) { _previousPage = currentDemoPage; // we have to rebuild the stuff drawing.DrawingPrimitives.Clear(); switch (currentDemoPage) { case 0: { yOffset += drawing.Print(heading1, "ModernQuickFont", new Vector3((float)Width / 2, Height, 0), QFontAlignment.Centre, heading1Options).Height; yOffset += drawing.Print(heading2, "Introduction #0", new Vector3(20, Height - yOffset, 0), QFontAlignment.Left, heading2Options) .Height; yOffset += drawing.Print(mainText, modernQuickFontIntro, new Vector3(30, Height - yOffset, 0), new SizeF(Width - 60f, -1), QFontAlignment.Justify, new Rectangle(60, Height - 400, 200, 200)).Height; PrintCode(modernIntroCode, ref yOffset); break; } case 1: { yOffset += drawing.Print(heading1, "QuickFont", new Vector3((float)Width / 2, Height, 0), QFontAlignment.Centre, heading1Options).Height; yOffset += drawing.Print(heading2, "Introduction", new Vector3(20, Height - yOffset, 0), QFontAlignment.Left, heading2Options) .Height; yOffset += 20f; drawing.Print(mainText, introduction, new Vector3(30, Height - yOffset, 0), new SizeF(Width - 60f, -1), QFontAlignment.Justify); break; } case 2: { yOffset += drawing.Print(heading2, "Easy as ABC!", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, heading2Options).Height; PrintComment(usingQuickFontIsSuperEasy, ref yOffset); PrintCode(loadingAFont1, ref yOffset); PrintComment(andPrintWithIt, ref yOffset); PrintCode(printWithFont1, ref yOffset); PrintComment(itIsAlsoEasyToMeasure, ref yOffset); PrintCode(measureText1, ref yOffset); PrintComment(oneOfTheFirstGotchas, ref yOffset); PrintCode(loadingAFont2, ref yOffset); break; } case 3: { yOffset += drawing.Print(heading2, "Alignment", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, heading2Options).Height; PrintCommentWithLine(whenPrintingText, QFontAlignment.Left, 20f, ref yOffset); PrintCode(printWithFont2, ref yOffset); PrintCommentWithLine(righAlignedText, QFontAlignment.Right, 20f, ref yOffset); yOffset += 10f; PrintCommentWithLine(centredTextAsYou, QFontAlignment.Centre, Width * 0.5f, ref yOffset); break; } case 4: { // in this stage force redraw and recreation of VBO every time: just divert last page _previousPage = -1; yOffset += drawing.Print(heading2, "Bounds and Justify", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, heading2Options).Height; yOffset += 20; yOffset += drawing.Print(controlsText, "Press [Up], [Down] or [Enter]!", new Vector3(Width * 0.5f, Height - yOffset, 0f), QFontAlignment.Centre, controlsTextOpts).Height; float boundShrink = (int)(350 * (1 - Math.Cos(boundsAnimationCnt * Math.PI * 2))); yOffset += 15; PrintWithBounds(mainText, ofCourseItsNot, new RectangleF(30f + boundShrink * 0.5f, yOffset, Width - 60 - boundShrink, 350f), cycleAlignment, ref yOffset); string printWithBounds = "myFont.Print(text, position, maxSize, QFontAlignment." + cycleAlignment + ");"; yOffset += 15f; PrintCode(printWithBounds, ref yOffset); break; } case 5: { yOffset += drawing.Print(heading2, "Your own Texture Fonts", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, heading2Options).Height; PrintComment(anotherCoolFeature, ref yOffset); PrintCode(textureFontCode1, ref yOffset); PrintComment(thisWillHaveCreated, ref yOffset); break; } case 6: { yOffset += drawing.Print(heading2, "Your own Texture Fonts", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, heading2Options).Height; PrintComment(ifYouDoIntend, ref yOffset); PrintCode(textureFontCode2, ref yOffset); PrintComment(actuallyTexturing, ref yOffset); PrintCode(textureFontCode3, ref yOffset); break; } case 7: { // in this stage force redraw and recreation of VBO every time: just divert last page _previousPage = -1; // store this primitive to remember QFontDrawingPrimitive dp = new QFontDrawingPrimitive(heading2); dp.Options.DropShadowActive = true; dp.Options.DropShadowOffset = new Vector2(0.1f + 0.2f * (float)Math.Sin(cnt), 0.1f + 0.2f * (float)Math.Cos(cnt)); yOffset += dp.Print("Drop Shadows", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left).Height; drawing.DrawingPrimitives.Add(dp); PrintComment(asIhaveleant, ref yOffset); PrintCode(dropShadowCode1, ref yOffset); PrintComment(thisWorksFine, ref yOffset); PrintCode(dropShadowCode2, ref yOffset); PrintComment(onceAFont, ref yOffset); //mainText.Options.DropShadowActive = false; break; } case 8: { yOffset += drawing.Print(heading2, "Monospaced Fonts", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, heading2Options).Height; QFontRenderOptions monoSpaceCondensed = monoSpacedOptions.CreateClone(); monoSpaceCondensed.CharacterSpacing = 0.05f; PrintComment(monoSpaced, hereIsSomeMono, QFontAlignment.Left, ref yOffset, monoSpaceCondensed); PrintCode(monoCode1, ref yOffset); PrintComment(monoSpaced, theDefaultMono, QFontAlignment.Left, ref yOffset, monoSpaceCondensed); PrintCommentWithLine(monoSpaced, mono, QFontAlignment.Left, 20f, ref yOffset, monoSpaceCondensed); yOffset += 2f; PrintCommentWithLine(monoSpaced, mono, QFontAlignment.Right, 20f, ref yOffset, monoSpaceCondensed); yOffset += 2f; PrintCommentWithLine(monoSpaced, mono, QFontAlignment.Centre, Width * 0.5f, ref yOffset, monoSpaceCondensed); yOffset += 2f; PrintComment(monoSpaced, "As usual, you can adjust character spacing with myPrimitive.Options.CharacterSpacing.", QFontAlignment.Left, ref yOffset, monoSpaceCondensed); break; } case 9: { // in this stage force redraw and recreation of VBO every time: just divert last page _previousPage = -1; yOffset += drawing.Print(heading2, "Preprocessed Text", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left).Height; yOffset += 20f; _stopwatch = Stopwatch.StartNew(); yOffset += drawing.Print(mainText, _processedText, new Vector3(20, Height - yOffset, 0)).Height; _stopwatch.Stop(); long preprocessed = _stopwatch.Elapsed.Ticks; _stopwatch = Stopwatch.StartNew(); yOffset += drawing.Print(mainText, nonPreProcessed, new Vector3(20, Height - yOffset, 0), new SizeF(Width - 40f, -1), QFontAlignment.Left) .Height; _stopwatch.Stop(); long notpreprocessed = _stopwatch.Elapsed.Ticks; if (frameCount > 60) { _benchResult = string.Format(("{0} {1}\nPreprocessed was {2} ticks faster"), preprocessed, notpreprocessed, notpreprocessed - preprocessed); frameCount = 0; } drawing.Print(_benchmarkResults, _benchResult, new Vector3(Width * 0.5f, Height - yOffset, 0), QFontAlignment.Centre, Color.White); break; } case 10: { yOffset += drawing.Print(heading2, "In Conclusion", new Vector3(20f, Height - yOffset, 0f), QFontAlignment.Left, heading2Options).Height; PrintComment(thereAreActually, ref yOffset); break; } } drawing.RefreshBuffers(); } // Create controlsDrawing every time.. would be also good to vary ProjectionMatrix with * Matrix4.CreateTranslation() ! // this would save buffer work for OpenGL controlsDrawing.DrawingPrimitives.Clear(); controlsDrawing.ProjectionMatrix = _projectionMatrix; if (currentDemoPage != lastPage) { Vector3 pos = new Vector3(Width - 10 - 16 * (float)(1 + Math.Sin(cnt * 4)), controlsText.Measure("P").Height + 10f, 0f); controlsDrawing.Print(controlsText, "Press [Right] ->", pos, QFontAlignment.Right, controlsTextOpts); } if (currentDemoPage != 0) { var pos = new Vector3(10 + 16 * (float)(1 + Math.Sin(cnt * 4)), controlsText.Measure("P").Height + 10f, 0f); controlsDrawing.Print(controlsText, "<- Press [Left]", pos, QFontAlignment.Left, controlsTextOpts); } controlsDrawing.RefreshBuffers(); controlsDrawing.Draw(); drawing.Draw(); SwapBuffers(); }