Ejemplo n.º 1
0
        public static void drawTextureImage(TextureImage textrueImage, RectangleF srcRect, RectangleF destRect, Matrix4 matrix, float alpha)
        {
            alpha = MathUtil.limitNumber(alpha, 0, 1);
            //GLGraphics.setColor((uint)(0xFFFFFF | (((int)(alpha*255))<<24)));
            GL.Color4(1.0f, 1.0f, 1.0f, alpha);
            GL.PushMatrix();
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.LineSmooth);

            //目标尺寸
            float _dw = destRect.Width;
            float _dh = destRect.Height;

            //贴图坐标
            float txW = textrueImage.TextureWidth;
            float txH = textrueImage.TextureHight;
            float ltX = srcRect.X / txW;
            float ltY = srcRect.Y / txH;
            float rbX = (srcRect.X + srcRect.Width) / txW;
            float rbY = (srcRect.Y + srcRect.Height) / txH;

            GL.BindTexture(TextureTarget.Texture2D, textrueImage._name);
            matrixDraw.identity();
            matrixDraw.preTranslate(destRect.X, destRect.Y);
            if (matrix != null)
            {
                matrix.multiply(matrixDraw, matrixDraw);
            }
            float[] data = matrixDraw.getValue();
            GL.MultMatrix(data);
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(ltX, ltY);
            GL.Vertex3(0, 0, 0);
            GL.TexCoord2(rbX, ltY);
            GL.Vertex3(_dw, 0, 0);
            GL.TexCoord2(rbX, rbY);
            GL.Vertex3(_dw, _dh, 0);
            GL.TexCoord2(ltX, rbY);
            GL.Vertex3(0, _dh, 0);
            GL.End();


            GL.Disable(EnableCap.Texture2D);
            GL.PopMatrix();
        }
 public static TextureImage createImage(Bitmap bitmap)
 {
     TextureImage image = new TextureImage(bitmap);
     imgs.Add(image);
     return image;
 }
Ejemplo n.º 3
0
 /**
  * 简易的绘图方式
  */
 public static void drawTextureImage(TextureImage textrueImage, RectangleF srcRect,float destX,float destY)
 {
     drawTextureImage(textrueImage, srcRect, new RectangleF(destX, destY, srcRect.Width, srcRect.Height), null, 1.0f);
 }
Ejemplo n.º 4
0
        public static void drawTextureImage(TextureImage textrueImage, RectangleF srcRect, RectangleF destRect, Matrix4 matrix,float alpha)
	    {
            alpha = MathUtil.limitNumber(alpha, 0, 1);
            //GLGraphics.setColor((uint)(0xFFFFFF | (((int)(alpha*255))<<24)));
            GL.Color4(1.0f, 1.0f, 1.0f, alpha);
            GL.PushMatrix();
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.LineSmooth);

            //目标尺寸
            float _dw = destRect.Width;
            float _dh = destRect.Height;

            //贴图坐标
            float txW = textrueImage.TextureWidth;
            float txH = textrueImage.TextureHight;
            float ltX = srcRect.X / txW;
            float ltY = srcRect.Y / txH;
            float rbX = (srcRect.X + srcRect.Width) / txW;
            float rbY = (srcRect.Y + srcRect.Height) / txH;

            GL.BindTexture(TextureTarget.Texture2D, textrueImage._name);
            matrixDraw.identity();
            matrixDraw.preTranslate(destRect.X, destRect.Y);
            if (matrix != null)
            {
                matrix.multiply(matrixDraw, matrixDraw);
            }
            float[] data = matrixDraw.getValue();
            GL.MultMatrix(data);
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(ltX, ltY);
            GL.Vertex3(0, 0, 0);
            GL.TexCoord2(rbX, ltY);
            GL.Vertex3(_dw, 0, 0);
            GL.TexCoord2(rbX, rbY);
            GL.Vertex3(_dw, _dh, 0);
            GL.TexCoord2(ltX, rbY);
            GL.Vertex3(0, _dh, 0);
            GL.End();


            GL.Disable(EnableCap.Texture2D);
		    GL.PopMatrix();
	    }
