コード例 #1
0
        private TextureCoordinates GetTextureCoords(RectangleF srcRect)
        {
            TextureCoordinates coords = new TextureCoordinates(
                (srcRect.Left) / (float)mTextureSize.Width,
                (srcRect.Top) / (float)mTextureSize.Height,
                (srcRect.Right) / (float)mTextureSize.Width,
                (srcRect.Bottom) / (float)mTextureSize.Height);

            return(coords);
        }
コード例 #2
0
        public override void SetSourceSurface(SurfaceImpl surf, Rectangle srcRect)
        {
            ReleaseTextureRef();
            AddTextureRef((surf as GL_Surface).mTextureID);

            mTextureSize = (surf as GL_Surface).mTextureSize;
            mSourceRect  = srcRect;

            mTexCoord = GetTextureCoords(mSourceRect);
        }
コード例 #3
0
        private GL_Surface(int textureID, Rectangle sourceRect, Size textureSize)
        {
            mDisplay = Display.Impl as GL_Display;
            mState   = mDisplay.State;

            AddTextureRef(textureID);

            mSourceRect  = sourceRect;
            mTextureSize = textureSize;

            mTexCoord = GetTextureCoords(mSourceRect);
        }
コード例 #4
0
        private void BufferQuad(float destX, float destY, float rotationCenterX, float rotationCenterY,
                                float displayWidth, float displayHeight, TextureCoordinates texCoord, Gradient color)
        {
            // order is
            //  1 -- 2
            //  |    |
            //  4 -- 3
            PointF[] pt = cachePt;

            SetPoints(pt, destX, destY,
                      rotationCenterX, rotationCenterY, displayWidth, displayHeight);

            //RectangleF destRect = new RectangleF(new PointF(-rotationCenterX, -rotationCenterY),
            //                     new SizeF(displayWidth, displayHeight));


            mState.DrawBuffer.AddQuad(mTextureID, color, texCoord, pt);
        }
コード例 #5
0
        public void AddQuad(int textureID, Color color, TextureCoordinates texCoord, RectangleF destRect)
        {
            PointF[] pt = cachePts;

            pt[0].X = destRect.Left;
            pt[0].Y = destRect.Top;

            pt[1].X = destRect.Right;
            pt[1].Y = destRect.Top;

            pt[2].X = destRect.Right;
            pt[2].Y = destRect.Bottom;

            pt[3].X = destRect.Left;
            pt[3].Y = destRect.Bottom;

            AddQuad(textureID, color, texCoord, pt);
        }
コード例 #6
0
        public override void Draw(RectangleF srcRect, RectangleF destRect)
        {
            srcRect.X += mSourceRect.X;
            srcRect.Y += mSourceRect.Y;

            TextureCoordinates texcoords = GetTextureCoords(srcRect);
            RectangleF         dest      = new RectangleF(destRect.X, destRect.Y, destRect.Width, destRect.Height);

            mState.DrawBuffer.SetInterpolationMode(InterpolationHint);

            if (TesselateFactor == 1)
            {
                mState.DrawBuffer.AddQuad(mTextureID, Color, texcoords, dest);
            }
            else
            {
                float texWidth  = texcoords.Right - texcoords.Left;
                float texHeight = texcoords.Bottom - texcoords.Top;

                for (int j = 0; j < TesselateFactor; j++)
                {
                    RectangleF         subRect = dest;
                    TextureCoordinates coords  = texcoords;

                    subRect.Y      = dest.Top + j * dest.Height / (float)TesselateFactor;
                    subRect.Height = dest.Height / (float)TesselateFactor;

                    coords.Top    = texcoords.Top + texHeight * j / TesselateFactor;
                    coords.Bottom = coords.Top + texHeight / TesselateFactor;

                    for (int i = 0; i < TesselateFactor; i++)
                    {
                        subRect.X     = dest.Left + i * dest.Width / (float)TesselateFactor;
                        subRect.Width = dest.Width / (float)TesselateFactor;

                        coords.Left  = texcoords.Left + texWidth * i / TesselateFactor;
                        coords.Right = coords.Left + texWidth / TesselateFactor;

                        mState.DrawBuffer.AddQuad(mTextureID, Color, coords, subRect);
                    }
                }
            }
        }
