/// <summary> /// Initialise QFont from a font file /// </summary> /// <param name="fontPath">The font file to load</param> /// <param name="size">The size.</param> /// <param name="config">The configuration.</param> /// <param name="style">The style.</param> /// <param name="currentProjectionMatrix">The current projection matrix to create a font pixel perfect, for.</param> public QFont(string fontPath, float size, QFontBuilderConfiguration config, FontStyle style = FontStyle.Regular, Matrix4 currentProjectionMatrix = default(Matrix4)) { Viewport? transToVp = null; float fontScale = 1f; if (config.TransformToCurrentOrthogProjection) transToVp = OrthogonalTransform(out fontScale, currentProjectionMatrix); using (Font font = GetFont(fontPath, size, style, config == null ? 1 : config.SuperSampleLevels, fontScale)) { _fontName = font.ToString(); InitialiseGlFont(font, config); } // TODO: What to do with transToVp? Property:Matrix4 and use in QFontDrawing? //if (transToVp != null)_fontData.Pages // Options.TransformToViewport = transToVp; }
private void InitialiseGlFont(Font font, QFontBuilderConfiguration config, QFontData data = null) { _fontData = data ?? BuildFont(font, config, null); // Check and fail if more than one texture was generated. The original implementation of QFont supported // this by choosing them as the come but this ModernOpenGl -implementation would be handycapped by // allowing this degree of freedom. It is now possible to call DrawArrays for whole texts (requiring // shadows and text to be each 1 texture). This is quite efficient. // To cover it from another aspect: OpenGL 3.1 and more easily allow Textures of up to 8129² not // necessrily being base2 and square - this generousity should be hapily used and effiency be gained. // So there will be no implementation of VAO VBO based "Modern" OpenGL that is limited to 512 textures. // So this is a well takeable tradeoff if( _fontData.Pages.Length != 1 || (_fontData.dropShadowFont != null && _fontData.dropShadowFont.FontData.Pages.Length != 1)) { throw new NotSupportedException("The implementation of QFontDrawing does not support multiple textures per Font/Shadow. " + "Thus this font can not be properly rendered in all cases. Reduce number of characters " + "or increase QFontBuilderConfiguration.MaxTexSize QFontShadowConfiguration.PageMaxTextureSize " + "to contain all characters/char-shadows in one Bitmap=>Texture."); } }
/// <summary> /// Initialise QFont from a System.Drawing.Font object /// </summary> /// <param name="font"></param> /// <param name="config"></param> public QFont(Font font, QFontBuilderConfiguration config = null) { InitialiseGlFont(font, config); }
public static void CreateTextureFontFiles(string fileName, float size, string newFontName, QFontBuilderConfiguration config, FontStyle style = FontStyle.Regular) { using (Font font = GetFont(fileName, size, style, config == null ? 1 : config.SuperSampleLevels)) { CreateTextureFontFiles(font, newFontName, config); } }
private static QFontData BuildFont(Font font, QFontBuilderConfiguration config, string saveName) { var builder = new Builder(font, config); return builder.BuildFontData(saveName); }
public Builder(Font font, QFontBuilderConfiguration config) { this.charSet = config.charSet; this.config = config; this.font = font; }
public static void CreateTextureFontFiles(Font font, string newFontName, QFontBuilderConfiguration config) { QFontData fontData = BuildFont(font, config, newFontName); Builder.SaveQFontDataToFile(fontData, newFontName); }
void drawGrid() { QFontBuilderConfiguration vonfig = new QFontBuilderConfiguration(); GL.PushAttrib(AttribMask.EnableBit); QFont font = new QFont(Font); font.Options.Colour = new OpenTK.Graphics.Color4(0, 0, 0, 1.0f); GL.PopAttrib(); //do minor lines first float min = unTransformY(0); float max = unTransformY(Height); int exp = (int)(Math.Floor(Math.Log10(max - min))); double d = Math.Pow(10.0, exp); d *= .1; //if((max-min)/d < 3) d*=.1; double graphmin = Math.Floor(min / d) * d; double graphmax = Math.Ceiling(max / d) * d; float alpha = (float)(1.0f - (150.0f - d * m_ScaleY) / 150.0f); alpha = Math.Max(alpha, 0.0f); alpha = Math.Min(alpha, 1.0f); GL.Color4(0, 0, 0, alpha / 2.0f); GL.LineWidth(1.5f); GL.Begin(BeginMode.Lines); for (double y = graphmin; y < graphmax + .5 * d; y += d) { int yi = (int)transformY((float)y); GL.Vertex2(0, yi); GL.Vertex2(Width, yi); } GL.End(); //now major d *= 10; graphmin = Math.Floor(min / d) * d; graphmax = Math.Ceiling(max / d) * d; alpha = (float)(1.0f - (150.0 - d * m_ScaleY) / 150.0); alpha = Math.Max(alpha, 0.0f); alpha = Math.Min(alpha, 1.0f); for (double y = graphmin; y < graphmax + .5 * d; y += d) { GL.Color4(0.0f, 0.0f, 0, alpha / 2.0f); GL.Begin(BeginMode.Lines); int yi = (int)transformY((float)y); GL.Vertex2(0, yi); GL.Vertex2(Width, yi); GL.End(); GL.PushAttrib(AttribMask.EnableBit); QFontBegin(); font.Print(string.Format("{0:G}", y), new Vector2(5, Height - yi)); QFontEnd(); GL.PopAttrib(); } /////////////////////////////////////////////////////////////// ////do minor lines first min = unTransformX(0); max = unTransformX(Width); exp = (int)(Math.Floor(Math.Log10(max - min))); d = Math.Pow(10.0, exp); d *= .1; //if((max-min)/d < 3) d*=.1; graphmin = Math.Floor(min / d) * d; graphmax = Math.Ceiling(max / d) * d; alpha = (float)(1.0 - (150.0 - d * TotalScaleX) / 150.0); alpha = Math.Max(alpha, 0.0f); alpha = Math.Min(alpha, 1.0f); GL.Color4(0, 0, 0, alpha / 2.0f); GL.Begin(BeginMode.Lines); for (double x = graphmin; x < graphmax + .5 * d; x += d) { int xi = (int)transformX((float)x); GL.Vertex2(xi, 0); GL.Vertex2(xi, Height); } GL.End(); //now major d *= 10; graphmin = Math.Floor(min / d) * d; graphmax = Math.Ceiling(max / d) * d; alpha = (float)(1.0 - (150.0 - d * TotalScaleX) / 150.0); alpha = Math.Max(alpha, 0.0f); alpha = Math.Min(alpha, 1.0f); for (double x = graphmin; x < graphmax + .5 * d; x += d) { GL.Color4(0, 0, 0, alpha / 2.0f); GL.Begin(BeginMode.Lines); int xi = (int)transformX((float)x); GL.Vertex2(xi, 0); GL.Vertex2(xi, Height); GL.End(); GL.PushAttrib(AttribMask.EnableBit); QFontBegin(); font.Print(string.Format("{0:G}", x), new Vector2(xi + 15, 5)); QFontEnd(); GL.PopAttrib(); } }
public ButtonBackup(ShaderProgram program, string text, Color4 colour, int x, int y, int width, int height, int windowWidth, int windowHeight, Matrix4 projection, Func <Task> execDelegate, LayoutAlign layoutAlign = LayoutAlign.TopRight, string fontLocation = "arial") : base(program) { LayoutAlign = layoutAlign; WindowWidth = windowWidth; WindowHeight = windowHeight; switch (LayoutAlign) { case LayoutAlign.TopRight: X = x; Y = WindowHeight - y; Width = width; Height = -height; break; case LayoutAlign.TopLeft: X = WindowWidth - x; Y = WindowHeight - y; Width = width; Height = -height; break; case LayoutAlign.BottomRight: X = x; Y = y; Width = width; Height = -height; break; case LayoutAlign.BottomLeft: X = WindowWidth - x; Y = y; Width = width; Height = -height; break; default: X = x; Y = y; Width = width; Height = height; break; } // Create model, then populate button positional data to that model data. Vertices = new Vertex[] { new Vertex(// Top left new Vector3(X, Y, 0.0f), colour, new Vector2(0.0f, 0.0f)), new Vertex(// Top right new Vector3(X + Width, Y, 0.0f), colour, new Vector2(1.0f, 0.0f)), new Vertex(// Bottom right new Vector3(X + Width, Y + Height, 0.0f), colour, new Vector2(1.0f, 1.0f)), new Vertex(// Bottom left new Vector3(X, Y + Height, 0.0f), colour, new Vector2(0.0f, 1.0f)) }; Indices = new int[] { 0, 1, 2, 0, 3, 2 }; Text = text; State = ButtonState.NotPressed; ProjectionMatrix = projection; ExecDelegate = execDelegate; // Configure text LabelDrawing = new QFontDrawing(); var builderConfig = new QFontBuilderConfiguration(true) { ShadowConfig = { BlurRadius = 2, BlurPasses = 1, Type = ShadowType.Blurred }, TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit, Characters = CharacterSet.General | CharacterSet.Japanese | CharacterSet.Thai | CharacterSet.Cyrillic }; LabelFont = new QFont(@"Resources\Fonts\" + fontLocation + ".ttf", 12, builderConfig); // Buffer text. LabelDrawing.DrawingPrimitives.Clear(); LabelDrawing.Print(LabelFont, Text, new Vector3(X + (Width / 2), Y, 0.0f), new SizeF(Width, Height), QFontAlignment.Centre, new QFontRenderOptions() { WordWrap = false }); LabelDrawing.RefreshBuffers(); }
/// <summary>Load resources here.</summary> /// <param name="e">Not used.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); _drawing = new QFontDrawing(); _controlsDrawing = new QFontDrawing(); _controlsTextOpts = new QFontRenderOptions { Colour = Color.FromArgb(new Color4(0.8f, 0.1f, 0.1f, 1.0f).ToArgb()), DropShadowActive = true }; _heading2 = new QFont("woodenFont.qfont", new QFontConfiguration(true)); _heading2Options = new QFontRenderOptions { Colour = Color.White, DropShadowActive = true }; var builderConfig = new QFontBuilderConfiguration(true) { ShadowConfig = { BlurRadius = 2, BlurPasses = 1, Type = ShadowType.Blurred }, TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit, Characters = CharacterSet.General | CharacterSet.Japanese | CharacterSet.Thai | CharacterSet.Cyrillic }; //reduce blur radius because font is very small //best render hint for this font _mainText = new QFont("Fonts/times.ttf", 14, builderConfig); _mainTextOptions = new QFontRenderOptions { DropShadowActive = true, Colour = Color.White, WordSpacing = 0.5f }; _benchmarkResults = new QFont("Fonts/times.ttf", 14, builderConfig); _heading1 = new QFont("Fonts/HappySans.ttf", 72, new QFontBuilderConfiguration(true)); _controlsText = new QFont("Fonts/HappySans.ttf", 32, new QFontBuilderConfiguration(true)); _codeText = new QFont("Fonts/Comfortaa-Regular.ttf", 12, new QFontBuilderConfiguration()); _heading1Options = new QFontRenderOptions { Colour = Color.FromArgb(new Color4(0.2f, 0.2f, 0.2f, 1.0f).ToArgb()), DropShadowActive = true }; _processedText = QFontDrawingPrimitive.ProcessText(_mainText, _mainTextOptions, _preProcessed, new SizeF(Width - 40, -1), QFontAlignment.Left); _codeTextOptions = new QFontRenderOptions { Colour = Color.FromArgb(new Color4(0.0f, 0.0f, 0.4f, 1.0f).ToArgb()) }; _monoSpaced = new QFont("Fonts/Anonymous.ttf", 10, new QFontBuilderConfiguration()); _monoSpacedOptions = new QFontRenderOptions { Colour = Color.FromArgb(new Color4(0.1f, 0.1f, 0.1f, 1.0f).ToArgb()), DropShadowActive = true }; // loop through some installed fonts and load them var ifc = new InstalledFontCollection(); _installedFonts = new List <QFont>(); foreach (var fontFamily in ifc.Families) { // Don't load too many fonts if (_installedFonts.Count > 15) { break; } _installedFonts.Add(new QFont(fontFamily.Name, 14, new QFontBuilderConfiguration())); } GL.ClearColor(Color4.CornflowerBlue); }
public void initializeGL() { GL.ClearColor(Color4.White); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); // Blending GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); // Z-buffer GL.ClearDepth(1.0f); GL.DepthMask(true); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.DepthTest); // Stencil GL.ClearStencil(0); GL.Enable(EnableCap.StencilTest); GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace); // Smoothing GL.Enable(EnableCap.PolygonSmooth); GL.Enable(EnableCap.LineSmooth); GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Nicest); GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest); GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest); // Sizes GL.PointSize(DrawOptions.pointSize); GL.LineWidth(DrawOptions.lineWidth); // Defining all the colors for further selection availableColors_ = new List <Color4>() { Color4.Blue, Color4.Green, Color4.DarkOrange, Color4.Red, Color4.SaddleBrown, Color4.Purple, Color4.DarkBlue, Color4.DarkCyan, Color4.Chocolate }; selection_ = new Dictionary <string, List <uint> >(); sequenceSelection_ = new List <string>(); selectionColor_ = Color4.HotPink; // Update drawing constants DrawOptions.update(glControl_.Width, glControl_.Height); // Transformations location_ = Vector3.Zero; modelTranslation_ = Matrix4.Identity; modelScale_ = Matrix4.CreateScale(DrawOptions.defaultScale, DrawOptions.defaultScale, 1.0f); modelRotation_ = Matrix4.Identity; view_ = Matrix4.Identity; projection_ = Matrix4.CreateOrthographic(glControl_.Width, glControl_.Height, DrawOptions.zNear, DrawOptions.zFar); // Markers isShowNodeMarkers = true; // Fonts isShowNodeNames = false; fontDrawing_ = new QFontDrawing(); var builderConfig = new QFontBuilderConfiguration(true) { TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit, Characters = CharacterSet.General | CharacterSet.Japanese | CharacterSet.Thai | CharacterSet.Cyrillic }; font_ = new QFont("Optima", 8, builderConfig); fontRenderOptions_ = new QFontRenderOptions() { Colour = Color.Black, DropShadowActive = false, CharacterSpacing = 0.1f }; // Compiling the shader shader_ = new Shader(shaderPath_ + "shaders/shader.vert", shaderPath_ + "shaders/shader.frag"); // Lighting isLighting = true; shader_.SetVector3("light.ambient", LightingOptions.lightAmbient); shader_.SetVector3("light.diffuse", LightingOptions.lightDiffuse); shader_.SetVector3("light.specular", LightingOptions.lightSpecular); // Light attenuation constants shader_.SetFloat("light.constant", LightingOptions.lightConstant); shader_.SetFloat("light.linear", LightingOptions.lightLinear); shader_.SetFloat("light.quadratic", LightingOptions.lightQuadratic); // Material shader_.SetVector3("material.ambient", LightingOptions.materialAmbient); shader_.SetVector3("material.diffuse", LightingOptions.materialDiffuse); shader_.SetVector3("material.specular", LightingOptions.materialSpecular); shader_.SetFloat("material.shininess", LightingOptions.materialShininess); // Coordinate system coordinateSystem_ = new CoordinateSystem(); coordinateSystem_.font = font_; coordinateSystem_.shader = shader_; coordinateSystemOrigin_ = new Vector3(DrawOptions.originSystemX, DrawOptions.originSystemY, DrawOptions.originSystemZ); coordinateSystemScaleTranslation_ = Matrix4.CreateScale(DrawOptions.defaultScale, DrawOptions.defaultScale, 1.0f) * Matrix4.CreateTranslation(coordinateSystemOrigin_); // Viewport prevControlWidth_ = glControl_.Width; prevControlHeight_ = glControl_.Height; }
/// <summary>Load resources here.</summary> /// <param name="e">Not used.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.Keyboard.KeyDown += KeyDown; drawing = new QFontDrawing(); controlsDrawing = new QFontDrawing(); controlsTextOpts = new QFontRenderOptions() { Colour = Color.FromArgb(new Color4(0.8f, 0.1f, 0.1f, 1.0f).ToArgb()), DropShadowActive = true }; heading2 = new QFont("woodenFont.qfont", new QFontConfiguration(addDropShadow: true), 1.0f); heading2Options = new QFontRenderOptions() { Colour = Color.White, DropShadowActive = true}; var builderConfig = new QFontBuilderConfiguration(addDropShadow: true); builderConfig.ShadowConfig.blurRadius = 2; //reduce blur radius because font is very small builderConfig.ShadowConfig.blurPasses = 1; builderConfig.ShadowConfig.Type = ShadowType.Blurred; builderConfig.TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit; //best render hint for this font mainText = new QFont("Fonts/times.ttf", 14, builderConfig); mainTextOptions = new QFontRenderOptions() { DropShadowActive = true, Colour = Color.White, WordSpacing = 0.5f}; _benchmarkResults = new QFont("Fonts/times.ttf", 14, builderConfig); heading1 = new QFont("Fonts/HappySans.ttf", 72, new QFontBuilderConfiguration(true)); controlsText = new QFont("Fonts/HappySans.ttf", 32, new QFontBuilderConfiguration(true)); codeText = new QFont("Fonts/Comfortaa-Regular.ttf", 12, new QFontBuilderConfiguration()); heading1Options = new QFontRenderOptions() { Colour = Color.FromArgb(new Color4(0.2f, 0.2f, 0.2f, 1.0f).ToArgb()), DropShadowActive = true}; _processedText = QFontDrawingPimitive.ProcessText(mainText, mainTextOptions, preProcessed, new SizeF(Width - 40, -1), QFontAlignment.Justify); codeTextOptions = new QFontRenderOptions() { Colour = Color.FromArgb(new Color4(0.0f, 0.0f, 0.4f, 1.0f).ToArgb()) }; monoSpaced = new QFont("Fonts/Anonymous.ttf", 10, new QFontBuilderConfiguration()); monoSpacedOptions = new QFontRenderOptions() { Colour = Color.FromArgb(new Color4(0.1f, 0.1f, 0.1f, 1.0f).ToArgb()), DropShadowActive = true}; GL.ClearColor(Color4.CornflowerBlue); }