Ejemplo n.º 5
0
 /**
  * 简易的绘图方式
  */
 public static void drawTextureImage(TextureImage textrueImage, RectangleF srcRect, float destX, float destY)
 {
     drawTextureImage(textrueImage, srcRect, new RectangleF(destX, destY, srcRect.Width, srcRect.Height), null, 1.0f);
 }
        public void UpdateRegion_EditFrame()
        {
            if (Form_MAnimation.inResetPanels)
            {
                return;
            }
            if (!loaded || this.IsHidden || this.Width <= 0 || this.Height <= 0)
            {
                return;
            }
            if (!glView.MakeCurrent())
            {
                return;
            }
            //获取屏幕尺寸
            imgEditBfWidth = glView.Width;
            imgEditBfHeight = glView.Height;
            GLGraphics.resetClip(imgEditBfWidth, imgEditBfHeight);
            //用白色清空屏幕
            GL.ClearColor(Color.White);
            //清除颜色和深度为缓冲
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            //重置模型视图矩阵
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            //用白色清空屏幕
            GL.ClearColor(Color.White);
            //附加属性
            //调整滚动条的调节范围(等同当前的背景图片可以动尺寸)
            setHScroolBarValue(MAX_OFFSET * 2 + 9, (MAX_OFFSET - imgEditCenterPixelX));
            setVScroolBarValue(MAX_OFFSET * 2 + 9, (MAX_OFFSET - imgEditCenterPixelY));

            //窗口缓冲尺寸
            if (imgEditBfWidth <= 0 || imgEditBfHeight <= 0)
            {
                return;
            }
            //映射坐标系
            matrixDraw.identity();
            matrixDraw.preScale(1.0f, -1.0f, 1.0f);
            matrixDraw.postTranslate(0, imgEditBfHeight, 0.0f);
            float[] data = matrixDraw.getValue();
            GL.MultMatrix(data);
            //创建网格
            int w_clip = 8;
            int h_clip = 8;
            if (imgEditBgBuffer == null || imgEditBgBuffer.OrgWidth != imgEditBfWidth + w_clip * 4
                || imgEditBgBuffer.OrgHeight != imgEditBfHeight + h_clip * 4)
            {
                Bitmap imgTemp = new Bitmap(imgEditBfWidth + w_clip * 4, imgEditBfHeight + h_clip * 4);
                int x = -w_clip;
                int y = -h_clip;
                bool bColor = true;
                Graphics gBgBuffer = Graphics.FromImage(imgTemp);
                GraphicsUtil.fillRect(gBgBuffer, 0, 0, imgTemp.Width, imgTemp.Height, Consts.color_white);
                while (x <= imgTemp.Width)
                {
                    bColor = !bColor;
                    int yT = y + (bColor ? h_clip : 0);
                    while (yT <= imgTemp.Height)
                    {
                        GraphicsUtil.fillRect(gBgBuffer, x, yT, w_clip, h_clip, Consts.colorGray);
                        yT += h_clip * 2;
                    }
                    x += w_clip;
                }
                imgEditBgBuffer = ConstTextureImgs.createImage(imgTemp);
                gBgBuffer.Dispose();
                gBgBuffer = null;
                imgTemp.Dispose();
                imgTemp = null;
            }
            //绘制背景
            if (Consts.showBgGrid)
            {
                int left = imgEditCenterPixelX * zoomLevel + imgEditBfWidth / 2;
                int top = -imgEditCenterPixelY * zoomLevel + imgEditBfHeight / 2;
                left += -(left / (w_clip * 2)) * (w_clip * 2);
                top += -(top / (h_clip * 2)) * (h_clip * 2);
                if (left > 0)
                {
                    left -= (w_clip * 2);
                }
                if (top > 0)
                {
                    top -= (h_clip * 2);
                }
                GLGraphics.drawTextureImage(imgEditBgBuffer, new RectangleF(-left, -top, imgEditBfWidth, imgEditBfHeight), 0, 0);
            }
            else
            {
                GLGraphics.setRGBColor(Consts.colorAnimBG);
                GLGraphics.fillRect(0, 0, imgEditBfWidth, imgEditBfHeight);
            }
            //绘制所有动画
            if (form_MA.form_MTimeLine != null)
            {
                //绘制洋葱皮效果
                if (Form_MTimeLine.OnionSkin_Enable)
                {
                    int bfCount = 1;
                    int ffCount = 1;
                    switch (Form_MTimeLine.OnionSkin_Mode)
                    {
                        case Form_MTimeLine.OnionSkinMode_FB:
                            bfCount = Form_MTimeLine.OnionSkin_Frame;
                            ffCount = Form_MTimeLine.OnionSkin_Frame;
                            break;
                        case Form_MTimeLine.OnionSkinMode_Back:
                            bfCount = Form_MTimeLine.OnionSkin_Frame;
                            ffCount = 0;
                            break;
                        case Form_MTimeLine.OnionSkinMode_Front:
                            bfCount = 0;
                            ffCount = Form_MTimeLine.OnionSkin_Frame;
                            break;
                    }

                    for (int i = -bfCount; i <= ffCount; i++)
                    {
                        if (i == 0)
                        {
                            continue;
                        }
                        List<MFrame> frameEditListX = form_MA.form_MTimeLine.getSameTimeFrames_Visible(Form_MTimeLine.timePosition + i);
                        foreach (MFrame frameEdit in frameEditListX)
                        {
                            if (frameEdit != null)
                            {
                                float alpha = (float)(Math.Pow(0.7, Math.Abs(i)));
                                frameEdit.glDisplay(getUICenterX(), getUICenterY(), zoomLevel, null, false, alpha, Form_MTimeLine.timePosition + i);
                            }
                        }
                    }

                }
                //绘制当前帧
                List<MFrame> frameEditList = form_MA.form_MTimeLine.getSameTimeFrames_Visible();
                foreach (MFrame frameEdit in frameEditList)
                {
                    if (frameEdit != null)
                    {
                        frameEdit.glDisplay(getUICenterX(), getUICenterY(), zoomLevel, currentUnits, TransformNew == null, Form_MTimeLine.timePosition);
                    }
                }
            }
            //边框
            if (Consts.showScreenFrame)
            {
                //世界边缘
                int screenW = Consts.screenWidth;
                int screenH = Consts.screenHeight;
                GLGraphics.setARGBColor(Consts.colorGrid, 0x88);
                GLGraphics.drawRect(
                    (imgEditCenterPixelX - screenW / 2) * zoomLevel + imgEditBfWidth / 2,
                    (imgEditCenterPixelY - screenH / 2) * zoomLevel + imgEditBfHeight / 2,
                    (screenW) * zoomLevel,
                    (screenH) * zoomLevel,false);
                screenW = MAX_OFFSET * 2;
                screenH = MAX_OFFSET * 2;
                //屏幕边框
                GLGraphics.setARGBColor(Consts.colorGrid1, 0x88);
                GLGraphics.drawRect(
                    (imgEditCenterPixelX - screenW / 2) * zoomLevel + imgEditBfWidth / 2,
                    (imgEditCenterPixelY - screenH / 2) * zoomLevel + imgEditBfHeight / 2,
                    (screenW) * zoomLevel,
                    (screenH) * zoomLevel, false);
            }
            if (Consts.showMFrameEdit_Axis)
            {
                GLGraphics.setARGBColor(Consts.colorMFrameEdit_Axis, 0x88);
                GLGraphics.drawLine(
                    imgEditCenterPixelX * zoomLevel + imgEditBfWidth / 2 - (MAX_OFFSET * zoomLevel),
                    imgEditCenterPixelY * zoomLevel + imgEditBfHeight / 2,
                    imgEditCenterPixelX * zoomLevel + imgEditBfWidth / 2 + (MAX_OFFSET * zoomLevel),
                    imgEditCenterPixelY * zoomLevel + imgEditBfHeight / 2,false);
                GLGraphics.drawLine(
                    imgEditCenterPixelX * zoomLevel + imgEditBfWidth / 2,
                    imgEditCenterPixelY * zoomLevel + imgEditBfHeight / 2 - (MAX_OFFSET * zoomLevel),
                    imgEditCenterPixelX * zoomLevel + imgEditBfWidth / 2,
                    imgEditCenterPixelY * zoomLevel + imgEditBfHeight / 2 + (MAX_OFFSET * zoomLevel), false);
            }

            //绘制变形框
            if (TransformNew != null)
            {
                TransformNew.glDisplay(getUICenterX(), getUICenterY(), zoomLevel, Consts.colorAnimSelect);
            }
            //绘制选择框
            if (clipEditMode == EMODE_SELECT_RECT)
            {
                GLGraphics.setRGBColor(Consts.colorAnimSelect);
                GLGraphics.drawLine(pointCursorOld.X, pointCursorOld.Y, pointCursorNew.X, pointCursorOld.Y,false);
                GLGraphics.drawLine(pointCursorOld.X, pointCursorOld.Y, pointCursorOld.X, pointCursorNew.Y, false);
                GLGraphics.drawLine(pointCursorNew.X, pointCursorOld.Y, pointCursorNew.X, pointCursorNew.Y, false);
                GLGraphics.drawLine(pointCursorOld.X, pointCursorNew.Y, pointCursorNew.X, pointCursorNew.Y, false);
            }
            glView.SwapBuffers();
        }
Ejemplo n.º 7
0
 public void rebindTexture()
 {
     if (GraphicsContext.CurrentContext == null)
     {
         return;
     }
     if (imageTextured == null)
     {
         imageTextured = new TextureImage((Bitmap)image);
     }
     else
     {
         imageTextured.rebindBitmap((Bitmap)image);
     }
 }