public void RegisterFont(EFonts _font, string _fileName, int _pointSize) { if(!File.Exists(_fileName)) { throw new ApplicationException("Не найден файл " + Path.GetFullPath(_fileName)); } var charSet = new List<char>(); for (var c = ' '; c < '}'; ++c) { charSet.Add(c); } for (var c = 'А'; c <= 'я'; ++c) { charSet.Add(c); } var s = new string(charSet.ToArray()); var qfc = new QFontBuilderConfiguration { charSet = s, TextGenerationRenderHint = TextGenerationRenderHint.SizeDependent | TextGenerationRenderHint.AntiAlias, SuperSampleLevels = 4, }; var qFont = new QFont(_fileName, _pointSize, FontStyle.Bold, qfc); m_fonts[_font] = qFont; }
public QuickFontWrapper(Font font) { qf = new QuickFont.QFont(font, new QuickFont.QFontBuilderConfiguration(true) { TextGenerationRenderHint = QuickFont.TextGenerationRenderHint.ClearTypeGridFit }); qf.Options.CharacterSpacing = -0.1f; qf.Options.WordSpacing = 0.5f; qf.Options.LineSpacing = 1.2f; }
public PlayerNameState(GameEngine engine, MainMenuState ms) { eng = engine; mouse = eng.Mouse; savedGameStates = new Stack<XmlNodeList>(); savedGameChoices = new Stack<string>(); _ms = ms; Assembly assembly = Assembly.GetExecutingAssembly(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); _old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); menu = eng.StateTextureManager.GetTexture("menu"); saveFont = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); saveFont.Options.DropShadowActive = true; start_x = saveFont.Measure("Name: ").Width; //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true)); title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true)); title.Options.DropShadowActive = true; name = ""; numOfButtons = savedGameChoices.Count - 1; }
public SubmenuInfo(WormsGame game, GameMenu menu) { this.game = game; this.menu = menu; font = new QFont(new Font(game.DefaultFontFamily, 13f)); }
public IFont GetFont(string name, int size, Weight weight, bool italic) { var fontStyle = GetFontStyle(weight, italic); var fce = new FontCacheEntry { FontFace = name, FontSize = size, FontStyle = fontStyle }; QFont font; var config = new QFontBuilderConfiguration(false) { TextGenerationRenderHint = GetFontFaceRenderHintingPreference(name), GlyphMargin = 2, TransformToCurrentOrthogProjection = true, KerningConfig = { alphaEmptyPixelTolerance = 40, }, }; if (!_fontCache.TryGetValue(fce, out font)) { var sysFont = GetFontBestSizeFit(name, size, fontStyle); font = new QFont(sysFont, config); _fontCache[fce] = font; } return new WrappedFont(font); }
// End Fonts public PauseMenuState(GameEngine engine, MainMenuState menustate) { eng = engine; menu = menustate; lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); // _p1 = eng.StateTextureManager.GetTexture("p1"); // _p2 = eng.StateTextureManager.GetTexture("p2"); // _p3 = eng.StateTextureManager.GetTexture("p3"); // _p4 = eng.StateTextureManager.GetTexture("p4"); // QFont Assembly assembly = Assembly.GetExecutingAssembly(); eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); bg = eng.StateTextureManager.GetTexture("menu"); _buttons = new List<String>(); _buttons.Add("Continue??"); _buttons.Add("Main Menu"); _buttons.Add("Quit"); button = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); button.Options.DropShadowActive = true; //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true)); title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true)); title.Options.DropShadowActive = false; buttonHighlight = QFont.FromQFontFile("Fonts/myHappySans2.qfont", new QFontLoaderConfiguration(true)); buttonHighlight.Options.DropShadowActive = true; //QFont.CreateTextureFontFiles("Fonts/Rock.TTF", 48, "myRock"); // Use this to create new Fonts that you will texture // End QFonts // Set the current image to be displayed at 0 which is the first in the sequence curFrame = 0.0; }
public TextBlock(int x, int y, int width, int height, bool staticImage, string text, Sprite background) : base(x, y, width, height, staticImage) { _font = new QFont (SystemFonts.DialogFont); _background = background; _text = text; }
public static QFont FromQFontFile(string filePath, float downSampleFactor, QFontLoaderConfiguration loaderConfig) { QFont qfont = new QFont(); qfont.fontLoadDescription = new FontLoadDescription(filePath, downSampleFactor, loaderConfig); qfont.LoadQFontFromQFontFile(qfont.fontLoadDescription); return(qfont); }
public SizeF Print(QFont font, ProcessedText processedText, Vector3 position, Color?colour = null, Rectangle clippingRectangle = default(Rectangle)) { var dp = new QFontDrawingPimitive(font); var size = (colour.HasValue) ? dp.Print(processedText, position, colour.Value) : dp.Print(processedText, position); _glFontDrawingPimitives.Add(dp); return(size); }
public FontGroup(Font font) { _normal = new QFont(new Font(font, FontStyle.Regular)); _normal.Options.Monospacing = QFontMonospacing.Yes; _bold = new QFont(new Font(font, FontStyle.Bold)); _bold.Options.Monospacing = QFontMonospacing.Yes; _italic = new QFont(new Font(font, FontStyle.Italic)); _italic.Options.Monospacing = QFontMonospacing.Yes; }
public static void AddText(this QFontDrawing renderer, string text, QFont font, Color color, RectangleF bounds, StringAlignment vAlign = StringAlignment.Near, StringAlignment hAlign = StringAlignment.Near) { var dp = new QFontDrawingPrimitive(font, new QFontRenderOptions() { Colour = color, LockToPixel = true }); AddText(dp, text, bounds, vAlign, hAlign); }
/// <summary> /// Prints the specified text with the given alignment, color and clipping rectangle /// </summary> /// <param name="font">The <see cref="QFont"/> to print the text with</param> /// <param name="text">The text to print</param> /// <param name="position">The position of the text</param> /// <param name="alignment">The alignment of the text</param> /// <param name="color">The colour of the text</param> /// <param name="clippingRectangle">The clipping rectangle to scissor test the text with</param> /// <returns>The size of the printed text</returns> public SizeF Print(QFont font, string text, Vector3 position, QFontAlignment alignment, Color?color = null, Rectangle clippingRectangle = default(Rectangle)) { var dp = new QFontDrawingPrimitive(font); DrawingPrimitives.Add(dp); if (color.HasValue) { return(dp.Print(text, position, alignment, color.Value, clippingRectangle)); } return(dp.Print(text, position, alignment, clippingRectangle)); }
public static QFont FromQFontFile(string filePath, float downSampleFactor, QFontShadowConfiguration shadowConfig) { QFont qfont = new QFont(); qfont.fontData = Builder.LoadQFontDataFromFile(filePath, downSampleFactor, shadowConfig); if (shadowConfig != null) { qfont.options.DropShadowActive = true; } return(qfont); }
public QFont Load(string path, float downSampleFactor, QFontLoaderConfiguration loaderConfig) { if (loaderConfig == null) loaderConfig = new QFontLoaderConfiguration(); TransformViewport? transToVp = null; float fontScale = 1f; if (loaderConfig.TransformToCurrentOrthogProjection) transToVp = QFont.OrthogonalTransform(out fontScale); QFont qfont = new QFont(); qfont.fontData = new QFontData (); QFontDataInformation fontInfo = null; using (var fs = File.OpenRead (path)) { fontInfo = qfont.fontData.LoadFromStream (fs); } var bitmapFiles = fontInfo.GenerateBitmapPageNames (path); var bitmapPages = new List<QBitmap> (); foreach (var bitmapFileName in bitmapFiles) { // TODO : GDI+ require the bitmap files to be locked as indexed image // during the lifetime i.e. maybe reloaded from disk using (var fs = File.OpenRead (bitmapFileName)) using (var b = new Bitmap(fs)) { var qb = new QBitmap (bitmapFileName); bitmapPages.Add (qb); } } var glyphList = qfont.fontData.InitialiseQFontData (fontInfo, ref bitmapPages, downSampleFactor, loaderConfig); if (loaderConfig.ShadowConfig != null) { qfont.DropShadow = Helper.BuildDropShadow<QFont, QBitmap> ( bitmapPages, glyphList.ToArray (), loaderConfig.ShadowConfig, Helper.ToArray (fontInfo.CharSet), loaderConfig.KerningConfig.alphaEmptyPixelTolerance); } qfont.fontData.InitialiseKerningPairs (fontInfo, bitmapPages, glyphList, loaderConfig); if (loaderConfig.ShadowConfig != null) qfont.Options.DropShadowActive = true; if (transToVp != null) qfont.Options.TransformToViewport = transToVp; return qfont; }
public SizeF Print(QFont font, ProcessedText processedText, Vector3 position, Color?colour = null, Rectangle clippingRectangle = default(Rectangle)) { var dp = new QFontDrawingPimitive(font); DrawingPimitiveses.Add(dp); if (colour.HasValue) { return(dp.Print(processedText, position, colour.Value)); } else { return(dp.Print(processedText, position)); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); // základní prvky samotné okno hry font = new QFont(new Font(DefaultFontFamily, 16f)); cursor = LoadCursor("cursor_normal.cur"); // přídavky gameMenu = new GameMenu(this); // získá poslední velikost a pozici okna prevWindowRect = new Rectangle(Location.X, Location.Y, Width, Height); }
private int submenu = 0; // hlavní menu #endregion Fields #region Constructors public GameMenu(WormsGame game) { this.game = game; subInfo = new SubmenuInfo(game, this); items = new List<MenuItem>(); font = new QFont(new Font(game.DefaultFontFamily, 28f)); fontSelected = new QFont(new Font(game.DefaultFontFamily, 32f)); AddMenuItem( new MenuItem("Play", null), new MenuItem("Options", null), new MenuItem("Score", null), new MenuItem("Info", null), new MenuItem("Exit", () => { game.Exit(); }) ); }
public LoadGameState(GameEngine engine, MainMenuState ms) { eng = engine; mouse = eng.Mouse; savedGameStates = new Stack<XmlNodeList>(); savedGameChoices = new Stack<string>(); _ms = ms; Assembly assembly = Assembly.GetExecutingAssembly(); musicFile = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Music.Menu.ogg")); musicFile.Play(); // Clear the color to work with the SplashScreen so it doesn't white out //GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); _old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); menu = eng.StateTextureManager.GetTexture("menu"); saveFont = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); saveFont.Options.DropShadowActive = true; //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true)); title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true)); title.Options.DropShadowActive = true; saveFontHighlighted = QFont.FromQFontFile("Fonts/myHappySans2.qfont", new QFontLoaderConfiguration(true)); saveFont.Options.DropShadowActive = true; //QFont.CreateTextureFontFiles("Fonts/HappySans.ttf", 48, "myHappySans2"); // Load available saved games // Setup saved game data SavedGameDataSetup(); numOfButtons = savedGameChoices.Count - 1; }
public object LoadContent(ContentManager contentManager, string contentName, bool background) { Stream stream = FileSystemManager.Instance.OpenStream(contentName); if (stream == null) return null; byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); stream.Close(); IntPtr unmanagedPointer = Marshal.AllocHGlobal(bytes.Length); Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length); // TODO: Turn this more flexibile, maybee transfer this code to some font manager QFont result = new QFont(unmanagedPointer, bytes.Length, 8, FontStyle.Regular, new QFontBuilderConfiguration(false)); Marshal.FreeHGlobal(unmanagedPointer); return result; }
/// <summary> /// Creates node list object associated with the text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <returns></returns> public static ProcessedText ProcessText(QFont font, QFontRenderOptions options, string text, SizeF maxSize, QFontAlignment alignment) { //TODO: bring justify and alignment calculations in here maxSize.Width = TransformWidthToViewport(maxSize.Width, options); var nodeList = new TextNodeList(text); nodeList.MeasureNodes(font.FontData, options); //we "crumble" words that are two long so that that can be split up var nodesToCrumble = new List <TextNode>(); foreach (TextNode node in nodeList) { if ((!options.WordWrap || node.Length >= maxSize.Width) && node.Type == TextNodeType.Word) { nodesToCrumble.Add(node); } } foreach (TextNode node in nodesToCrumble) { nodeList.Crumble(node, 1); } //need to measure crumbled words nodeList.MeasureNodes(font.FontData, options); var processedText = new ProcessedText(); processedText.textNodeList = nodeList; processedText.maxSize = maxSize; processedText.alignment = alignment; return(processedText); }
// End Fonts public LevelStoryState(GameEngine engine, int lvl_being_loaded) { cur_page = 0; eng = engine; // _ps = ps; lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); lvl = lvl_being_loaded; // QFont //Assembly assembly = Assembly.GetExecutingAssembly(); //eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); //bg = eng.StateTextureManager.GetTexture("menu"); credit = QFont.FromQFontFile("Fonts/myStoryWhite.qfont", new QFontLoaderConfiguration(true, false)); credit.Options.DropShadowActive = false; button = QFont.FromQFontFile("Fonts/myStoryBright.qfont", new QFontLoaderConfiguration(true, false)); button.Options.DropShadowActive = true; // Set the current image to be displayed at 0 which is the first in the sequence curFrame = 0.0; }
/// <summary> /// Renders the glyph at the position given. /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="c">The character to print.</param> internal void RenderGlyph(float x, float y, char c, QFont font, IList <QVertex> store, Rectangle clippingRectangle) { QFontGlyph glyph = font.FontData.CharSetMapping[c]; //note: it's not immediately obvious, but this combined with the paramteters to //RenderGlyph for the shadow mean that we render the shadow centrally (despite it being a different size) //under the glyph if (font.FontData.isDropShadow) { x -= (int)(glyph.rect.Width * 0.5f); y -= (int)(glyph.rect.Height * 0.5f + glyph.yOffset); } else { RenderDropShadow(x, y, c, glyph, font.FontData.dropShadowFont, ref clippingRectangle); } y = -y; TexturePage sheet = font.FontData.Pages[glyph.page]; float tx1 = (float)(glyph.rect.X) / sheet.Width; float ty1 = (float)(glyph.rect.Y) / sheet.Height; float tx2 = (float)(glyph.rect.X + glyph.rect.Width) / sheet.Width; float ty2 = (float)(glyph.rect.Y + glyph.rect.Height) / sheet.Height; float vx = x + PrintOffset.X; float vy = y - glyph.yOffset + PrintOffset.Y; float vwidth = glyph.rect.Width; float vheight = glyph.rect.Height; if (clippingRectangle != default(Rectangle) && ScissorsTest(ref vx, ref vy, ref vwidth, ref vheight, ref tx1, ref ty1, ref tx2, ref ty2, clippingRectangle)) { return; } var tv1 = new Vector2(tx1, ty1); var tv2 = new Vector2(tx1, ty2); var tv3 = new Vector2(tx2, ty2); var tv4 = new Vector2(tx2, ty1); Vector3 v1 = new Vector3(vx, vy, PrintOffset.Z); Vector3 v2 = new Vector3(vx, vy - vheight, PrintOffset.Z); Vector3 v3 = new Vector3(vx + vwidth, vy - vheight, PrintOffset.Z); Vector3 v4 = new Vector3(vx + vwidth, vy, PrintOffset.Z); Color color; if (font.FontData.isDropShadow) { color = this.Options.DropShadowColour; } else { color = this.Options.Colour; } Vector4 colour = Helper.ToVector4(color); store.Add(new QVertex() { Position = v1, TextureCoord = tv1, VertexColor = colour }); store.Add(new QVertex() { Position = v2, TextureCoord = tv2, VertexColor = colour }); store.Add(new QVertex() { Position = v3, TextureCoord = tv3, VertexColor = colour }); store.Add(new QVertex() { Position = v1, TextureCoord = tv1, VertexColor = colour }); store.Add(new QVertex() { Position = v3, TextureCoord = tv3, VertexColor = colour }); store.Add(new QVertex() { Position = v4, TextureCoord = tv4, VertexColor = colour }); }
public static void Load() { BlockOverlays.Add(TetraminoType.I, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "I.png"))); BlockOverlays.Add(TetraminoType.O, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "O.png"))); BlockOverlays.Add(TetraminoType.J, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "J.png"))); BlockOverlays.Add(TetraminoType.L, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "L.png"))); BlockOverlays.Add(TetraminoType.S, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "S.png"))); BlockOverlays.Add(TetraminoType.Z, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "Z.png"))); BlockOverlays.Add(TetraminoType.T, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "T.png"))); BlockOverlaysSmall.Add(TetraminoType.I, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "Is.png"))); BlockOverlaysSmall.Add(TetraminoType.O, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "Os.png"))); BlockOverlaysSmall.Add(TetraminoType.J, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "Js.png"))); BlockOverlaysSmall.Add(TetraminoType.L, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "Ls.png"))); BlockOverlaysSmall.Add(TetraminoType.S, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "Ss.png"))); BlockOverlaysSmall.Add(TetraminoType.Z, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "Zs.png"))); BlockOverlaysSmall.Add(TetraminoType.T, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "Ts.png"))); BlockOverlaysSmall.Add(TetraminoType.Null, new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "Ns.png"))); LoadTexture(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "tetrion.png"), out TetrionTexture, out TetrionTextureSampler); LoadTexture(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "block.png"), out Block, out BlockSampler); LoadTexture(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "blockGhost.png"), out BlockGhost, out BlockGhostSampler); PanelBase = new Bitmap(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), TEXTURES_DIR), "panel.png")); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), MODELS_DIR), "blockCyan.xml"), FileMode.Open)) Blocks.Add(TetraminoColor.Cyan, new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp))); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), MODELS_DIR), "blockYellow.xml"), FileMode.Open)) Blocks.Add(TetraminoColor.Yellow, new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp))); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), MODELS_DIR), "blockPurple.xml"), FileMode.Open)) Blocks.Add(TetraminoColor.Purple, new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp))); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), MODELS_DIR), "blockGreen.xml"), FileMode.Open)) Blocks.Add(TetraminoColor.Green, new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp))); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), MODELS_DIR), "blockRed.xml"), FileMode.Open)) Blocks.Add(TetraminoColor.Red, new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp))); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), MODELS_DIR), "blockBlue.xml"), FileMode.Open)) Blocks.Add(TetraminoColor.Blue, new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp))); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), MODELS_DIR), "blockOrange.xml"), FileMode.Open)) Blocks.Add(TetraminoColor.Orange, new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp))); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), MODELS_DIR), "tetrion.xml"), FileMode.Open)) Tetrion = new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp)); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), MODELS_DIR), "panel.xml"), FileMode.Open)) Panel = new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp)); using (StreamReader vs = new StreamReader(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), SHADERS_DIR), "vs_simple.glsl"))) using (StreamReader fs = new StreamReader(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), SHADERS_DIR), "fs_simple.glsl"))) LoadShader(vs.ReadToEnd(), fs.ReadToEnd(), out Simple_vs, out Simple_fs, out Simple_Shader); LightPositionUniform = GL.GetUniformLocation(Simple_Shader, "lightPosition"); LightDiffuseUniform = GL.GetUniformLocation(Simple_Shader, "lightDiffuse"); SamplerUniform = GL.GetUniformLocation(Simple_Shader, "color_texture"); LiberationSans = new QFont(Path.Combine(Path.Combine(Path.Combine(START_DIR, RESOURCE_DIR), FONTS_DIR), "LiberationSans.ttf"), 64); LiberationSans.Options.Colour = new Color4(1.0f, 0.0f, 0.0f, 1.0f); }
public static QFont FromQFontFile(string filePath, float downSampleFactor, QFontLoaderConfiguration loaderConfig) { QFont qfont = new QFont(); qfont.fontLoadDescription = new FontLoadDescription(filePath,downSampleFactor,loaderConfig); qfont.LoadQFontFromQFontFile(qfont.fontLoadDescription); return qfont; }
private void PrintComment(QFont font, string comment,QFontAlignment alignment, ref float yOffset){ GL.PushMatrix(); yOffset += 20; GL.Translate(30f, yOffset, 0f); font.Print(comment, Width - 60, alignment); yOffset += font.Measure(comment, Width - 60, alignment).Height; GL.PopMatrix(); }
public void OnLoad(EventArgs e) { area.LoadContent(data); GL.ClearColor(area.ClearColor); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Texture2D); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); font = new QFont("Resources/Fonts/Cousine-Regular-Latin.ttf", 24); player = new Player(); Resources.Audio["wind.wav"].Looping = true; Resources.Audio["shipStaticLoop.wav"].Looping = true; Resources.Audio["start.wav"].Play(); }
private void RenderDropShadow(float x, float y, char c, QFontGlyph nonShadowGlyph, QFont shadowFont, ref Rectangle clippingRectangle) { //note can cast drop shadow offset to int, but then you can't move the shadow smoothly... if (shadowFont != null && this.Options.DropShadowActive) { float xOffset = (_font.FontData.meanGlyphWidth * this.Options.DropShadowOffset.X + nonShadowGlyph.rect.Width * 0.5f); float yOffset = (_font.FontData.meanGlyphWidth * this.Options.DropShadowOffset.Y + nonShadowGlyph.rect.Height * 0.5f + nonShadowGlyph.yOffset); this.RenderGlyph(x + xOffset, y + yOffset, c, shadowFont, this.ShadowVertexRepr, clippingRectangle); } }
/// <summary> /// Creates node list object associated with the text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <returns></returns> public static ProcessedText ProcessText(QFont font, QFontRenderOptions options, string text, SizeF maxSize, QFontAlignment alignment) { return(ProcessText(font.FontData, options, text, maxSize, alignment)); }
public QFont GetQFont(Font font) { QFont qfont; if(FontMap.TryGetValue(font, out qfont)) return qfont; var config = new QFontBuilderConfiguration() { UseVertexBuffer = true, TextGenerationRenderHint = TextGenerationRenderHint.AntiAliasGridFit }; qfont = new QFont(font, config); qfont.Options.TransformToViewport = null; qfont.Options.WordWrap = false; FontMap[font] = qfont; return qfont; }
public QFontDrawingPimitive(QFont font) { Font = font.FontData; Options = new QFontRenderOptions(); }
/// <summary>Load resources here.</summary> /// <param name="e">Not used.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); _heading1 = QFont.FromQFontFile("woodenFont.qfont", 1.0f, new QFontLoaderConfiguration(true)); GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.Disable(EnableCap.DepthTest); GL.Enable(EnableCap.PointSmooth); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.PointSize(10.0f); }
//public static void AddText(this QFontDrawing renderer, string text, QFont font, Color color, PointF position, QFontAlignment alignment = QFontAlignment.Left) //{ // AddText(renderer, text, font, color, new Vector2(position.X, position.Y), alignment); //} //public static void AddText(this QFontDrawing renderer, string text, QFont font, Color color, Vector2 position, QFontAlignment alignment = QFontAlignment.Left) //{ // var dp = new QFontDrawingPrimitive(font, new QFontRenderOptions() { Colour = color, LockToPixel = true }); // dp.Print(text, new Vector3(position), alignment); // renderer.DrawingPrimitives.Add(dp); //} public static void AddText(this QFontDrawing renderer, string text, QFont font, Color color, Vector4 bounds, StringAlignment vAlign = StringAlignment.Near, StringAlignment hAlign = StringAlignment.Near) { AddText(renderer, text, font, color, new RectangleF(bounds.X, bounds.Y, bounds.Z, bounds.W), vAlign, hAlign); }
private void PrintCommentWithLine(QFont font, string comment, QFontAlignment alignment, float xOffset, ref float yOffset) { GL.PushMatrix(); yOffset += 20; GL.Translate((int)xOffset, yOffset, 0f); font.Print(comment, alignment); var bounds = font.Measure(comment, Width-60, 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; GL.PopMatrix(); }
public QFontDrawingPimitive(QFont font, QFontRenderOptions options) { _font = font; Options = options; }
public QFontDrawingPimitive(QFont font) { _font = font; Options = new QFontRenderOptions(); }
private void InitOpenGLResources() { String fragSource = Properties.Resources.ps_FrontBack; String vertSource = Properties.Resources.vs_FrontBack; shader_frontback = GLEx.CreateShaderProgramStrings(vertSource, fragSource); GL.ClearColor(0.0f, 0.0f, 0.0f, 0f); GL.Enable(EnableCap.DepthTest); // Setup VBO state GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.IndexArray); try { codeText = new QFont("consolab.ttf", Properties.Resources.consolab, 10, FontStyle.Bold); } catch (System.Exception ex) { Debug.WriteLine(ex.ToString()); } GL.BindTexture(TextureTarget.Texture2D, 0); }
public void OnLoad(EventArgs e) { camera = new Camera(); camera.LoadProjection(); entities = new List<Entity>(); player = new Player(); map = new LevelMap(new Texture("Resources/Levels/" + level + ".png"), new Texture("Resources/Levels/" + level + "_col.png")); helpFont = new QFont("Resources/Fonts/anarchysans.ttf", 22); helpFont.Options.Colour = Color4.DarkRed; using (StreamReader reader = new StreamReader("Resources/Levels/" + level + ".txt")) { while (!reader.EndOfStream) { string line = reader.ReadLine(); string[] values = line.Split(' '); Vector2 pos = new Vector2(int.Parse(values[1]), int.Parse(values[2])); switch (values[0]) { case "Spawn": player.Position = pos; player.Position = pos; break; case "Generator": generator = new Generator(pos); entities.Add(generator); break; case "Lift": lift = new Lift(pos); entities.Add(lift); break; case "Pickaxe": entities.Add(new Pickaxe(pos, 0, true)); break; case "PickaxeB": entities.Add(new Pickaxe(pos, 0, false)); break; case "Skeleton": entities.Add(new Skeleton(0, pos)); break; case "Goblin": entities.Add(new Goblin(pos)); break; case "GameEnd": entities.Add(new Endgame(pos)); break; } } } fadeIn = new Mesh(1024, 768, Texture.Zero); fadePercent = 1f; fadingIn = true; GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Texture2D); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); }
public static QFont FromQFontFile(string filePath, float downSampleFactor, QFontLoaderConfiguration loaderConfig) { if (loaderConfig == null) loaderConfig = new QFontLoaderConfiguration(); TransformViewport? transToVp = null; float fontScale = 1f; if (loaderConfig.TransformToCurrentOrthogProjection) transToVp = OrthogonalTransform(out fontScale); QFont qfont = new QFont(); qfont.fontData = Builder.LoadQFontDataFromFile(filePath, downSampleFactor * fontScale, loaderConfig); if (loaderConfig.ShadowConfig != null) qfont.Options.DropShadowActive = true; if (transToVp != null) qfont.Options.TransformToViewport = transToVp; return qfont; }
public GameFont(QFont font, string fontType, Vector2 screenDimensions) { Font = font; FontType = fontType; OptimalScreenDimensions = screenDimensions; }
private void PrintWithBounds(QFont font, string text, RectangleF bounds, QFontAlignment alignment, ref float yOffset) { GL.Disable(EnableCap.Texture2D); GL.Color4(1.0f, 0f, 0f, 1.0f); float maxWidth = bounds.Width; float height = font.Measure(text, maxWidth, 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(); font.Print(text, maxWidth, alignment, new Vector2(bounds.X,bounds.Y)); yOffset += height; }
public Game() : base(800, 600, GraphicsMode.Default, "Rawbots") { VSync = VSyncMode.On; renderModeCount = 0; shadingModeCount = 0; if (IsWindows()) useFonts = true; config = Config.Load(); this.Width = config.ScreenWidth; this.Height = config.ScreenHeight; if (config.Fullscreen) this.WindowState = WindowState.Fullscreen; resourcePath = DetectResourcePath(); Mouse.Move += new EventHandler<MouseMoveEventArgs>(OnMouseMove); Keyboard.KeyDown += new EventHandler<KeyboardKeyEventArgs>(OnKeyDown); Keyboard.KeyUp += new EventHandler<KeyboardKeyEventArgs>(OnKeyUp); Console.WriteLine("{0}", resourcePath); if (useFonts) { font = new QFont(resourcePath + "/Fonts/Ubuntu-R.ttf", 16); font.Options.Colour = new Color4(1.0f, 1.0f, 1.0f, 1.0f); font.Options.DropShadowActive = false; monoFont = new QFont(resourcePath + "/Fonts/UbuntuMono-R.ttf", 16); monoFont.Options.Colour = new Color4(1.0f, 1.0f, 1.0f, 1.0f); monoFont.Options.DropShadowActive = false; } GL.Disable(EnableCap.Texture2D); }
public GameFont(QFont font, GameFontType fontType, Vector2 screenDimensions) { Font = font; OptimalScreenDimensions = screenDimensions; FontType = GetLookupString(fontType); }
public static void Draw(QFont font, string text, QFontAlignment alignment, Vector2 position) { position.Y -= font.Measure(text, alignment).Height / 2; font.Options.UseDefaultBlendFunction = false; font.Print(text, alignment, position); }
public static QFont FromQFontFile(IFontRenderer renderer, string filePath, float downSampleFactor = 1.0f, QFontLoaderConfiguration loaderConfig = null) { QFont qfont = new QFont(renderer); qfont.fontLoadDescription = new FontLoadDescription(filePath,downSampleFactor,loaderConfig); qfont.LoadQFontFromQFontFile(qfont.fontLoadDescription); return qfont; }