public ImageAtlasPage(String textureName, String groupName, int width, int height)
 {
     rootNode         = new ImagePackTreeNode(new Size(width, height));
     texture          = TextureManager.getInstance().createManual(textureName, groupName, TextureType.TEX_TYPE_2D, (uint)width, (uint)height, 1, 0, OgrePlugin.PixelFormat.PF_A8R8G8B8, TextureUsage.TU_STATIC_WRITE_ONLY, null, false, 0);
     bufferPtr        = texture.Value.getBuffer();
     this.TextureName = textureName;
     this.GroupName   = groupName;
 }
Beispiel #2
0
        public ImagePackTreeNode insert(String imageID, FreeImageBitmap img)
        {
            //If not a leaf and both children are full
            if (!IsLeaf)
            {
                ImagePackTreeNode newNode = children[0].insert(imageID, img);
                if (newNode != null)
                {
                    return(newNode);
                }

                return(children[1].insert(imageID, img));
            }
            else
            {
                //If there is already an image, return
                if (this.imageID != null)
                {
                    return(null);
                }

                Rectangle imageRect = new Rectangle(rc.Left, rc.Top, img.Width, img.Height);

                //If the area is too small return
                if (rc.Width < imageRect.Width || rc.Height < imageRect.Height)
                {
                    return(null);
                }

                //If were just right accept
                if (rc.Width == imageRect.Width && rc.Height == imageRect.Height)
                {
                    this.imageID = imageID;
                    return(this);
                }

                //Otherwise gotta split this node and create some kids
                this.children[0] = new ImagePackTreeNode();
                this.children[1] = new ImagePackTreeNode();

                int dw = rc.Width - imageRect.Width;
                int dh = rc.Height - imageRect.Height;

                if (dw > dh)
                {
                    children[0].rc = new Rectangle(rc.Left, rc.Top, imageRect.Width, rc.Height);
                    children[1].rc = new Rectangle(rc.Left + imageRect.Width, rc.Top, rc.Width - imageRect.Width, rc.Height);
                }
                else
                {
                    children[0].rc = new Rectangle(rc.Left, rc.Top, rc.Width, imageRect.Height);
                    children[1].rc = new Rectangle(rc.Left, rc.Top + imageRect.Height, rc.Width, rc.Height - imageRect.Height);
                }

                return(children[0].insert(imageID, img));
            }
        }
        /// <summary>
        /// Add an image to this page, will return true if the image was sucessfully added to the page.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="image"></param>
        /// <returns></returns>
        internal unsafe bool addImage(String name, FreeImageBitmap image)
        {
            ImagePackTreeNode node = rootNode.insert(name, image);

            if (node != null)
            {
                using (PixelBox pixelBox = new PixelBox(0, 0, image.Width, image.Height, OgreDrawingUtility.getOgreFormat(image.PixelFormat), image.GetScanlinePointer(0).ToPointer()))
                {
                    Rectangle locationRect = node.LocationRect;
                    bufferPtr.Value.blitFromMemory(pixelBox, new IntRect(locationRect.Left, locationRect.Top, locationRect.Right, locationRect.Bottom));
                    imageInfo.Add(name, node);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }