Ejemplo n.º 1
0
        protected unsafe void setupVideoGraphicsObject()
        {
            this.mCubeTexture = TextureManager.Singleton.CreateManual(
                "MyCubeTexture",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                TextureType.TEX_TYPE_2D,
                (uint)this.TexWidth,
                (uint)this.TexHeight,
                0,
                Mogre.PixelFormat.PF_A8R8G8B8);

            MaterialPtr inMat = MaterialManager.Singleton.Create("MyCubeMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

            inMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("MyCubeTexture");
            mCubeEntity.SetMaterialName("MyCubeMat");

            // draw bitmap to texture
            HardwarePixelBufferSharedPtr texBuffer = this.mCubeTexture.GetBuffer();

            texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
            PixelBox pb = texBuffer.CurrentLock;

            using (Bitmap bm = new Bitmap(
                       (int)this.mCubeTexture.Width,
                       (int)this.mCubeTexture.Height,
                       (int)((this.mCubeTexture.Width * 4) + (pb.RowSkip * 4)),
                       System.Drawing.Imaging.PixelFormat.Format32bppArgb,
                       pb.data))
            {
                mVideoGraphics = Graphics.FromImage(bm);
            }

            texBuffer.Unlock();
            texBuffer.Dispose();
        }
Ejemplo n.º 2
0
        private unsafe void ConvertBitmap(Bitmap pTextureBitmap)
        {
            if (this.mCubeTexture == null)
            {
                this.mCubeTexture = TextureManager.Singleton.CreateManual(
                    "MyCubeTexture",
                    ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                    TextureType.TEX_TYPE_2D,
                    (uint)this.TexWidth,
                    (uint)this.TexHeight,
                    0,
                    Mogre.PixelFormat.PF_A8R8G8B8);

                MaterialPtr inMat = MaterialManager.Singleton.Create("MyCubeMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                inMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("MyCubeTexture");
                mCubeEntity.SetMaterialName("MyCubeMat");
            }

            if (pTextureBitmap != null)
            {
                // draw bitmap to texture
                HardwarePixelBufferSharedPtr texBuffer = this.mCubeTexture.GetBuffer();

                texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
                PixelBox pb = texBuffer.CurrentLock;

                using (Bitmap bm = new Bitmap(
                           (int)this.mCubeTexture.Width,
                           (int)this.mCubeTexture.Height,
                           (int)((this.mCubeTexture.Width * 4) + (pb.RowSkip * 4)),
                           System.Drawing.Imaging.PixelFormat.Format32bppArgb,
                           pb.data))
                {
                    using (Graphics g = Graphics.FromImage(bm))
                    {
                        //g.DrawImage(this.mTextureBitmap, 0, 0);
                        g.DrawImage(pTextureBitmap, new System.Drawing.Rectangle(0, 0, (int)this.mCubeTexture.Width, (int)this.mCubeTexture.Height));
                    }
                }

                texBuffer.Unlock();
                texBuffer.Dispose();
            }


            /*
             * // draw bitmap to texture
             * HardwarePixelBufferSharedPtr texBuffer = this.mCubeTexture.GetBuffer();
             * texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
             * mVideoGraphics.DrawImage(this.mTextureBitmap, new System.Drawing.Rectangle(0, 0, (int)this.mCubeTexture.Width, (int)this.mCubeTexture.Height));
             * texBuffer.Unlock();
             */
        }
Ejemplo n.º 3
0
        public override unsafe void WriteToTexture(byte[] bytes, object textureHandle)
        {
            // draw bitmap to texture
            Texture texture = SafeResolveTexture(textureHandle);

            using (HardwarePixelBufferSharedPtr texBuffer = texture.GetBuffer())
            {
                texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
                PixelBox pb = texBuffer.CurrentLock;

                Debug.Assert(texture.Width == texture.SrcWidth && texture.Height == texture.SrcHeight, "Texture dimensions altered by render system.");
                Marshal.Copy(bytes, 0, pb.data, bytes.Length);

                texBuffer.Unlock();
            }
        }
Ejemplo n.º 4
0
        public unsafe void Replace2(byte[] bytes, string textureName)
        {
            if (this.IndexOf(textureName) < 0)
            {
                throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist");
            }
            TexturePtr pTexture = this[textureName];
            HardwarePixelBufferSharedPtr texBuffer = pTexture.GetBuffer();

            texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
            PixelBox pb = texBuffer.CurrentLock;

            Marshal.Copy(bytes, 0, pb.data, bytes.Length);
            texBuffer.Unlock();
            texBuffer.Dispose();
        }
Ejemplo n.º 5
0
        public unsafe void Replace3(byte[] bytes, string textureName)
        {
            using (ResourcePtr rpt = TextureManager.Singleton.GetByName(textureName))
            {
                using (TexturePtr texture = rpt)
                {
                    HardwarePixelBufferSharedPtr texBuffer = texture.GetBuffer();
                    texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
                    PixelBox pb = texBuffer.CurrentLock;

                    Marshal.Copy(bytes, 0, pb.data, bytes.Length);

                    texBuffer.Unlock();
                    texBuffer.Dispose();
                }
            }
        }
Ejemplo n.º 6
0
        private static unsafe void ConvertImageToTexture(Bitmap image, string textureName, Size size)
        {
            int width  = size.Width;
            int height = size.Height;

            using (ResourcePtr rpt = TextureManager.Singleton.GetByName(textureName))
            {
                using (TexturePtr texture = rpt)
                {
                    HardwarePixelBufferSharedPtr texBuffer = texture.GetBuffer();
                    texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
                    PixelBox pb = texBuffer.CurrentLock;

                    System.Drawing.Imaging.BitmapData data = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    CopyMemory(pb.data, data.Scan0, (uint)(width * height * 4));
                    image.UnlockBits(data);

                    texBuffer.Unlock();
                    texBuffer.Dispose();
                }
            }
        }
Ejemplo n.º 7
0
        internal static unsafe void ClearTexture(Texture texture, Colour colour)
        {
            using (HardwarePixelBufferSharedPtr hbuf = texture.GetBuffer())
            {
                hbuf.Lock(HardwareBuffer.LockOptions.HBL_NORMAL);
                PixelBox pb = hbuf.CurrentLock;

                byte *destData          = (byte *)pb.data;
                uint  destPixelSize     = PixelUtil.GetNumElemBytes(pb.format);
                uint  destRowPitchBytes = pb.rowPitch * destPixelSize;

                ColourValue cv = new ColourValue(colour.Red / 255f, colour.Green / 255f, colour.Blue / 255f, colour.Alpha / 255f);
                for (uint i = 0; i < texture.Height; i++)
                {
                    for (uint j = 0; j < texture.Width; j++)
                    {
                        uint offset = (i * destRowPitchBytes) + (j * destPixelSize);
                        PixelUtil.PackColour(cv, pb.format, &destData[offset]);
                    }
                }

                hbuf.Unlock();
            }
        }