예제 #1
0
        /// <summary>
        /// Create a font from a font bitmap and font metrics data.
        /// </summary>
        /// <param name="file">File that contains font data.</param>
        /// <param name="metrics">File that contains metrics data.</param>
        public Font(File_System.File file, File_System.File metrics)
        {
            texture = new Image(file, 32, 32, 0, 0, 0);

            FallenGE.Utility.Buffer buffer = new FallenGE.Utility.Buffer(512);
            FallenGE.File_System.FileManager.Read(metrics, buffer, 1, 512);

            width = new int[512];
            for (int i = 0; i < 512; i += 2)
            {
                width[i / 2] = (int)Marshal.ReadByte(buffer.Data, i);
            }

            height = 32;
        }
예제 #2
0
        /// <summary>
        /// Create a new image.
        /// </summary>
        /// <param name="file">The file that contains image data.</param>
        /// <param name="redMask">The red value of the color to be masked.</param>
        /// <param name="greenMask">The green value of the color to be masked.</param>
        /// <param name="blueMask">The blue value of the color to be masked.</param>
        public Image(File file, int redMask, int greenMask, int blueMask)
        {
            Il.ilGenImages(1, out ilName);

            Il.ilBindImage(ilName);

            FallenGE.Utility.Buffer buffer = new FallenGE.Utility.Buffer();

            uint size = Convert.ToUInt32(FallenGE.File_System.FileManager.FileSize(file));

            FallenGE.File_System.FileManager.Read(file, buffer, size, 1);

            Il.ilLoadL(Il.IL_TYPE_UNKNOWN, buffer.Data, Convert.ToInt32(size));

            Il.ilConvertImage(Il.IL_RGBA, Il.IL_UNSIGNED_BYTE);

            int[] textures = new int[1];
            Gl.glGenTextures(1, textures);
            glName = textures[0];

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, glName);

            width  = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
            height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);

            frameWidth  = width;
            frameHeight = height;

            textureWidth  = Math.Global.NextPow2(width);
            textureHeight = Math.Global.NextPow2(height);

            widthRatio  = (float)width / textureWidth;
            heightRatio = (float)height / textureHeight;

            int xFrames, yFrames;

            xFrames    = width / frameWidth;
            yFrames    = height / frameHeight;
            frameCount = xFrames * yFrames;

            if (textureWidth != width || textureHeight != height)
            {
                imageData = Marshal.AllocHGlobal(textureWidth * textureHeight * 4);
                Il.ilCopyPixels(0, 0, 0, textureWidth, textureHeight, 1, Il.IL_RGBA, Il.IL_UNSIGNED_BYTE, imageData);
            }
            else
            {
                imageData = Il.ilGetData();
            }

            tmpData = new byte[textureWidth * textureHeight * 4];
            Marshal.Copy(imageData, tmpData, 0, tmpData.Length);
            for (int i = 0; i < tmpData.Length; i += 4)
            {
                if (tmpData[i + 0] == redMask && tmpData[i + 1] == greenMask && tmpData[i + 2] == blueMask)
                {
                    tmpData[i + 3] = 0;
                }
            }
            Marshal.Copy(tmpData, 0, imageData, tmpData.Length);

            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
            Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Il.ilGetInteger(Il.IL_IMAGE_BPP), textureWidth, textureHeight, 0, Il.ilGetInteger(Il.IL_IMAGE_FORMAT), Gl.GL_UNSIGNED_BYTE, imageData);

            string ext = file.Path.Substring(file.Path.Length - 3, 3);

            /*if (ext == "bmp")
             * {
             *  Gl.glMatrixMode(Gl.GL_TEXTURE);
             *  Gl.glTranslatef(0.5f, 0.5f, 0.0f);
             *  Gl.glScalef(-1.0f, 1.0f, 1.0f);
             *  Gl.glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
             *  Gl.glTranslatef(-0.5f, -0.5f, 0.0f);
             *  Gl.glMatrixMode(Gl.GL_MODELVIEW);
             * }*/

            Il.ilDeleteImages(1, ref ilName);

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, -1);

            buffer.Destroy();
        }