Beispiel #1
0
        public static unsafe Texture LoadBitmap(BitmapLoadData loadData)
        {
            IBitmapImage bitmap = loadData.Bitmap;
            bool isTransparent = loadData.IsTransparent;

            Size size;
            bitmap.GetSize(out size);
            RECT rect = new RECT(0, 0, size.Width, size.Height);

            uint glFormat = gl.GL_RGB;
            uint glType = gl.GL_UNSIGNED_SHORT_5_6_5;
            if (isTransparent)
            {
                glFormat = gl.GL_RGBA;
                glType = gl.GL_UNSIGNED_BYTE;
            }

            Texture ret = new Texture();

            uint tex;
            gl.GenTextures(1, &tex);
            ret.myName = tex;

            gl.BindTexture(gl.GL_TEXTURE_2D, ret.myName);

            gl.TexImage2D(gl.GL_TEXTURE_2D, 0, glFormat, size.Width, size.Height, 0, glFormat, glType, loadData.Data.Scan0);

            gl.TexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR);
            gl.TexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR);
            gl.TexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE);
            gl.TexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE);

            ret.myWidth = loadData.Width;
            ret.myHeight = size.Height;
            ret.myIsTransparent = isTransparent;

            return ret;
        }