Ejemplo n.º 1
0
        public GLFont(Font font, GLFontEngine eng)
        {
            Engine = eng;
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            Engine.Shaders.ColorMultShader.Bind();
            Name               = font.Name;
            Size               = (int)(font.Size * eng.TheClient.DPIScale);
            Bold               = font.Bold;
            Italic             = font.Italic;
            Height             = font.Height;
            CharacterLocations = new List <RectangleF>();
            StringFormat sf = new StringFormat(StringFormat.GenericTypographic);

            sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap;
            Internal_Font   = font;
            Bitmap bmp = new Bitmap(Engine.bwidth, Engine.bheight);

            GL.BindTexture(TextureTarget.Texture2DArray, Engine.Texture3D);
            Characters = Engine.textfile;
            using (Graphics gfx = Graphics.FromImage(bmp))
            {
                gfx.Clear(Color.Transparent);
                gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                float X = 6;
                float Y = 0;
                gfx.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, 5, (int)Height));
                Brush brush = new SolidBrush(Color.White);
                for (int i = 0; i < Engine.textfile.Length; i++)
                {
                    string chr    = Engine.textfile[i] == '\t' ? "    " : Engine.textfile[i].ToString();
                    float  nwidth = (float)Math.Ceiling(gfx.MeasureString(chr, font, new PointF(0, 0), sf).Width);
                    if (font.Italic)
                    {
                        nwidth += 2;
                    }
                    if (X + nwidth >= Engine.bwidth)
                    {
                        Y += Height + 8;
                        X  = 6;
                    }
                    gfx.DrawString(chr, font, brush, new PointF(X, Y), sf);
                    CharacterLocations.Add(new RectangleF(X, Y, nwidth, Height));
                    X += nwidth + 8f;
                }
            }
            BitmapData data = bmp.LockBits(new Rectangle(0, 0, Engine.bwidth, Engine.bheight), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexSubImage3D(TextureTarget.Texture2DArray, 0, 0, 0, cZ, Engine.bwidth, Engine.bheight, 1, OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
            TexZ = cZ;
            cZ++;
            cZ = cZ % 48;
            // TODO: Handle > 24 fonts more cleanly
            bmp.UnlockBits(data);
            bmp.Dispose();
        }
Ejemplo n.º 2
0
 public FontSetEngine(GLFontEngine fengine)
 {
     GLFonts = fengine;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Called when the window is loading, only to be used by the startup process.
 /// </summary>
 void Window_Load(object sender, EventArgs e)
 {
     SysConsole.Output(OutputType.INIT, "Window generated!");
     DPIScale = Window.Width / CVars.r_width.ValueF;
     SysConsole.Output(OutputType.INIT, "DPIScale is " + DPIScale + "!");
     SysConsole.Output(OutputType.INIT, "Loading base textures...");
     PreInitRendering();
     Textures = new TextureEngine();
     Textures.InitTextureSystem(this);
     ItemFrame = Textures.GetTexture("ui/hud/item_frame");
     SysConsole.Output(OutputType.INIT, "Loading shaders...");
     Shaders = new ShaderEngine();
     GLVendor = GL.GetString(StringName.Vendor);
     CVars.s_glvendor.Value = GLVendor;
     GLVersion = GL.GetString(StringName.Version);
     CVars.s_glversion.Value = GLVersion;
     GLRenderer = GL.GetString(StringName.Renderer);
     CVars.s_glrenderer.Value = GLRenderer;
     SysConsole.Output(OutputType.INIT, "Vendor: " + GLVendor + ", GLVersion: " + GLVersion + ", Renderer: " + GLRenderer);
     if (GLVendor.ToLowerFast().Contains("intel"))
     {
         SysConsole.Output(OutputType.INIT, "Disabling good graphics (Appears to be Intel: '" + GLVendor + "')");
         Shaders.MCM_GOOD_GRAPHICS = false;
     }
     Shaders.InitShaderSystem(this);
     View3D.CheckError("Load - Shaders");
     SysConsole.Output(OutputType.INIT, "Loading rendering helper...");
     Rendering = new Renderer(Textures, Shaders);
     Rendering.Init();
     SysConsole.Output(OutputType.INIT, "Preparing load screen...");
     Texture load_screen = Textures.GetTexture("ui/menus/loadscreen");
     load_screen.Bind();
     Shaders.ColorMultShader.Bind();
     Establish2D();
     Rendering.RenderRectangle(0, 0, Window.Width, Window.Height);
     Window.SwapBuffers();
     SysConsole.Output(OutputType.INIT, "Loading block textures...");
     TBlock = new TextureBlock();
     TBlock.Generate(this, CVars, Textures);
     View3D.CheckError("Load - Textures");
     SysConsole.Output(OutputType.INIT, "Loading fonts...");
     Fonts = new GLFontEngine(Shaders);
     Fonts.Init(this);
     FontSets = new FontSetEngine(Fonts);
     FontSets.Init(this);
     View3D.CheckError("Load - Fonts");
     SysConsole.Output(OutputType.INIT, "Loading animation engine...");
     Animations = new AnimationEngine();
     SysConsole.Output(OutputType.INIT, "Loading model engine...");
     Models = new ModelEngine();
     Models.Init(Animations, this);
     SysConsole.Output(OutputType.INIT, "Loading general graphics settings...");
     CVars.r_vsync.OnChanged += onVsyncChanged;
     onVsyncChanged(CVars.r_vsync, null);
     CVars.r_cloudshadows.OnChanged += onCloudShadowChanged;
     View3D.CheckError("Load - General Graphics");
     SysConsole.Output(OutputType.INIT, "Loading UI engine...");
     UIConsole.InitConsole(); // TODO: make this non-static
     InitChatSystem();
     View3D.CheckError("Load - UI");
     SysConsole.Output(OutputType.INIT, "Preparing rendering engine...");
     InitRendering();
     View3D.CheckError("Load - Rendering");
     SysConsole.Output(OutputType.INIT, "Loading particle effect engine...");
     Particles = new ParticleHelper(this) { Engine = new ParticleEngine(this) };
     SysConsole.Output(OutputType.INIT, "Preparing mouse, keyboard, and gamepad handlers...");
     KeyHandler.Init();
     GamePadHandler.Init();
     View3D.CheckError("Load - Keyboard/mouse");
     SysConsole.Output(OutputType.INIT, "Building the sound system...");
     Sounds = new SoundEngine();
     Sounds.Init(this, CVars);
     View3D.CheckError("Load - Sound");
     SysConsole.Output(OutputType.INIT, "Building game world...");
     BuildWorld();
     View3D.CheckError("Load - World");
     SysConsole.Output(OutputType.INIT, "Preparing networking...");
     Network = new NetworkBase(this);
     RegisterDefaultEntityTypes();
     View3D.CheckError("Load - Net");
     SysConsole.Output(OutputType.INIT, "Playing background music...");
     BackgroundMusic();
     CVars.a_musicvolume.OnChanged += onMusicVolumeChanged;
     CVars.a_musicpitch.OnChanged += onMusicPitchChanged;
     CVars.a_music.OnChanged += onMusicChanged;
     CVars.a_echovolume.OnChanged += OnEchoVolumeChanged;
     OnEchoVolumeChanged(null, null);
     SysConsole.Output(OutputType.INIT, "Setting up screens...");
     TheMainMenuScreen = new MainMenuScreen(this);
     TheGameScreen = new GameScreen(this);
     TheSingleplayerMenuScreen = new SingleplayerMenuScreen(this);
     SysConsole.Output(OutputType.INIT, "Preparing inventory...");
     InitInventory();
     SysConsole.Output(OutputType.INIT, "Showing main menu...");
     ShowMainMenu();
     SysConsole.Output(OutputType.INIT, "Trying to grab RawGamePad...");
     try
     {
         RawGamePad = new XInput();
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.INIT, "Failed to grab RawGamePad: " + ex.Message);
     }
     View3D.CheckError("Load - Final");
     SysConsole.Output(OutputType.INIT, "Ready and looping!");
 }
Ejemplo n.º 4
0
 public TextVBO(GLFontEngine fengine)
 {
     Engine = fengine;
 }
Ejemplo n.º 5
0
 public TextVBO(GLFontEngine fengine)
 {
     Engine = fengine;
 }
Ejemplo n.º 6
0
 public GLFont(Font font, GLFontEngine eng)
 {
     Engine = eng;
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     Engine.Shaders.ColorMultShader.Bind();
     Name = font.Name;
     Size = (int)(font.Size * eng.TheClient.DPIScale);
     Bold = font.Bold;
     Italic = font.Italic;
     Height = font.Height;
     CharacterLocations = new List<RectangleF>();
     StringFormat sf = new StringFormat(StringFormat.GenericTypographic);
     sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap;
     Internal_Font = font;
     Bitmap bmp = new Bitmap(Engine.bwidth, Engine.bheight);
     GL.BindTexture(TextureTarget.Texture2DArray, Engine.Texture3D);
     Characters = Engine.textfile;
     using (Graphics gfx = Graphics.FromImage(bmp))
     {
         gfx.Clear(Color.Transparent);
         gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
         float X = 6;
         float Y = 0;
         gfx.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, 5, (int)Height));
         Brush brush = new SolidBrush(Color.White);
         for (int i = 0; i < Engine.textfile.Length; i++)
         {
             string chr = Engine.textfile[i] == '\t' ? "    " : Engine.textfile[i].ToString();
             float nwidth = (float)Math.Ceiling(gfx.MeasureString(chr, font, new PointF(0, 0), sf).Width);
             if (font.Italic)
             {
                 nwidth += 2;
             }
             if (X + nwidth >= Engine.bwidth)
             {
                 Y += Height + 8;
                 X = 6;
             }
             gfx.DrawString(chr, font, brush, new PointF(X, Y), sf);
             CharacterLocations.Add(new RectangleF(X, Y, nwidth, Height));
             X += nwidth + 8f;
         }
     }
     BitmapData data = bmp.LockBits(new Rectangle(0, 0, Engine.bwidth, Engine.bheight), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     GL.TexSubImage3D(TextureTarget.Texture2DArray, 0, 0, 0, cZ, Engine.bwidth, Engine.bheight, 1, OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
     TexZ = cZ;
     cZ++;
     cZ = cZ % 48;
     // TODO: Handle > 24 fonts more cleanly
     bmp.UnlockBits(data);
     bmp.Dispose();
 }
Ejemplo n.º 7
0
 public FontSetEngine(GLFontEngine fengine)
 {
     GLFonts = fengine;
 }