Exemple #1
0
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            Control senderControl = (Control)sender;

            if (context == null)
            {
                var glInterface = GRGlInterface.CreateNativeGlInterface();
                context = GRContext.Create(GRBackend.OpenGL, glInterface);
            }

            if (renderTarget == null || surface == null || renderTarget.Width != senderControl.Width || renderTarget.Height != senderControl.Height)
            {
                renderTarget?.Dispose();

                GL.GetInteger(GetPName.FramebufferBinding, out var framebuffer);
                GL.GetInteger(GetPName.StencilBits, out var stencil);
                var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());
                renderTarget = new GRBackendRenderTarget(senderControl.Width, senderControl.Height, context.GetMaxSurfaceSampleCount(colorType), stencil, glInfo);
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
            }

            figure.Render(surface.Canvas, figureSize, plotEngagedWithMouse);

            surface.Canvas.Flush();
            glControl1.SwapBuffers();
        }
        private void display(Int64 iter)
        {
            stopwatch.Start();
            simulateFluids();

            // render points from vertex buffer
            GL.Clear(ClearBufferMask.ColorBufferBit);

            if (iter % 1000 == 0)
            {
                R = (float)rnd.NextDouble();
                G = (float)rnd.NextDouble();
                B = (float)rnd.NextDouble();
            }

            DrawPoints(1.0f, 0.0f, 0.0f, 0, DS / 2);
            DrawPoints(0.0f, 1.0f, 0.0f, DS / 2, DS);

            // Finish timing before swap buffers to avoid refresh sync
            stopwatch.Stop();
            m_renderControl.SwapBuffers();

            fpsCount++;
            if (fpsCount == fpsLimit)
            {
                float  ifps = 1.0f / (stopwatch.GetElapsedTime() / 1000.0f);
                string fps  = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Cuda/GL Stable Fluids ({0} x {1}): {2} fps", DIM, DIM, ifps);
                this.Text = fps;
                fpsCount  = 0;
                fpsLimit  = (int)Math.Max(ifps, 1.0f);
            }
        }
Exemple #3
0
        private void glControl_Paint(object sender, PaintEventArgs e)
        {
            if (!RenderingEnabled)
            {
                return;
            }

            Render(false);

            glControl.SwapBuffers();

            Primitive prim    = null;
            string    objName = string.Empty;

            if (Client.Network.CurrentSim.ObjectsPrimitives.TryGetValue(RootPrimLocalID, out prim))
            {
                if (prim.Properties != null)
                {
                    objName = prim.Properties.Name;
                }
            }

            string title = string.Format("Object Viewer - {0}", instance.Names.Get(Client.Self.AgentID, Client.Self.Name));

            if (!string.IsNullOrEmpty(objName))
            {
                title += string.Format(" - {0}", objName);
            }

            Text = title;
        }
Exemple #4
0
        /// <summary>
        /// Paint a control
        /// </summary>
        /// <param name="control">Control to paint</param>
        /// <param name="tileid">Id of the tile to draw</param>
        private void DrawTiles(OpenTK.GLControl control, int tileid)
        {
            control.MakeCurrent();
            Display.ClearBuffers();

            SpriteBatch.Begin();

            // Background texture
            Rectangle dst = new Rectangle(Point.Empty, control.Size);

            SpriteBatch.Draw(CheckerBoard, dst, dst, Color.White);


            // Tile to draw
            if (TileSet != null)
            {
                Tile tile = TileSet.GetTile(tileid);
                if (tile != null)
                {
                    Point location = new Point((control.Width - tile.Size.Width) / 2, (control.Height - tile.Size.Height) / 2);
                    location.Offset(tile.Pivot);
                    SpriteBatch.DrawTile(TileSet, tileid, location);
                }
            }

            SpriteBatch.End();
            control.SwapBuffers();
        }
