SwapBuffers() public method

Swaps the front and back buffers, presenting the rendered scene to the screen.
public SwapBuffers ( ) : void
return void
Exemplo n.º 1
0
 public void draw_attractor()
 {
     GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
     GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, Color4.Red);
     my_draw_attractor();
     glControl.SwapBuffers();
 }
Exemplo n.º 2
0
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            if (!glContextCreated)
            {
                return; //can't do anything with this, heh
            }
            glControl1.MakeCurrent();
            renderer.Pitch           = (trackBar2.Value - 8) * -22.5d;
            renderer.Angle           = (trackBar1.Value - 8) * -22.5d;
            renderer.ShowBBs         = chkShowBBs.Checked;
            renderer.ShowNormals     = chkNorm.Checked;
            renderer.Wireframe       = chkWireframe.Checked;
            renderer.ShowRadius      = chkRadius.Checked;
            renderer.EmulateSoftware = chkSoftwareOverdraw.Checked;
            if (chkAnimation.Checked)
            {
                renderer.Frame = (int)numericUpDown1.Value;
            }
            else
            {
                renderer.Frame = -1;
            }

            renderer.Draw();

            glControl1.SwapBuffers();
        }
Exemplo n.º 3
0
        private void Updater_Tick(object sender, EventArgs e)
        {
            c++;
            ErrorCode er = GL.GetError();

            if (er != ErrorCode.NoError)
            {
                System.Console.WriteLine(er);
            }
            t.Stop();
            float et = (float)t.Elapsed.TotalSeconds;

            ti += et;
            t.Restart();
            while (ti > 1)
            {
                ti--;
                fps = c;
                c   = 0;
                //System.Console.WriteLine(fps);
            }
            //_scene.Update(et, OpenTK.Input.Mouse.GetState().WheelPrecise * 2);
            _scene.Render();
            glc.SwapBuffers();

            fpsLable.Text = "Fps : " + fps;
        }
Exemplo n.º 4
0
        private void Render()
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.PushMatrix();

            var mouseState = OpenTK.Input.Mouse.GetCursorState();
            var mousePos   = _glControl.PointToClient(new Point(mouseState.X, mouseState.Y));


            GL.Translate(mousePos.X, Height - mousePos.Y, 0.0);

            GL.Begin(PrimitiveType.Lines);            // These vertices form a closed polygon
            GL.Vertex2(-10.0f, 0.0f);
            GL.Vertex2(10.0f, 0.0f);
            GL.Vertex2(0.0f, -10.0f);
            GL.Vertex2(0.0f, 10.0f);
            GL.End();

            GL.PopMatrix();

            GL.Begin(PrimitiveType.Polygon); // These vertices form a closed polygon
            GL.Color3(1.0f, 1.0f, 0.0f);     // Yellow
            GL.Vertex2(40.0f, 20.0f);
            GL.Vertex2(60.0f, 20.0f);
            GL.Vertex2(70.0f, 40.0f);
            GL.Vertex2(60.0f, 60.0f);
            GL.Vertex2(40.0f, 60.0f);
            GL.Vertex2(30.0f, 40.0f);
            GL.End();

            GL.Flush();

            _glControl.SwapBuffers();
        }
Exemplo n.º 5
0
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            if (!glContextCreated)
            {
                return; //can't do anything with this, heh
            }
            if (nudElementNum.Value < 0)
            {
                return;
            }

            if (datafile.replacedModels.Count == 0)
            {
                return; //can't do anything with no models.
            }
            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();
        }
Exemplo n.º 6
0
        public void Run()
        {
            using (Form form = CreateForm())
            {
                var mGLControl = new GLControl
                {
                    Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
                    BackColor = Color.LightGreen,
                    Location = new Point(1, 0),
                    Name = "GL Control",
                    Size = new Size(WIDTH, HEIGHT),
                    TabIndex = 0,
                    VSync = false
                };
                form.Controls.Add(mGLControl);

                //have to set this to get a -1 to 1 system view
                GL.Viewport(0, 0, WIDTH, HEIGHT);

                mPositions = new[]
                {
                    new Vector3(-1, -1, 0),
                    new Vector3(1, -1, 0),
                    new Vector3(0, 1, 0)
                };
                mColors = new[]
                {
                    Color.Red, Color.Green,
                    Color.Blue
                };

                Application.Idle +=
                    delegate
                    {
                        mGLControl.MakeCurrent();

                        GL.ClearColor(mGLControl.BackColor);
                        GL.Clear(ClearBufferMask.ColorBufferBit);

                        RenderFrame();

                        mGLControl.SwapBuffers();
                    };

                form.BringToFront();
                Application.Run(form);
            }
        }
Exemplo n.º 7
0
        internal static void DefaultRender(float rotation)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            if (viewport_changed)
            {
                viewport_changed = false;
                SetupViewport();
            }

            DrawText();

            DrawCube(viewportWidth / (float)viewportHeight, rotation);

            renderView.SwapBuffers();
        }
Exemplo n.º 8
0
        public void Draw(OpenTK.GLControl glControl)
        {
            GL.ClearColor(Color.AliceBlue);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.UseProgram(BasicProgramID);

            // Camera
            int location = GL.GetUniformLocation(BasicProgramID, "scale");

            GL.Uniform2(location, new Vector2(1, 1 / aspect));

            // Tracing depth
            int traceDepth = GL.GetUniformLocation(BasicProgramID, "traceDepth");

            GL.Uniform1(traceDepth, uniform_traceDepth);

            // Materials color
            for (int i = 0; i < uniform_materialColors.Length; i++)
            {
                int   materialColor = GL.GetUniformLocation(BasicProgramID, $"materialColor{i}");
                Color color         = uniform_materialColors[i];
                GL.Uniform3(materialColor, new Vector3(color.R / 255f, color.G / 255f, color.B / 255f));
            }

            // Quad
            GL.Color3(Color.White);
            GL.Begin(PrimitiveType.Quads);

            GL.TexCoord2(0, 1);
            GL.Vertex2(-1, -1);

            GL.TexCoord2(1, 1);
            GL.Vertex2(1, -1);

            GL.TexCoord2(1, 0);
            GL.Vertex2(1, 1);

            GL.TexCoord2(0, 0);
            GL.Vertex2(-1, 1);

            GL.End();

            glControl.SwapBuffers();

            GL.UseProgram(0);
        }
Exemplo n.º 9
0
 public static void SwapBuffers(GLControl glControl)
 {
     glControl.SwapBuffers();
 }
