private bool loadCubeMapSide(int texture, TextureTarget side_target, string url)
        {
            GL.BindTexture(TextureTarget.TextureCubeMap, texture);

            int width, height;

            win.Bitmap             image;
            win.Imaging.BitmapData pixelData;
            win.Rectangle          imgRect;
            IntPtr pTexImage;

            if (ImageTexture.GetTextureImageFromMFString(url, out image, out width, out height, flipX: true))
            {
                imgRect   = new win.Rectangle(0, 0, width, height);
                pixelData = image.LockBits(imgRect, win.Imaging.ImageLockMode.ReadOnly,
                                           System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                pTexImage = pixelData.Scan0;

                // copy image data into 'target' side of cube map
                GL.TexImage2D(side_target, 0, PixelInternalFormat.Rgba, width, height, 0,
                              PixelFormat.Bgra, PixelType.UnsignedByte, pTexImage);

                return(true);
            }

            return(false);
        }
示例#2
0
        private bool loadCubeMapSide(int texture, TextureTarget side_target, win.Bitmap image)
        {
            if (image == null)
            {
                image = Properties.Resources.ErrorTexture;

                ImageTexture.Rescale(ref image);
            }

            GL.BindTexture(TextureTarget.TextureCubeMap, texture);

            win.Imaging.BitmapData pixelData;
            win.Rectangle          imgRect;
            IntPtr pTexImage;

            bool?rotCW = null;

            if (side_target == TextureTarget.TextureCubeMapPositiveY)      // Top
            {
                rotCW = false;                                             // CCW
            }
            else if (side_target == TextureTarget.TextureCubeMapNegativeY) // Bottom
            {
                rotCW = true;                                              // CW
            }

            if (rotCW.HasValue)
            {
                if (rotCW.Value)
                {
                    // Clockwise by 90 degrees
                    image.RotateFlip(win.RotateFlipType.Rotate90FlipNone);
                }
                else
                {
                    // Counterclockwise by -90 degrees
                    image.RotateFlip(win.RotateFlipType.Rotate270FlipNone);
                }
            }

            imgRect   = new win.Rectangle(0, 0, image.Width, image.Height);
            pixelData = image.LockBits(imgRect, win.Imaging.ImageLockMode.ReadOnly,
                                       System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            pTexImage = pixelData.Scan0;

            // copy image data into 'target' side of cube map
            GL.TexImage2D(side_target, 0, PixelInternalFormat.Rgba, image.Width, image.Height, 0,
                          PixelFormat.Bgra, PixelType.UnsignedByte, pTexImage);

            image.UnlockBits(pixelData);

            return(true);
        }
        private void UpdateString(String text, out BoundingBox bbox)
        {
            Brush  b;
            PointF p;
            Bitmap bmp;

            bbox = BoundingBox.CalculateBoundingBox(text, Font);

            bmp = new Bitmap((int)bbox.Width, (int)bbox.Height);

            bmp.MakeTransparent(BackColor);

            //if(FontStyle.Justify.FirstOrDefault() == "MIDDLE")
            //{
            //p = new PointF((float)Offset.X + (boundingbox.Width / 8.0f), (float)Offset.Y);
            //}
            //else
            //{
            p = new PointF((float)Offset.X, (float)Offset.Y);
            //}



            b = new SolidBrush(ForeColor);

            using (Graphics g2D = Graphics.FromImage(bmp))
            {
                //g2D.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                g2D.Clear(BackColor);
                g2D.DrawString(text, Font, b, p, StringFormat.GenericDefault);
            }

            bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);

            ImageTexture texture = ImageTexture.CreateTextureFromImage(bmp, new Rectangle(0, 0, (int)bbox.Width, (int)bbox.Height));

            if (stringTextures.ContainsKey(text))
            {
                stringTextures[text].FreeTexture();
                stringTextures[text].Dispose();

                stringTextures[text] = texture;
            }
            else
            {
                stringTextures.Add(text, texture);
            }
        }
示例#4
0
        public static ImageTexture CreateTextureFromImage(Bitmap image, Rectangle boundingbox, bool adjustSize = false)
        {
            ImageTexture texture = new ImageTexture();

            texture._type  = InternalImageType.Bitmap;
            texture.Width  = boundingbox.Width;
            texture.Height = boundingbox.Height;


            if (adjustSize)
            {
                /*	Get the maximum texture size supported by OpenGL: */
                int[] textureMaxSize = new int[] { 0 };
                GL.GetInteger(GetPName.MaxTextureSize, textureMaxSize);
                //gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE,textureMaxSize);

                /*	Find the target width and height sizes, which is just the highest
                 *	posible power of two that'll fit into the image. */
                int glTexWidth  = textureMaxSize[0];
                int glTexHeight = textureMaxSize[0];
                for (int size = 1; size <= textureMaxSize[0]; size *= 2)
                {
                    if (image.Width < size)
                    {
                        glTexWidth = size / 2;
                        break;
                    }
                    if (image.Width == size)
                    {
                        glTexWidth = size;
                    }
                }

                for (int size = 1; size <= textureMaxSize[0]; size *= 2)
                {
                    if (image.Height < size)
                    {
                        glTexHeight = size / 2;
                        break;
                    }
                    if (image.Height == size)
                    {
                        glTexHeight = size;
                    }
                }

                if (image.Width != glTexWidth || image.Height != glTexHeight)
                {
                    /* Scale the image according to OpenGL requirements */
                    Image newImage = image.GetThumbnailImage(glTexWidth, glTexHeight, null, IntPtr.Zero);

                    image.Dispose();
                    image = (Bitmap)newImage;

                    boundingbox.Width  = glTexWidth;
                    boundingbox.Height = glTexHeight;
                }
            }


            texture.Index = GL.GenTexture();
            //GL.BindTexture(TextureTarget.Texture2D, texture.Index);
            //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
            //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
            //GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, boundingbox.Width, boundingbox.Height, 0,
            //    OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);

            texture.pixelData = image.LockBits(boundingbox,
                                               System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                               System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            texture.image = image;

            // Upload done later by system automatically
            texture.LoadTexture();

            // Append to system texture assets
            //texture._textureID = SceneManager.CreateTexture(texture);

            return(texture);
        }