/// <summary> /// 終了処理。(Disposeから呼び出されるので通例、呼び出す必要はない) /// </summary> private void Release() { if (hRC != IntPtr.Zero) { if (theFirstHRc != this.hRC) // ひとつ目のだけ保持しておく必要あり。 { Opengl32.wglDeleteContext(hRC); } hRC = IntPtr.Zero; } }
public override bool Begin(gdi.Color color) { if (stateDraw) { return(false); } Begin(); Opengl32.glClearColor(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f); Opengl32.glClear(GLConsts.GL_COLOR_BUFFER_BIT); ctx.Resize(); return(true); }
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); }
public void UnloadGPU() { if (GLTextureID != 0) { int id = GLTextureID; Opengl32.glDeleteTextures(1, ref id); GLTextureID = 0; } if (D2DBitmap != null && !D2DBitmap.IsDisposed) { D2DBitmap?.Dispose(); } //D2DBitmap = null; }
void render(float dt) { animationTime += dt; if (timerLog) { Console.WriteLine("Set clear Color"); } Opengl32.glClearColor(0, 0, 0, 1); if (timerLog) { Console.WriteLine("Clear Screen"); } Opengl32.glClear(GLConsts.GL_COLOR_BUFFER_BIT); pgl.Opengl32.glLoadIdentity(); float cx = (float)Math.Cos(animationTime); float sx = (float)Math.Sin(animationTime); pgl.Opengl32.glLoadMatrixf(new float[] { cx, sx, 0, 0, -sx, cx, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }); if (timerLog) { Console.WriteLine("Begin triangle"); } pgl.GL.Begin(PrimitiveType.TRIANGLES); pgl.GL.Color(Color.Yellow); pgl.GL.Vertex2(0, -.75f); pgl.GL.Color(Color.Green); pgl.GL.Vertex2(.75f, .75f); pgl.GL.Color(Color.Red); pgl.GL.Vertex2(-.75f, .75f); pgl.GL.End(); if (timerLog) { Console.WriteLine("Ended Triangle"); } if (timerLog) { Console.WriteLine("Swap Buffer"); } ctx.SwapBuffer(); timerLog = false; }
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); }
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); }
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(); }
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; } }
public override void ResetTransform() { Transformation = new Matrix3x3(); Opengl32.glLoadIdentity(); }
public override void Begin() { FBO.Bind(); Opengl32.glClear(GLConsts.GL_COLOR_BUFFER_BIT); }
// IntPtr oldContext; // ↑ // Win32WindowのSelectのネストが出来るようにしようと考えたのだが、 // 前のコンテキストを保存しておいても、 // Select // Select // Update ←このあと、1つ目のSelectのViewに設定しなおす必要があるのだが、 // このための復帰処理が難しい // Update // ので、こういう実装は現実的ではないと判断する。 // 初期化用のhelper関数 private YanesdkResult InitByHdc_(IntPtr hDc) { this.hDC = hDc; screen_ = new Screen2DGl(); screen_.BeginDrawDelegate = delegate { hDC = GetDC(this.hWnd); // oldContext = opengl32.wglGetCurrentContext(); Opengl32.wglMakeCurrent(this.hDC, this.hRC); // テクスチャー描画が基本なのでテクスチャーを有効にしておかねば }; screen_.EndDrawDelegate = delegate { SwapBuffers(this.hDC); Opengl32.wglMakeCurrent(this.hDC, IntPtr.Zero); ReleaseDC(this.hWnd, this.hDC); }; // 描画を行なわないdelegateを渡す。 // なぜなら、テクスチャの読み込みは、 // wglMakeCurrentが実行されていないと // 正しく読み込まれないので、beginDrawDelegateを行なってから // 読み込み、それが終わり次第この // delegateを呼び出して、openglのassignを解放してやる必要がある。 screen_.QuitDrawDelegate = delegate { Opengl32.wglMakeCurrent(this.hDC, IntPtr.Zero); // opengl32.wglMakeCurrent(this.hDC , oldContext); ReleaseDC(this.hWnd, this.hDC); }; YanesdkResult result = CreatePixelFormat(this.hDC); if (result != YanesdkResult.NoError) { return(result); } // Create a new OpenGL rendering contex this.hRC = Opengl32.wglCreateContext(this.hDC); // context共有を利用する。 // 0番は常に生きていると仮定。 // opengl32.wglShareLists(Singleton<GlInitializer>.Instance.hNullRC,this.hRC); // ↑これをやるとthreadが終了しなくなるので // 一つ目のRendering Contextだけ解放しないことにする。 if (theFirstHRc != IntPtr.Zero) { Opengl32.wglShareLists(theFirstHRc, this.hRC); } else { theFirstHRc = this.hRC; } ReleaseDC(this.hWnd, this.hDC); RECT32 rect = new RECT32(); // GetWindowRect((IntPtr)this.hWnd, out rect); GetClientRect((IntPtr)this.hWnd, out rect); Screen.UpdateView(rect.left - rect.right, rect.bottom - rect.top); return(YanesdkResult.NoError); }