Exemplo n.º 10
0
        private void Glview_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (glview == null)
            {
                return;
            }

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

            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);

            float wratio = (float)glview.Width / (float)glview.Height;

            if (previewCameraMode == PreviewCameraMode.Orthographic)
            {
                proj = Matrix4.CreateOrthographic(Math.Max(1, cameraTranslation.Z), Math.Max(1, cameraTranslation.Z / wratio), 0.03f, 1000f);
            }
            else
            {
                proj = Matrix4.CreatePerspectiveFieldOfView(40 * (float)(Math.PI / 180.0f), (float)glview.Width / (float)glview.Height, 0.03f, 1000f);
            }

            Matrix4 view = Matrix4.CreateFromQuaternion(rotation) * Matrix4.CreateTranslation(-cameraTranslation);
            Vector3 pos  = Vector3.Normalize((view * new Vector4(0, 0, 1, 1)).Xyz) * cameraTranslation.Z;

            CheckMaterials();

            if (previewType == PreviewGeometryType.Cube)
            {
                if (cube != null)
                {
                    cube.CameraPosition = pos;
                    cube.IrradianceMap  = irradiance;
                    cube.PrefilterMap   = prefiltered;
                    cube.Projection     = proj;
                    cube.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    cube.View           = view;
                    cube.LightColor     = lightColor;
                    cube.LightPosition  = lightPosition;
                    cube.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.Sphere)
            {
                if (sphere != null)
                {
                    sphere.CameraPosition = pos;
                    sphere.IrradianceMap  = irradiance;
                    sphere.PrefilterMap   = prefiltered;
                    sphere.Projection     = proj;
                    sphere.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    sphere.View           = view;
                    sphere.LightColor     = lightColor;
                    sphere.LightPosition  = lightPosition;
                    sphere.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.Cylinder)
            {
                if (cylinder != null)
                {
                    cylinder.CameraPosition = pos;
                    cylinder.IrradianceMap  = irradiance;
                    cylinder.PrefilterMap   = prefiltered;
                    cylinder.Projection     = proj;
                    cylinder.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    cylinder.View           = view;
                    cylinder.LightColor     = lightColor;
                    cylinder.LightPosition  = lightPosition;
                    cylinder.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.Plane)
            {
                if (plane != null)
                {
                    plane.CameraPosition = pos;
                    plane.IrradianceMap  = irradiance;
                    plane.PrefilterMap   = prefiltered;
                    plane.Projection     = proj;
                    plane.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    plane.View           = view;
                    plane.LightColor     = lightColor;
                    plane.LightPosition  = lightPosition;
                    plane.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.RoundedCube)
            {
                if (cubeRounded != null)
                {
                    cubeRounded.CameraPosition = pos;
                    cubeRounded.IrradianceMap  = irradiance;
                    cubeRounded.PrefilterMap   = prefiltered;
                    cubeRounded.Projection     = proj;
                    cubeRounded.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    cubeRounded.View           = view;
                    cubeRounded.LightColor     = lightColor;
                    cubeRounded.LightPosition  = lightPosition;
                    cubeRounded.Draw();
                }
            }

            glview.SwapBuffers();
        }
Exemplo n.º 11
0
        internal void OnGraphicsContextInitialized(GLControl context, WindowsFormsHost host)
        {
            m_control = context;

            m_editorCore = new EditorCore();
            m_intervalTimer = new System.Windows.Forms.Timer();
            m_intervalTimer.Interval = 16; // 60 FPS roughly
            m_intervalTimer.Enabled = true;
            m_intervalTimer.Tick += (args, o) =>
            {
                Vector2 mousePosGlobal = new Vector2(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y);
                Vector2 glControlPosGlobal = new Vector2((float)host.PointToScreen(new Point(0, 0)).X, (float)host.PointToScreen(new Point(0, 0)).Y);

                var delta = mousePosGlobal - glControlPosGlobal;

                delta.X = MathE.Clamp(delta.X, 0, m_control.Width);
                delta.Y = MathE.Clamp(delta.Y, 0, m_control.Height);

                ((MainWindow)Application.Current.MainWindow).Tick();

                m_editorCore.GetWorldByName("main").Input.SetMousePosition(delta);
                m_editorCore.Tick();

                if (m_control != null)
                    m_control.SwapBuffers();
            };

            m_editorCore.PropertyChanged += OnEditorPropertyChanged;
            EntityOutliner.m_world = m_editorCore.GetWorldByName("main");
        }
Exemplo n.º 12
0
        public void Run()
        {
            using (Form form = CreateForm())
            {
                var mGLControl = new GLControl
                {
                    Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
                    BackColor = Color.LightGreen,
                    Location = new Point(1, 0),
                    Name = "GL Control",
                    Size = new Size(WIDTH, HEIGHT),
                    TabIndex = 0,
                    VSync = false
                };
                form.Controls.Add(mGLControl);

                //have to set this to get a -1 to 1 system view
                GL.Viewport(0, 0, WIDTH, HEIGHT);

                if (false)//!GL.SupportsExtension("VERSION_1_5"))
                {
                    Assert.Fail("You need at least OpenGL 1.5 to run this example. Aborting.", "VBOs not supported");
                }

                var positions = new[]
                {
                    new Vector3(-1, -1, 0),
                    new Vector3(1, -1, 0),
                    new Vector3(1, 1, 0),
                    new Vector3(-1, 1, 0),
                };
                var colors = new[]
                {
                    new Vector3(1, 0, 0), new Vector3(0, 1, 0),
                    new Vector3(0, 0, 1), new Vector3(1, 1, 0)
                };

                var indices = new uint[] { 0, 1, 2, 0, 2, 3 };

                LoadBuffers(positions, indices, colors);

                Application.Idle +=
                    delegate
                    {
                        mGLControl.MakeCurrent();

                        GL.ClearColor(mGLControl.BackColor);
                        GL.Clear(ClearBufferMask.ColorBufferBit);

                        RenderFrame();

                        mGLControl.SwapBuffers();
                    };

                form.BringToFront();
                Application.Run(form);
            }
        }