Exemple #5
0
 void draw()
 {
     glControl1.MakeCurrent();
     canvas.resize(glControl1.Width, glControl1.Height);
     canvas.draw(RenderingMode.Render, true);
     glControl1.SwapBuffers();
 }
        private void Glview_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (glview == null)
            {
                return;
            }

            ViewContext.VerifyContext(glview);
            ViewContext.Context.MakeCurrent(glview.WindowInfo);

            GL.Disable(EnableCap.CullFace);

            GL.Viewport(0, 0, glview.Width, glview.Height);
            GL.ClearColor(0.1f, 0.1f, 0.1f, 1);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Clear(ClearBufferMask.DepthBufferBit);

            Matrix4 proj        = Matrix4.CreateOrthographic(glview.Width, glview.Height, 0.03f, 1000f);
            Matrix4 translation = Matrix4.CreateTranslation((float)pan.X, (float)-pan.Y, 0);
            //half width/height for scale as it is centered based
            Matrix4 sm    = Matrix4.CreateScale(scale * (float)(vw * 0.5f), scale * (float)(vh * 0.5f), 1);
            Matrix4 model = sm * translation;
            Matrix4 view  = Matrix4.LookAt(new Vector3(0, 0, 1), Vector3.Zero, Vector3.UnitY);

            processor.FlipY      = true;
            processor.Model      = model;
            processor.View       = view;
            processor.Projection = proj;

            if (current != null && current.Node != null && current.Node.GetActiveBuffer() != null && current.Node.GetActiveBuffer().Id != 0)
            {
                processor.Bind(current.Node.GetActiveBuffer());
            }
            else if (blankTexture != null)
            {
                processor.Bind(blankTexture);
            }

            if (quad != null)
            {
                quad.Draw();
            }

            processor.Unbind();

            if (uvs != null && showUV)
            {
                uvs.View       = view;
                uvs.Projection = proj;
                uvs.Model      = model;
                uvs.Draw();
            }

            GL.Enable(EnableCap.CullFace);

            glview.SwapBuffers();
        }
Exemple #7
0
        internal static void GlControlPaint(object sender, PaintEventArgs e)
        {
            if (_image != null)
            {
                // describes a transformation that produces a parallel projection
                //GL.Ortho(-_width / 2, _width / 2, -_height / 2, _height / 2, -1.0, 1.0);
                //SetOffset();
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                if (!_textureRendered)
                {
                    DrawImage();
                }

                OnRenderFrame();
                _glControl.SwapBuffers();
            }
        }
Exemple #8
0
        /// <summary>
        /// Paint event
        /// </summary>
        public void Paint(OpenTK.GLControl control)
        {
            GL.Viewport(0, 0, control.Width, control.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            if (canDraw)
            {
                uniforms.UpdateUniforms(control);
                GL.DrawArrays(PrimitiveType.Triangles, 0, nVertices);
            }

            GL.Flush();
            control.SwapBuffers();
        }
Exemple #9
0
        private void ModelViewControl_Paint(object sender, PaintEventArgs e)
        {
            if (!glContextCreated)
            {
                return; //can't do anything with this, heh
            }
            ModelViewControl.MakeCurrent();

            SetupViewport();

            modelRenderer.Pitch           = (PitchTrackBar.Value - 8) * -22.5d;
            modelRenderer.Angle           = (AngleTrackBar.Value - 8) * -22.5d;
            modelRenderer.ShowBBs         = ShowBBCheckBox.Checked;
            modelRenderer.ShowNormals     = ShowNormCheckBox.Checked;
            modelRenderer.Wireframe       = WireframeCheckBox.Checked;
            modelRenderer.ShowRadius      = ShowRadiusCheckBox.Checked;
            modelRenderer.EmulateSoftware = NoDepthCheckBox.Checked;

            modelRenderer.Draw((int)ModelNumSpinner.Value);
            ModelViewControl.SwapBuffers();
        }
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            if (noPMView)
            {
                return;
            }
            if (!glContextCreated)
            {
                return; //can't do anything with this, heh
            }
            glControl1.MakeCurrent();

            modelRenderer.Pitch       = (trackBar3.Value - 8) * -22.5d;
            modelRenderer.Angle       = (trackBar1.Value - 8) * -22.5d;
            modelRenderer.ShowBBs     = chkShowBBs.Checked;
            modelRenderer.ShowNormals = chkNorm.Checked;
            modelRenderer.Wireframe   = chkWireframe.Checked;
            modelRenderer.ShowRadius  = chkRadius.Checked;

            modelRenderer.Draw();
            glControl1.SwapBuffers();
        }
Exemple #11
0
        private void display()
        {
            stopwatch.Start();
            simulateFluids();

            // render points from vertex buffer
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Color4(0, 1, 0, 0.5f);
            GL.PointSize(1);
            GL.Enable(EnableCap.PointSmooth);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
            GL.VertexPointer(2, VertexPointerType.Float, 0, 0);
            GL.DrawArrays(BeginMode.Points, 0, DS);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.TextureCoordArray);
            GL.Disable(EnableCap.Texture2D);

            // Finish timing before swap buffers to avoid refresh sync
            stopwatch.Stop();
            m_renderControl.SwapBuffers();

            fpsCount++;
            if (fpsCount == fpsLimit)
            {
                float  ifps = 1.0f / (stopwatch.GetElapsedTime() / 1000.0f);
                string fps  = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Cuda/GL Stable Fluids ({0} x {1}): {2} fps", DIM, DIM, ifps);
                this.Text = fps;
                fpsCount  = 0;
                fpsLimit  = (int)Math.Max(ifps, 1.0f);
            }
        }
Exemple #12
0
        private void OnPaint(object sender, PaintEventArgs e)
        {
            switch (renderingState)
            {
            case RenderingState.Updated:
                if (glControl.IsHandleCreated && form.Visible && !glControl.IsDisposed)
                {
                    glControl.MakeCurrent();
                    PixelScale = CalcPixelScale(e.Graphics.DpiX);
                    fpsCounter.Refresh();
                    RaiseRendering();
                    glControl.SwapBuffers();
                }
                renderingState = RenderingState.Rendered;
                break;

            case RenderingState.Rendered:
                renderingState = RenderingState.RenderDeferred;
                break;

            case RenderingState.RenderDeferred:
                break;
            }
        }
Exemple #13
0
        private void Glview_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (glview == null)
            {
                return;
            }

            ViewContext.VerifyContext(glview);
            ViewContext.Context.MakeCurrent(glview.WindowInfo);

            camera.Aspect = (float)glview.Width / (float)glview.Height;

            Matrix4 proj;

            if (previewCameraMode == PreviewCameraMode.Orthographic)
            {
                proj = camera.Orthographic;
            }
            else
            {
                proj = camera.Perspective;
            }

            //Update SSS
            mat.SSSAmbient    = materialSettings.SSSAmbient;
            mat.SSSDistortion = materialSettings.SSSDistortion;
            mat.SSSPower      = materialSettings.SSSPower;

            tessMat.SSSAmbient    = materialSettings.SSSAmbient;
            tessMat.SSSDistortion = materialSettings.SSSDistortion;
            tessMat.SSSPower      = materialSettings.SSSPower;

            //update other material settings
            mat.IOR             = materialSettings.IndexOfRefraction;
            mat.HeightScale     = materialSettings.HeightScale;
            mat.ClipHeight      = materialSettings.Clip;
            mat.ClipHeightBias  = materialSettings.HeightClipBias;
            mat.UseDisplacement = false;

            tessMat.IOR             = materialSettings.IndexOfRefraction;
            tessMat.HeightScale     = materialSettings.HeightScale;
            tessMat.ClipHeight      = materialSettings.Clip;
            tessMat.ClipHeightBias  = materialSettings.HeightClipBias;
            tessMat.UseDisplacement = true;

            CheckTessMaterials();
            CheckBaseMaterials();

            IGL.Primary.Viewport(0, 0, glview.Width, glview.Height);
            IGL.Primary.ClearColor(0.1f, 0.1f, 0.1f, 1);
            IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit);
            IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit);

            if (previewRenderMode == PreviewRenderMode.WireframeShading)
            {
                IGL.Primary.PolygonMode((int)MaterialFace.FrontAndBack, (int)PolygonMode.Line);
            }

            MeshRenderer[] meshes = GatherMeshes(ref proj, camera, materialSettings.Displacement ? tessMat : mat);

            if (basePass != null)
            {
                basePass.Update(meshes, glview.Width, glview.Height);
            }
            if (bloomPass != null)
            {
                bloomPass.Intensity = lightSettings.BloomIntensity;
                bloomPass.Update(glview.Width, glview.Height);
            }

            if (renderStack != null)
            {
                renderStack.Process();
            }

            IGL.Primary.PolygonMode((int)MaterialFace.FrontAndBack, (int)PolygonMode.Fill);

            glview.SwapBuffers();
        }
Exemple #14
0
        void GLWindow_Paint(object sender, PaintEventArgs e)
        {
            GLPic.MakeCurrent();

            //GL.DrawBuffer(DrawBufferMode.BackLeft);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.ClearColor(0.1f, 0.1f, 0.3f, 0.0f);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(0, 1, 0, 1, -1, 1);

            if (curMode == StereoMode.CrossedEyes)
            {
                #region Draws 3D mouse cursor
                float xMouse, yMouse; float cursorSize = 0.05f;
                xMouse = curMousePos.X > 0.5 ? curMousePos.X - 0.5f : curMousePos.X;
                yMouse = 1.0f - curMousePos.Y;
                GL.Translate(0.0f, 0.0f, -1.0f);

                //Adjust cursor color
                DateTime dt          = DateTime.Now;
                double   param       = dt.Second + dt.Millisecond * 0.001f + 60.0 * dt.Minute + 3600.0 * dt.Hour;
                float    cursorColor = (float)Math.Pow((0.5 + 0.5 * Math.Sin(4.1 * param)), 8);
                GL.Color4(cursorColor, cursorColor, cursorColor, 1.0f);

                GL.LineWidth(2);
                GL.BindTexture(TextureTarget.Texture2D, 0);
                GL.Begin(BeginMode.Lines);
                {
                    //Cursor of right image (displayed to the left)
                    GL.Vertex3(xMouse - cursorSize * 0.5f, yMouse, 0.1f);
                    GL.Vertex3(xMouse + cursorSize * 0.5f, yMouse, 0.1f);
                    GL.Vertex3(xMouse, yMouse - cursorSize * 0.5f * aspect, 0.2f);
                    GL.Vertex3(xMouse, yMouse + cursorSize * 0.5f * aspect, 0.2f);

                    //Cursor of left image (displayed to the right)
                    GL.Vertex3(0.5f + xMouse - cursorSize * 0.5f, yMouse, 0.2f);
                    GL.Vertex3(0.5f + xMouse + cursorSize * 0.5f, yMouse, 0.2f);
                    GL.Vertex3(0.5f + xMouse, yMouse - cursorSize * 0.5f * aspect, 0.2f);
                    GL.Vertex3(0.5f + xMouse, yMouse + cursorSize * 0.5f * aspect, 0.2f);
                }
                GL.End();
                #endregion
            }

            //GLPic.SwapBuffers();
            //return;

            //Check texture
            if (GLTex == 0)
            {
                GLTex = GL.GenTexture();
                ApplyTex(ImgBmp, GLTex);
            }

            #region Perform animation if using animated stereo mode

            if (curMode == StereoMode.Wiggle)
            {
                //Adjust cursor color
                DateTime dt2    = DateTime.Now;
                double   param2 = dt2.Second + dt2.Millisecond * 0.001f + 60.0 * dt2.Minute + 3600.0 * dt2.Hour;

                double temp      = Math.Sin(3.1 * param2);
                float  minIntens = 0.2f;

                float imgIntens = (float)(temp * (0.5 - minIntens) + 0.5);
                VBOColor[16 + 3] = imgIntens; VBOColor[16 + 7] = imgIntens; VBOColor[16 + 11] = imgIntens; VBOColor[16 + 15] = imgIntens;

                GL.BindBuffer(BufferTarget.ArrayBuffer, GLVBOs[1]);
                GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(VBOColor.Length * sizeof(float)), VBOColor, BufferUsageHint.DynamicDraw);
            }

            #endregion


            #region Draw VBOs
            GL.BindTexture(TextureTarget.Texture2D, GLTex);

            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            //GL.EnableClientState(ArrayCap.NormalArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);

            GL.BindBuffer(BufferTarget.ArrayBuffer, GLVBOs[0]);
            GL.VertexPointer(3, VertexPointerType.Float, 0, 0);

            GL.BindBuffer(BufferTarget.ArrayBuffer, GLVBOs[1]);
            GL.ColorPointer(4, ColorPointerType.Float, 0, 0);

            //GL.BindBuffer(BufferTarget.ArrayBuffer, parte.GLBuffers[2]);
            //GL.NormalPointer(NormalPointerType.Float, 0, 0);

            GL.BindBuffer(BufferTarget.ArrayBuffer, GLVBOs[2]);
            GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, 0);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, GLVBOs[3]);

            GL.DrawElements(BeginMode.Triangles, VBOElements.Length, DrawElementsType.UnsignedInt, 0);

            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.ColorArray);
            //GL.DisableClientState(ArrayCap.NormalArray);
            GL.DisableClientState(ArrayCap.TextureCoordArray);
            #endregion


            //RIGHT
            //AplicaTextura(bmp2);
            //if (bmp2 != null) GL.BindTexture(TextureTarget.Texture2D, texture[1]);
            //GL.Scale(scale, scale, scale);
            //GL.Translate((tx + txTemp) * scale - paralax, (ty + tyTemp) * scale, 0);


            GLPic.SwapBuffers();
        }
        private void Render(int cornerCount = 100, int maxVisibleDistance = 200)
        {
            // create the field if needed or if the size changed
            if (field == null || field.width != glControl1.Width || field.height != glControl1.Height)
            {
                field = new IntroAnimation.Field(glControl1.Width, glControl1.Height, cornerCount);
            }

            // step the field forward in time
            field.StepForward(3);

            // Create a Skia surface using the OpenGL control
            SKColorType colorType     = SKColorType.Rgba8888;
            GRContext   contextOpenGL = GRContext.Create(GRBackend.OpenGL, GRGlInterface.CreateNativeGlInterface());

            GL.GetInteger(GetPName.FramebufferBinding, out var framebuffer);
            GRGlFramebufferInfo glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());

            GL.GetInteger(GetPName.StencilBits, out var stencil);
            GRBackendRenderTarget renderTarget = new GRBackendRenderTarget(glControl1.Width, glControl1.Height, contextOpenGL.GetMaxSurfaceSampleCount(colorType), stencil, glInfo);
            SKSurface             surface      = SKSurface.Create(contextOpenGL, renderTarget, GRSurfaceOrigin.BottomLeft, colorType);
            SKCanvas canvas = surface.Canvas;

            // draw the stuff
            var bgColor = field.GetBackgroundColor();

            canvas.Clear(new SKColor(bgColor.R, bgColor.G, bgColor.B));

            // draw circles at every corner
            var paint = new SKPaint {
                Color = new SKColor(255, 255, 255), IsAntialias = true
            };
            float radius = 2;

            for (int cornerIndex = 0; cornerIndex < field.corners.Length; cornerIndex++)
            {
                canvas.DrawCircle((float)field.corners[cornerIndex].X, (float)field.corners[cornerIndex].Y, radius, paint);
            }

            // draw lines between every corner and every other corner
            for (int i = 0; i < field.corners.Length; i++)
            {
                for (int j = 0; j < field.corners.Length; j++)
                {
                    double distance = field.GetDistance(i, j);
                    if (distance < maxVisibleDistance && distance != 0)
                    {
                        SKPoint pt1 = new SKPoint((float)field.corners[i].X, (float)field.corners[i].Y);
                        SKPoint pt2 = new SKPoint((float)field.corners[j].X, (float)field.corners[j].Y);
                        double  distanceFraction = distance / maxVisibleDistance;
                        byte    alpha            = (byte)(255 - distanceFraction * 256);
                        var     linePaint        = new SKPaint {
                            Color = new SKColor(255, 255, 255, alpha), IsAntialias = true
                        };
                        canvas.DrawLine(pt1, pt2, linePaint);
                    }
                }
            }

            // Force a display
            surface.Canvas.Flush();
            glControl1.SwapBuffers();

            // dispose to prevent memory access violations while exiting
            renderTarget?.Dispose();
            contextOpenGL?.Dispose();
            canvas?.Dispose();
            surface?.Dispose();

            // update the FPS display
            Text = field.GetBenchmarkMessage();
        }
Exemple #16
0
 private void GLControl_Paint(object sender, PaintEventArgs e)
 {
     view.Draw(this.Width, this.Height);
     glControl.SwapBuffers();
 }
Exemple #17
0
 /// <summary>Finish up rendering. The default swaps buffers.</summary>
 protected void RenderEnd()
 {
     Renderer.SwapBuffers();
 }
Exemple #18
0
 private void GLPaint(object sender, PaintEventArgs e)
 {
     GLViewer.MakeCurrent();
     SV.DrawQuads();
     GLViewer.SwapBuffers();
 }
Exemple #19
0
        public void draw()
        {
            if (Form1.currentX0 != null && Form1.currentY0 != null && Form1.currentZ0 != null)
            {
                Yoff = (float)Form1.currentY0 - 129.9f;
                Xoff = (float)Form1.currentX0 - 289.9f;
                Zoff = -(float)Form1.currentZ0 + 140f;
            }

            addLine();
            removePoint();
            checkVol();

            //GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            displayBackground();

            float far = 800, near = 50f;



            OpenTK.Matrix4 RTMat = new OpenTK.Matrix4(
                rotateArr[0], rotateArr[1], rotateArr[2], translateArr[0],
                rotateArr[3], rotateArr[4], rotateArr[5], translateArr[1],
                rotateArr[6], rotateArr[7], rotateArr[8], translateArr[2],
                0, 0, 0, 1);

            OpenTK.Matrix4 reverse = new OpenTK.Matrix4(
                1, 0, 0, 0,
                0, -1, 0, 0,
                0, 0, -1, 0,
                0, 0, 0, 1);

            //not sure if needed
            OpenTK.Matrix4 landscape = new OpenTK.Matrix4(
                0, 1, 0, 0,
                -1, 0, 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1);

            OpenTK.Matrix4 projection = new OpenTK.Matrix4(
                2 * cameraPar[0] / 816f, 0, 1 - (2 * cameraPar[2] / 816f), 0,
                0, 2 * cameraPar[4] / 612f, -1 + (2 * cameraPar[5] + 2) / 612f, 0,
                0, 0, -(far + near) / (far - near), -2 * far * near / (far - near),
                0, 0, -1, 0);

            OpenTK.Matrix4 projT = new OpenTK.Matrix4(
                2 * cameraPar[0] / 816f, 0, 1 - (2 * cameraPar[2] / 816f), 0,
                0, 2 * cameraPar[4] / 612f, -1 + (2 * cameraPar[5] + 2) / 612f, 0,
                0, 0, -(far + near) / (far - near), -2 * far * near / (far - near),
                0, 0, -1, 0);

            projT.Transpose();
            OpenTK.Matrix4 mvMat    = OpenTK.Matrix4.Mult(reverse, RTMat);
            OpenTK.Matrix4 projMat2 = OpenTK.Matrix4.Mult(landscape, projection);
            OpenTK.Matrix4 mvp      = OpenTK.Matrix4.Mult(projection, mvMat);


            // render graphics

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.LoadMatrix(ref projT.Row0.X);

            mvMat.Transpose();
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.LoadMatrix(ref mvMat.Row0.X);


            /*
             * GL.LineWidth(2.5f);
             * GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
             * GL.Color3(Color.Green);
             * GL.Begin(PrimitiveType.Lines);
             * GL.Vertex3(0, 0, 0);
             * GL.Vertex3(0, 0, 100);
             *
             * GL.End();
             *
             * GL.Color3(Color.Aqua);
             * GL.Begin(PrimitiveType.Lines);
             * GL.Vertex3(0, 0, 0);
             * GL.Vertex3(0, 31, 0);
             *
             *
             * GL.Color3(Color.Yellow);
             * GL.Begin(PrimitiveType.Lines);
             * GL.Vertex3(31, 0, 0);
             * GL.Vertex3(0, 0, 0);
             *
             * GL.End();
             */


            if (camInit == true)
            {
                if (Form1.axisDisplay)
                {
                    if (Form1.currentX0 != null && Form1.currentY0 != null && Form1.currentZ0 != null)
                    {
                        GL.LineWidth(5.5f);
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                        GL.Color3(.99f, 0.1f, 0.1f);
                        GL.Begin(PrimitiveType.Lines);
                        GL.Vertex3(Xoff, Yoff, Zoff);
                        GL.Vertex3(Xoff, Yoff, Zoff + 93);

                        GL.End();

                        GL.Color3(0.1f, 0.99f, 0.1f);
                        GL.Begin(PrimitiveType.Lines);
                        GL.Vertex3(Xoff, Yoff, Zoff);
                        GL.Vertex3(Xoff - 93, Yoff, Zoff);


                        GL.Color3(.1f, 0.1f, 0.99f);
                        GL.Begin(PrimitiveType.Lines);

                        GL.Vertex3(Xoff, Yoff, Zoff);
                        GL.Vertex3(Xoff, Yoff - 93, Zoff);

                        GL.End();
                    }
                }


                if (Form1.physicalToolpath)
                {
                    foreach (line ln in lineList)
                    {
                        GL.LineWidth(2.5f);
                        GL.Color3(Color.Blue);
                        GL.Begin(PrimitiveType.Lines);
                        GL.Vertex3(-ln.startX + Form1.currentX0.Value + 188 + toolXoff - 289.9, -ln.startY + Form1.currentY0.Value + toolYoff + 50 - 129.9, (ln.startZ - Form1.currentZ0.Value + 140 - toolZoff));
                        GL.Vertex3(-ln.endX + Form1.currentX0.Value + 188 + toolXoff - 289.9, -ln.endY + Form1.currentY0.Value + toolYoff + 50 - 129.9, (ln.endZ - Form1.currentZ0.Value + 140 - toolZoff));

                        GL.End();
                    }
                }

                if (Form1.tooltipDisplay)
                {
                    GL.LineWidth(20f);
                    line Drill = new line(Form1.currentX0.Value, Form1.currentY0.Value, Form1.currentZ0.Value, Form1.currentX0.Value, Form1.currentY0.Value, Form1.currentZ0.Value + 50);
                    GL.Color3(Color.Silver);
                    GL.Begin(PrimitiveType.Lines);
                    GL.Vertex3(-Drill.startX + Form1.currentX0.Value + 188 + toolXoff - 289.9, -Drill.startY + Form1.currentY0.Value + toolYoff + 50 - 129.9, (Drill.startZ - Form1.currentZ0.Value + 140 - toolZoff));
                    GL.Vertex3(-Drill.endX + Form1.currentX0.Value + 188 + toolXoff - 289.9, -Drill.endY + Form1.currentY0.Value + toolYoff + 50 - 129.9, (Drill.endZ - Form1.currentZ0.Value + 140 - toolZoff));

                    GL.End();
                }


                GL.Enable(EnableCap.DepthTest);
                GL.DepthFunc(DepthFunction.Lequal);

                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                GL.Enable(EnableCap.Blend);

                if (Form1.badVolDisplay)
                {
                    foreach (badVolume badVol in badVolumes)
                    {
                        Color a = Color.FromArgb(160, 255, 0, 0);
                        Color b = Color.FromArgb(160, 225, 25, 25);
                        Color c = Color.FromArgb(160, 195, 50, 50);
                        Color d = Color.FromArgb(160, 225, 25, 25);

                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        Color black = Color.FromArgb(0, 0, 0);
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                        GL.Color4(black);
                        GL.LineWidth(1.2f);


                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.End();
                    }
                }



                GL.LineWidth(1.8f);



                if (Form1.matRemove)
                {
                    wp.draw();
                    wp.draw2();
                }



                if (Form1.cadModel)
                {
                    Color black = Color.FromArgb(0, 0, 0);


                    Color a = Color.FromArgb(160, 119, 136, 153);
                    Color b = Color.FromArgb(160, 112, 138, 144);
                    Color c = Color.FromArgb(160, 49, 79, 79);



                    GL.LineWidth(1.0f);
                    foreach (stlObj obj in objects)
                    {
                        object[] facetArray = obj.facets.ToArray();
                        for (int i = 0; i < obj.facetNum - 1; i++)
                        {
                            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

                            Object fcet = (facet)facetArray[i];
                            GL.Begin(PrimitiveType.Triangles);
                            facet fct = (facet)fcet;

                            if (Form1.currentX0 != null && Form1.currentY0 != null && Form1.currentZ0 != null)
                            {
                                GL.Color4(a);
                                GL.Vertex3(-fct.points[0].x + Xoff, -fct.points[0].y + Yoff, fct.points[0].z + Zoff);
                                GL.Color4(b);
                                GL.Vertex3(-fct.points[1].x + Xoff, -fct.points[1].y + Yoff, fct.points[1].z + Zoff);
                                GL.Color4(c);
                                GL.Vertex3(-fct.points[2].x + Xoff, -fct.points[2].y + Yoff, fct.points[2].z + Zoff);

                                GL.End();
                            }
                            else
                            {
                                GL.Color4(a);
                                GL.Vertex3(-fct.points[0].x, -fct.points[0].y, fct.points[0].z);
                                GL.Color4(b);
                                GL.Vertex3(-fct.points[1].x, -fct.points[1].y, fct.points[1].z);
                                GL.Color4(c);
                                GL.Vertex3(-fct.points[2].x, -fct.points[2].y, fct.points[2].z);

                                GL.End();
                            }

                            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                            GL.Color4(black);
                            GL.Begin(PrimitiveType.LineLoop);

                            GL.Vertex3(-fct.points[0].x + Xoff, -fct.points[0].y + Yoff, fct.points[0].z + Zoff);
                            GL.Vertex3(-fct.points[1].x + Xoff, -fct.points[1].y + Yoff, fct.points[1].z + Zoff);
                            GL.Vertex3(-fct.points[2].x + Xoff, -fct.points[2].y + Yoff, fct.points[2].z + Zoff);

                            GL.End();
                        }
                    }
                }



                GL.Disable(EnableCap.Blend);
            }

            glControl1.Refresh();// redraws and updates



            glControl1.SwapBuffers();
        }