Example #1
0
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or
        /// internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>.
        /// </summary>
        public override void OnApplyTemplate()
        {
            //  Call the base.
            base.OnApplyTemplate();

            object windowHandle = null;

            //  Pass handle to window if RenderContextType is NativeWindow (better performance)
            if (this.RenderContextType == SharpGL.RenderContextType.NativeWindow)
            {
                windowHandle = ((HwndSource)HwndSource.FromVisual(this)).Handle;
            }

            //  Lock on OpenGL.
            lock (gl)
            {
                //  Create OpenGL.
                gl.Create(OpenGLVersion, RenderContextType, 1, 1, 32, windowHandle);

                // JWH - FOR NEW RENDER METHOD
                // Force re-set of dpi and format settings
                m_dpiX = 0;
            }
            //  Create our fast event args.
            eventArgsFast = new OpenGLEventArgs(gl);

            //  Set the most basic OpenGL styles.
            gl.ShadeModel(OpenGL.GL_SMOOTH);
            gl.ThrowIfErrors();
            gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            gl.ThrowIfErrors();
            gl.ClearDepth(1.0);
            gl.ThrowIfErrors();
            gl.Enable(OpenGL.GL_DEPTH_TEST);
            gl.ThrowIfErrors();
            gl.DepthFunc(OpenGL.GL_LEQUAL);
            gl.ThrowIfErrors();
            gl.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);
            gl.ThrowIfErrors();

            //  Fire the OpenGL initialised event.
            OpenGLInitialized?.Invoke(this, eventArgsFast);

            timer.Interval = new TimeSpan(0, 0, 0, 0, (int)(1000.0 / FrameRate));
        }
Example #2
0
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or
        /// internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>.
        /// </summary>
        public override void OnApplyTemplate()
        {
            //  Call the base.
            base.OnApplyTemplate();

            // initialize framebufferhandler for OpeTK
            mLoaded        = false;
            mSize          = Size.Empty;
            mFramebufferId = -1;

            var gmode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 4, 0, 2, false);

            mTkGlControl = new GLControl(gmode, VersionMajor, VersionMinor, GraphicsContextFlags.Default);
            mTkGlControl.MakeCurrent();

            //  Fire the OpenGL initialised event.
            OpenGLInitialized?.Invoke(this, EventArgs.Empty);
        }
Example #3
0
 /// <summary>
 /// Calls the OpenGL initialized function.
 /// </summary>
 protected virtual void DoOpenGLInitialized()
 {
     OpenGLInitialized?.Invoke(this, null);
 }