예제 #1
0
        private void DrawText(float x, float y, float maxX, float size, FontInfo font, string text)
        {
            // text = text.RemoveDiacritics();
             float height = size * font.HeightRatio;

             Gl.glBegin(Gl.GL_QUADS);
             TextureManager.Instance.ChangeTextureForQuads(font.TextureName);

             float currentX = x;
             float currentY = y;

             for (int i = 0; i < text.Length; i++)
             {
            char c = text[i];
            if (c < 32 || c > 127)
            {
               c = ' ';
            }
            float[] texCoords = font.GetTexCoords(c);

            Gl.glTexCoord2f(texCoords[0], texCoords[3]);
            Gl.glVertex3f(currentX, currentY, 0.0f);
            Gl.glTexCoord2f(texCoords[2], texCoords[3]);
            Gl.glVertex3f(currentX + size, currentY, 0.0f);
            Gl.glTexCoord2f(texCoords[2], texCoords[1]);
            Gl.glVertex3f(currentX + size, currentY + height, 0.0f);
            Gl.glTexCoord2f(texCoords[0], texCoords[1]);
            Gl.glVertex3f(currentX, currentY + height, 0.0f);

            currentX += size;
            if (currentX >= maxX)
            {
               currentY -= height;
               currentX = x;
            }
             }

             Gl.glEnd();
        }
예제 #2
0
        internal void LoadFonts()
        {
            DirectoryInfo fontsDir = new DirectoryInfo(_FontsPath);
             FileInfo[] fonts = fontsDir.GetFiles("*.jpg");
             int[] fontTextureNames = new int[fonts.Length];

             lock (_LoadLock)
             {
            Gl.glGenTextures(fontTextureNames.Length, fontTextureNames);

            for (int i = 0; i < fontTextureNames.Length; i++)
            {
               string path = fonts[i].FullName;
               string name = fonts[i].Name;

               // load texture into opengl
               BindTexture(fontTextureNames[i], path, 256, 256);
               float heightRatio = 0.0f;
               float rowSize = 0.0f;
               int[] paddings = new int[4];

               foreach (string fontInfoData in File.ReadAllLines(path + ".info"))
               {
                  string[] frags = fontInfoData.Split('=');
                  switch (frags[0])
                  {
                     case "heightRatio":
                        heightRatio = float.Parse(frags[1], CultureInfo.InvariantCulture);
                        break;
                     case "padding":
                        string[] paddingData = frags[1].Split(';');
                        for (int p = 0; p < 4; p++)
                        {
                           paddings[p] = Convert.ToInt32(paddingData[p]);
                        }
                        break;
                     case "rowSize":
                        rowSize = float.Parse(frags[1], CultureInfo.InvariantCulture);
                        break;
                  }
               }

               // store texture by name
               FontInfo fontInfo = new FontInfo(name, heightRatio, rowSize, paddings, fontTextureNames[i]);
               _FontTextureMap.Add(name.Substring(0, name.IndexOf(".jpg")), fontInfo);
            }

            _Textures.AddRange(fontTextureNames);
             }
        }
예제 #3
0
        private void DrawHud()
        {
            Gl.glLoadIdentity();
            Gl.glOrtho(-100, 100, -100, 100, 0, 5);

            Gl.glDisable(Gl.GL_TEXTURE_2D);

            Gl.glColor3fv(Configuration.Customization.HudColor.ToArray());
            Gl.glLineWidth(2.0f);

            // draw crosshair
            Gl.glBegin(Gl.GL_LINES);

            Gl.glVertex3f(5.0f, 0.0f, 0.0f);
            Gl.glVertex3f(3.0f, 0.0f, 0.0f);
            Gl.glVertex3f(-5.0f, 0.0f, 0.0f);
            Gl.glVertex3f(-3.0f, 0.0f, 0.0f);
            Gl.glVertex3f(0.0f, 5.0f, 0.0f);
            Gl.glVertex3f(0.0f, 3.0f, 0.0f);
            Gl.glVertex3f(0.0f, -5.0f, 0.0f);
            Gl.glVertex3f(0.0f, -3.0f, 0.0f);

            Gl.glEnd();

            // draw selected material frame
            Gl.glBegin(Gl.GL_QUADS);

            Gl.glVertex3f(95.25f, -44.75f, 0.0f);
            Gl.glVertex3f(84.75f, -44.75f, 0.0f);
            Gl.glVertex3f(84.75f, -55.25f, 0.0f);
            Gl.glVertex3f(95.25f, -55.25f, 0.0f);

            Gl.glEnd();

            // draw selected material top face
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glColor3f(1.0f, 1.0f, 1.0f);

            Gl.glBegin(Gl.GL_QUADS);

            TextureManager.Instance.ChangeTextureForQuads(Material.GetMaterial(Player.SelectedMaterial)[Sides.BackY]);
            Gl.glTexCoord2f(1.0f, 0.0f);
            Gl.glVertex3f(95.0f, -45.0f, 0.0f);
            Gl.glTexCoord2f(0.0f, 0.0f);
            Gl.glVertex3f(85.0f, -45.0f, 0.0f);
            Gl.glTexCoord2f(0.0f, 1.0f);
            Gl.glVertex3f(85.0f, -55.0f, 0.0f);
            Gl.glTexCoord2f(1.0f, 1.0f);
            Gl.glVertex3f(95.0f, -55.0f, 0.0f);

            Gl.glEnd();

            // draw chat
            FontInfo font        = TextureManager.Instance.GetFont("consolas");
            float    x           = -95.0f;
            float    y           = -55.0f;
            float    maxXchat    = -10.0f;
            float    maxXtextBox = 80.0f;
            float    size        = 1.5f;

            // draw player's chat message editor line
            Gl.glColor3fv(Configuration.Customization.HudColor.ToArray());

            if (_ChatBoxActive)
            {
                DrawText(x - 3.0f, y, maxXtextBox, size, font, "> ");
            }
            DrawText(x, y, maxXtextBox, size, font, _CurrentChatMessage);

            // draw last 10 messages
            Gl.glColor3f(1.0f, 1.0f, 1.0f);
            for (int i = _ChatHistory.Count - 1; i >= 0 && i >= _ChatHistory.Count - 6; i--)
            {
                y += MeasureTextLines(x, maxXchat, size, _ChatHistory[i].Length) * size * font.HeightRatio;
                DrawText(x, y, maxXchat, size, font, _ChatHistory[i]);
            }

            Gl.glDisable(Gl.GL_TEXTURE_2D);
        }