Ejemplo n.º 1
0
        public void OnRender(OpenTkControlBase.GlRenderEventArgs e)
        {
            if (Errored)
            {
                return;
            }
            try
            {
                if (!loaded)
                {
                    InitProgram();
                    loaded = true;
                }
                if (e.Resized)
                {
                    w = e.Width;
                    h = e.Height;
                }
                UpdateFrame();

                GL.Viewport(0, 0, w, h);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                GL.Enable(EnableCap.DepthTest);
                foreach (var shader in shaders)
                {
                    RenderShader(shader.Key, shader.Value);
                }
                GL.Flush();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
Ejemplo n.º 2
0
        private void RenderCallback(object?sender, OpenTkControlBase.GlRenderEventArgs e)
        {
            if (!initialized)
            {
                Initialize();
            }

            if (e.Resized)
            {
                GL.Viewport(0, 0, (int)control.ActualWidth, (int)control.ActualHeight);
            }

            deltaTimeStopwatch.Stop();
            float deltaTime = deltaTimeStopwatch.ElapsedMilliseconds / 1000f;

            deltaTimeStopwatch.Reset();
            deltaTimeStopwatch.Start();

            Render(deltaTime);
        }
Ejemplo n.º 3
0
        private void OpenTkControl_OnGlRender(object sender, OpenTkControlBase.GlRenderEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            float halfWidth  = e.Width / 2f;
            float halfHeight = e.Height / 2f;

            GL.Ortho(-halfWidth, halfWidth, -halfHeight, halfHeight, 1000, -1000);
            GL.Viewport(0, 0, e.Width, e.Height);

            //Using the same example as used by https://github.com/freakinpenguin/OpenTK-WPF
            //to make it easier to compare different approaches
            if (_displayList <= 0 || e.NewContext)
            {
                _displayList = GL.GenLists(1);
                GL.NewList(_displayList, ListMode.Compile);

                GL.Color3(Color.Red);

                GL.Begin(PrimitiveType.Points);

                Random rnd = new Random();
                for (int i = 0; i < 1000000; i++)
                {
                    float   factor   = 0.2f;
                    Vector3 position = new Vector3(
                        rnd.Next(-1000, 1000) * factor,
                        rnd.Next(-1000, 1000) * factor,
                        rnd.Next(-1000, 1000) * factor);
                    GL.Vertex3(position);

                    position.Normalize();
                    GL.Normal3(position);
                }

                GL.End();

                GL.EndList();
            }

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

            GL.ClearColor(Color.FromArgb(200, Color.LightBlue));
            GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            _angle += 1f;
            GL.Rotate(_angle, Vector3.UnitZ);
            GL.Rotate(_angle, Vector3.UnitY);
            GL.Rotate(_angle, Vector3.UnitX);
            GL.Translate(0.5f, 0, 0);

            GL.CallList(_displayList);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            GL.Begin(PrimitiveType.Triangles);

            GL.Color4(Color.Green);
            GL.Vertex3(0, 300, 0);
            GL.Vertex3(0, 0, 0);
            GL.Vertex3(300, 0, 0);

            GL.End();

            Interlocked.Increment(ref _fps);
        }