コード例 #7
0
        private void LoadFromBitmap(Drawing.Bitmap sourceImage)
        {
            mSourceRect.Size = Interop.Convert(sourceImage.Size);

            Size newSize = GetOGLSize(sourceImage);

            // create a new bitmap of the size OpenGL expects, and copy the source image to it.
            Drawing.Bitmap   textureImage = new Drawing.Bitmap(newSize.Width, newSize.Height);
            Drawing.Graphics g            = Drawing.Graphics.FromImage(textureImage);

            g.Transform = new System.Drawing.Drawing2D.Matrix();
            g.Clear(Drawing.Color.FromArgb(0, 0, 0, 0));
            g.DrawImage(sourceImage, new Drawing.Rectangle(new Drawing.Point(0, 0), sourceImage.Size));
            g.Dispose();

            mTextureSize = Interop.Convert(textureImage.Size);

            mTexCoord = GetTextureCoords(mSourceRect);


            // Rectangle For Locking The Bitmap In Memory
            Rectangle rectangle = new Rectangle(0, 0, textureImage.Width, textureImage.Height);

            // Get The Bitmap's Pixel Data From The Locked Bitmap
            BitmapData bitmapData = textureImage.LockBits(Interop.Convert(rectangle),
                                                          ImageLockMode.ReadOnly, Drawing.Imaging.PixelFormat.Format32bppArgb);

            // use a pixelbuffer to do format conversion.
            PixelBuffer buffer = new PixelBuffer(PixelFormat.RGBA8888, mTextureSize,
                                                 bitmapData.Scan0, PixelFormat.BGRA8888, bitmapData.Stride);

            // Create The GL Texture object
            int textureID;

            GL.GenTextures(1, out textureID);
            AddTextureRef(textureID);

            WritePixels(buffer);

            textureImage.UnlockBits(bitmapData);                                 // Unlock The Pixel Data From Memory
            textureImage.Dispose();                                              // Dispose The Bitmap
        }
コード例 #8
0
        public GL_Surface(Size size)
        {
            mDisplay = Display.Impl as GL_Display;
            mState   = mDisplay.State;

            mSourceRect = new Rectangle(Point.Empty, size);

            mTextureSize = new Size(NextPowerOfTwo(size.Width), NextPowerOfTwo(size.Height));

            //int[] array = new int[1];
            //GL.GenTextures(1, array);
            int textureID;

            GL.GenTextures(1, out textureID);

            AddTextureRef(textureID);

            IntPtr fake = IntPtr.Zero;

            try
            {
                fake = Marshal.AllocHGlobal(mTextureSize.Width * mTextureSize.Height * Marshal.SizeOf(typeof(int)));

                // Typical Texture Generation Using Data From The Bitmap
                GL.BindTexture(TextureTarget.Texture2D, mTextureID);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
                              mTextureSize.Width, mTextureSize.Height, 0, OTKPixelFormat.Rgba,
                              PixelType.UnsignedByte, fake);

                mTexCoord = GetTextureCoords(mSourceRect);
            }
            finally
            {
                if (fake != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(fake);
                }
            }
        }
