Beispiel #1
0
        public GPURenderer3(System.Windows.Forms.Control cltr)
        {
            this.cltr = cltr;
            Console.WriteLine("Create Renderer {0}", Thread.CurrentThread.ManagedThreadId);
            ctx        = new RenderContext(cltr);
            IsHardware = true;
            float scale = GetScaleFactor();

            Width  = cltr.Width;
            Height = cltr.Height;

            Opengl32.glEnable(GLConsts.GL_MULTISAMPLE);
        }
Beispiel #2
0
 public override void DrawImage(Image img, RectangleF rect)
 {
     if (img.GLTextureID == 0)
     {
         img.LoadGL();
     }
     Opengl32.glBindTexture(GLConsts.GL_TEXTURE_2D, img.GLTextureID);
     Opengl32.glEnable(GLConsts.GL_TEXTURE_2D);
     GL.Color(1, 1, 1, 1);
     GL.Begin(PrimitiveType.QUADS);
     GL.TexCoord(0, 0); GL.Vertex2(rect.Left, rect.Top);
     GL.TexCoord(1, 0); GL.Vertex2(rect.Right, rect.Top);
     GL.TexCoord(1, 1); GL.Vertex2(rect.Right, rect.Bottom);
     GL.TexCoord(0, 1); GL.Vertex2(rect.Left, rect.Bottom);
     GL.End();
     Opengl32.glDisable(GLConsts.GL_TEXTURE_2D);
 }
Beispiel #3
0
        public override void DrawRenderBitmap(RenderBitmap bmp)
        {
            float x1 = 0, y1 = 0, x2 = Width, y2 = Height;

            if (bmp == null || !(bmp is RenderBitmap3))
            {
                return;
            }

            Opengl32.glEnable(GLConsts.GL_TEXTURE_2D);
            Opengl32.glBindTexture(GLConsts.GL_TEXTURE_2D, ((RenderBitmap3)bmp).FBO.Texture);

            GL.Color(1, 1, 1, 1);
            GL.Begin(PrimitiveType.QUADS);
            GL.TexCoord(0, 1); GL.Vertex2(x1, y1);
            GL.TexCoord(1, 1); GL.Vertex2(x2, y1);
            GL.TexCoord(1, 0); GL.Vertex2(x2, y2);
            GL.TexCoord(0, 0); GL.Vertex2(x1, y2);
            GL.End();
            Opengl32.glDisable(GLConsts.GL_TEXTURE_2D);
        }
Beispiel #4
0
        public override void DrawText(string str, PBrush brush, RectangleF rect, float size)
        {
            float quality = 5;

            size = Util.MmToPoint(size);
            rect = Util.MmToPoint(rect);
            gdi.Graphics dummy = gdi.Graphics.FromHwnd(IntPtr.Zero);
            gdi.Font     ft    = new gdi.Font("Calibri", size / Util.GetScaleFactor() * quality);
            gdi.SizeF    s     = dummy.MeasureString(str, ft);
            s.Height *= 2;
            s.Height *= quality;
            s.Width  *= quality;
            gdi.Bitmap     bmp = new gdi.Bitmap((int)s.Width, (int)s.Height);
            gdi.Color      c1  = brush.GetColor();
            gdi.Color      c2  = gdi.Color.FromArgb(0, c1.R, c1.G, c1.B);
            gdi.SolidBrush b   = new gdi.SolidBrush(c1);
            gdi.Graphics   g   = gdi.Graphics.FromImage(bmp);
            g.Clear(c2);
            g.DrawString(str, ft, b, new PointF(0, 0));

            int tex = GLRenderer.Util.LoadTexture(bmp);

            Opengl32.glEnable(GLConsts.GL_TEXTURE_2D);
            Opengl32.glBindTexture(GLConsts.GL_TEXTURE_2D, tex);
            rect = new RectangleF(rect.X, rect.Y, s.Width / quality, s.Height / quality);
            GL.Color(1, 1, 1, 1);
            GL.Begin(PrimitiveType.QUADS);
            GL.TexCoord(0, 0); GL.Vertex2(rect.Left, rect.Top);
            GL.TexCoord(1, 0); GL.Vertex2(rect.Right, rect.Top);
            GL.TexCoord(1, 1); GL.Vertex2(rect.Right, rect.Bottom);
            GL.TexCoord(0, 1); GL.Vertex2(rect.Left, rect.Bottom);
            GL.End();
            Opengl32.glDisable(GLConsts.GL_TEXTURE_2D);

            Opengl32.glDeleteTextures(1, ref tex);
            b.Dispose();
            bmp.Dispose();
            dummy.Dispose();
        }
Beispiel #5
0
        public override void Init()
        {
            ctx.InitAsync();
            ctx.MakeCurrent();
            NativeGL.nglInit();
            Opengl32.glBlendFunc(GLConsts.GL_SRC_ALPHA, GLConsts.GL_ONE_MINUS_SRC_ALPHA);
            Opengl32.glEnable(GLConsts.GL_BLEND);

            int eSize = 32;

            ellipse = new gdi.Bitmap(eSize, eSize);
            var g = gdi.Graphics.FromImage(ellipse);

            g.Clear(gdi.Color.Transparent);
            g.SmoothingMode = gdi2d.SmoothingMode.HighQuality;
            g.FillEllipse(gdi.Brushes.White, new RectangleF(1, 1, eSize - 2, eSize - 2));
            texEllipse = Kritzel.GLRenderer.Util.LoadTexture(ellipse);

            int eDet = 16;

            pEllipseX = new float[3 * eDet];
            pEllipseY = new float[3 * eDet];
            float l_x = 1, l_y = 0;

            for (int i = 0; i < eDet; i++)
            {
                float arg = (i + 1) / (float)eDet * 2 * (float)Math.PI;
                float x   = (float)Math.Cos(arg);
                float y   = (float)Math.Sin(arg);
                pEllipseX[i * 3]     = l_x;
                pEllipseY[i * 3]     = l_y;
                pEllipseX[i * 3 + 1] = 0;
                pEllipseY[i * 3 + 1] = 0;
                l_x = x; l_y = y;
                pEllipseX[i * 3 + 2] = x;
                pEllipseY[i * 3 + 2] = y;
            }
        }