/// <summary> /// Initialises OpenGL. /// </summary> protected void InitialiseOpenGL() { object parameter = null; // Native render context providers need a little bit more attention. if (RenderContextType == RenderContextType.NativeWindow) { SetStyle(ControlStyles.OptimizedDoubleBuffer, false); parameter = Handle; } // Create the render context. RenderContextType eRender = this.RenderContextType; gl.Create(ref eRender, Width, Height, 32, parameter); this.RenderContextType = eRender; // Set the most basic OpenGL styles. gl.ShadeModel(OpenGL.GL_SMOOTH); gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.ClearDepth(1.0f); gl.Enable(OpenGL.GL_DEPTH_TEST); gl.DepthFunc(OpenGL.GL_LEQUAL); gl.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST); // Fire the OpenGL initialized event. DoOpenGLInitialized(); // Set the draw timer. timerDrawing.Tick += timerDrawing_Tick; }
public OGLDevice() { InitializeComponent(); _glVersion = OpenGLVersion.OpenGL2_1; _glRenderContextType = RenderContextType.NativeWindow; ResizeRedraw = false; MinimumSize = new Size(1, 1); SetStyle(ControlStyles.DoubleBuffer, false); SetStyle(ControlStyles.OptimizedDoubleBuffer, false); // а надо ли SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.Opaque, true); SetStyle(ControlStyles.ResizeRedraw, false); _Thread = new Thread(RenderLoop); glContext = new QueueSynchronizationContext(_Thread); uiContext = SynchronizationContext.Current; // NOTE: Сделанно допущение, что объект всегда создается из потока UI HandleDestroyed += (sender, args) => { if (Closed != null) { lock (LockObj) DeviceUpdate = null; // Нет смысла вызывать обновление устройства после обратки события glContext.Send(d => Closed(sender, new OpenGLEventArgs(OpenGL)), null); } _Thread.Abort(); lock (LockObj); }; _Thread.Start(); }
public OGLViewport(OpenGLVersion version = OpenGLVersion.OpenGL2_1, RenderContextType contextType = SharpGL.RenderContextType.FBO) { OglVersion = version; RenderContextType = contextType; // Lock on OpenGL. lock (Gl) { // Create OpenGL. Gl.Create(OglVersion, RenderContextType, 1, 1, 32, null); } Gl.Enable(OpenGL.GL_DEPTH_TEST); }
public OGLViewport(OpenGLVersion version = OpenGLVersion.OpenGL2_1, RenderContextType contextType = SharpGL.RenderContextType.FBO) { OglVersion = version; RenderContextType = contextType; // Lock on OpenGL. lock (Gl) { // Create OpenGL. Gl.Create(OglVersion, RenderContextType, 1, 1, 32, null); } Gl.Enable(OpenGL.GL_DEPTH_TEST); }
/// <summary> /// Creates the OpenGL instance. /// </summary> /// <param name="openGLVersion">The OpenGL version requested.</param> /// <param name="renderContextType">Type of the render context.</param> /// <param name="width">The drawing context width.</param> /// <param name="height">The drawing context height.</param> /// <param name="bitDepth">The bit depth.</param> /// <param name="parameter">The parameter.</param> /// <returns></returns> public virtual bool Create(OpenGLVersion openGLVersion, RenderContextType renderContextType, int width, int height, int bitDepth, object parameter) { // Return if we don't have a sensible width or height. if(width == 0 || height == 0 || bitDepth == 0) return false; // TODO: [RS] I suggest to replace the switch-case statement with a RenderContextProviderFactory. // Create an instance of the render context provider. switch (renderContextType) { case RenderContextType.DIBSection: renderContextProvider = new DIBSectionRenderContextProvider(); break; case RenderContextType.NativeWindow: renderContextProvider = new NativeWindowRenderContextProvider(); break; case RenderContextType.HiddenWindow: renderContextProvider = new HiddenWindowRenderContextProvider(); break; case RenderContextType.FBO: renderContextProvider = new FBORenderContextProvider(); break; } // Create the render context. renderContextProvider.Create(openGLVersion, this, width, height, bitDepth, parameter); return true; }
/// <summary> /// Creates the OpenGL instance. /// </summary> /// <param name="renderContextType">Type of the render context.</param> /// <param name="width">The drawing context width.</param> /// <param name="height">The drawing context height.</param> /// <param name="bitDepth">The bit depth.</param> /// <param name="parameter">The parameter.</param> /// <returns></returns> public virtual bool Create(ref RenderContextType renderContextType, int width, int height, int bitDepth, object parameter) { // Return if we don't have a sensible width or height. if(width == 0 || height == 0 || bitDepth == 0) return false; try { // Create an instance of the render context provider. switch (renderContextType) { case RenderContextType.DIBSection: renderContextProvider = new DIBSectionRenderContextProvider(); break; case RenderContextType.NativeWindow: renderContextProvider = new NativeWindowRenderContextProvider(); break; case RenderContextType.HiddenWindow: renderContextProvider = new HiddenWindowRenderContextProvider(); break; case RenderContextType.FBO: renderContextProvider = new FBORenderContextProvider(); break; } // Create the render context. renderContextProvider.Create(this, width, height, bitDepth, parameter); } catch { //if FBO failed, try with DIBSection if (renderContextType==RenderContextType.FBO) { renderContextType = RenderContextType.DIBSection; renderContextProvider = null; renderContextProvider = new DIBSectionRenderContextProvider(); // Create the render context, second try renderContextProvider.Create(this, width, height, bitDepth, parameter); } } return true; }