コード例 #9
0
        public void AddQuad(int textureID, Gradient color, TextureCoordinates texCoord, PointF[] pts)
        {
            SetTexture(textureID);

            if (mIndex + 4 >= mVertexCoords.Length)
            {
                Flush();
                SetBufferSize(mVertexCoords.Length + 1000);
            }

            for (int i = 0; i < 4; i++)
            {
                mVertexCoords[mIndex + i].x = pts[i].X;
                mVertexCoords[mIndex + i].y = pts[i].Y;

                mNormalCoords[mIndex + i].x = 0;
                mNormalCoords[mIndex + i].y = 0;
                mNormalCoords[mIndex + i].z = -1;
            }

            mTexCoords[mIndex].u = texCoord.Left;
            mTexCoords[mIndex].v = texCoord.Top;
            mColorCoords[mIndex] = new ColorCoord(color.TopLeft);

            mTexCoords[mIndex + 1].u = texCoord.Right;
            mTexCoords[mIndex + 1].v = texCoord.Top;
            mColorCoords[mIndex + 1] = new ColorCoord(color.TopRight);

            mTexCoords[mIndex + 2].u = texCoord.Right;
            mTexCoords[mIndex + 2].v = texCoord.Bottom;
            mColorCoords[mIndex + 2] = new ColorCoord(color.BottomRight);

            mTexCoords[mIndex + 3].u = texCoord.Left;
            mTexCoords[mIndex + 3].v = texCoord.Bottom;
            mColorCoords[mIndex + 3] = new ColorCoord(color.BottomLeft);


            mIndex += 4;
        }
コード例 #10
0
        void DrawImpl(float destX, float destY, Rectangle srcRect, float rotationCenterX, float rotationCenterY)
        {
            SizeF dispSize = new SizeF(
                srcRect.Width * (float)ScaleWidth,
                srcRect.Height * (float)ScaleHeight);

            if (DisplaySize.Width < 0)
            {
                destX           -= dispSize.Width;
                rotationCenterX += dispSize.Width;
            }

            if (DisplaySize.Height < 0)
            {
                destY           -= dispSize.Height;
                rotationCenterY += dispSize.Height;
            }

            mTexCoord = GetTextureCoords(srcRect);

            mState.DrawBuffer.SetInterpolationMode(InterpolationHint);

            if (TesselateFactor == 1)
            {
                BufferQuad(destX, destY, rotationCenterX, rotationCenterY,
                           dispSize.Width, dispSize.Height, mTexCoord, ColorGradient);
            }
            else
            {
                TextureCoordinates texCoord = new TextureCoordinates();
                float texWidth  = mTexCoord.Right - mTexCoord.Left;
                float texHeight = mTexCoord.Bottom - mTexCoord.Top;

                float displayWidth  = DisplayWidth / (float)TesselateFactor;
                float displayHeight = DisplayHeight / (float)TesselateFactor;

                for (int j = 0; j < TesselateFactor; j++)
                {
                    texCoord.Top    = mTexCoord.Top + j * texHeight / TesselateFactor;
                    texCoord.Bottom = mTexCoord.Top + (j + 1) * texHeight / TesselateFactor;

                    for (int i = 0; i < TesselateFactor; i++)
                    {
                        texCoord.Left  = mTexCoord.Left + i * texWidth / TesselateFactor;
                        texCoord.Right = mTexCoord.Left + (i + 1) * texWidth / TesselateFactor;

                        float dx = destX + i * displayWidth * mRotationCos + j * displayHeight * mRotationSin;
                        float dy = destY - i * displayWidth * mRotationSin + j * displayHeight * mRotationCos;

                        double cx = i / (double)TesselateFactor;
                        double cy = j / (double)TesselateFactor;

                        Gradient color = new Gradient(
                            ColorGradient.Interpolate(cx, cy),
                            ColorGradient.Interpolate(cx + 1.0 / TesselateFactor, cy),
                            ColorGradient.Interpolate(cx, cy + 1.0 / TesselateFactor),
                            ColorGradient.Interpolate(cx + 1.0 / TesselateFactor, cy + 1.0 / TesselateFactor));

                        BufferQuad(dx, dy,
                                   rotationCenterX, rotationCenterY,
                                   displayWidth, displayHeight, texCoord, color);
                    }
                }
            }
            //GL.PushMatrix();

            //GL.Translatef(-translatePoint.X, -translatePoint.Y, 0);
            //GL.Rotatef((float)-RotationAngleDegrees, 0.0f, 0.0f, 1.0f);


            // restore the matrix
            //GL.PopMatrix();
        }
コード例 #11
0
 public void AddQuad(int textureID, Color color, TextureCoordinates texCoord, PointF[] pts)
 {
     AddQuad(textureID, new Gradient(color), texCoord, pts);
 }