OpenTK.GLControl Class Reference

Defines a UserControl with OpenGL rendering capabilities. More...

List of all members.

Public Member Functions

 GLControl ()
 Constructs a new GLControl.
 GLControl (GraphicsMode mode)
 Constructs a new GLControl with the specified GraphicsMode.
 GLControl (GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
 Constructs a new GLControl with the specified GraphicsMode.
void SwapBuffers ()
 Swaps the front and back buffers, presenting the rendered scene to the screen.
void MakeCurrent ()
 Makes the underlying this GLControl current in the calling thread. All OpenGL commands issued are hereafter interpreted by this GLControl.
Bitmap GrabScreenshot ()
 Grabs a screenshot of the frontbuffer contents.

Protected Member Functions

override void OnHandleCreated (EventArgs e)
 Raises the HandleCreated event.
override void OnHandleDestroyed (EventArgs e)
 Raises the HandleDestroyed event.
override void OnPaint (PaintEventArgs e)
 Raises the System.Windows.Forms.Control.Paint event.
override void OnResize (EventArgs e)
 Raises the Resize event. Note: this method may be called before the OpenGL context is ready. Check that IsHandleCreated is true before using any OpenGL methods.
override void OnParentChanged (EventArgs e)
 Raises the ParentChanged event.

Properties

bool IsIdle [get]
 Gets a value indicating whether the current thread contains pending system messages.
IGraphicsContext Context [get, set]
 Gets an interface to the underlying GraphicsContext used by this GLControl.
float AspectRatio [get]
 Gets the aspect ratio of this GLControl.
bool VSync [get, set]
 Gets or sets a value indicating whether vsync is active for this GLControl.
GraphicsMode GraphicsMode [get]
 Gets the GraphicsMode of the GraphicsContext attached to this GLControl.
IWindowInfo WindowInfo [get]
 Gets the OpenTK.Platform.IWindowInfo for this instance.

Detailed Description

Defines a UserControl with OpenGL rendering capabilities.

Definition at line 46 of file GLControl.cs.


Constructor & Destructor Documentation

OpenTK.GLControl.GLControl (  ) 

Constructs a new GLControl.

Definition at line 65 of file GLControl.cs.

00066             : this(GraphicsMode.Default)
00067         { }

OpenTK.GLControl.GLControl ( GraphicsMode  mode  ) 

Constructs a new GLControl with the specified GraphicsMode.

Parameters:
mode The OpenTK.Graphics.GraphicsMode of the control.

Definition at line 73 of file GLControl.cs.

00074             : this(mode, 1, 0, GraphicsContextFlags.Default)
00075         { }

OpenTK.GLControl.GLControl ( GraphicsMode  mode,
int  major,
int  minor,
GraphicsContextFlags  flags 
)

Constructs a new GLControl with the specified GraphicsMode.

Parameters:
mode The OpenTK.Graphics.GraphicsMode of the control.
major The major version for the OpenGL GraphicsContext.
minor The minor version for the OpenGL GraphicsContext.
flags The GraphicsContextFlags for the OpenGL GraphicsContext.

Definition at line 84 of file GLControl.cs.

00085         {
00086             if (mode == null)
00087                 throw new ArgumentNullException("mode");
00088             
00089             SetStyle(ControlStyles.Opaque, true);
00090             SetStyle(ControlStyles.UserPaint, true);
00091             SetStyle(ControlStyles.AllPaintingInWmPaint, true);
00092             DoubleBuffered = false;
00093 
00094             this.format = mode;
00095             this.major = major;
00096             this.minor = minor;
00097             this.flags = flags;
00098 
00099             InitializeComponent();
00100         }


Member Function Documentation

Bitmap OpenTK.GLControl.GrabScreenshot (  ) 

Grabs a screenshot of the frontbuffer contents.

Returns:
A System.Drawing.Bitmap, containing the contents of the frontbuffer.
Exceptions:
OpenTK.Graphics.GraphicsContextException Occurs when no OpenTK.Graphics.GraphicsContext is current in the calling thread.

Definition at line 392 of file GLControl.cs.

00393         {
00394             ValidateState();
00395 
00396             Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
00397             System.Drawing.Imaging.BitmapData data =
00398                 bmp.LockBits(this.ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly,
00399                              System.Drawing.Imaging.PixelFormat.Format24bppRgb);
00400             GL.ReadPixels(0, 0, this.ClientSize.Width, this.ClientSize.Height, PixelFormat.Bgr, PixelType.UnsignedByte,
00401                           data.Scan0);
00402             bmp.UnlockBits(data);
00403             bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
00404             return bmp;
00405         }

void OpenTK.GLControl.MakeCurrent (  ) 

Makes the underlying this GLControl current in the calling thread. All OpenGL commands issued are hereafter interpreted by this GLControl.

Definition at line 258 of file GLControl.cs.

00259         {
00260             ValidateState();
00261             Context.MakeCurrent(Implementation.WindowInfo);
00262         }

override void OpenTK.GLControl.OnHandleCreated ( EventArgs  e  )  [protected]

Raises the HandleCreated event.

Parameters:
e Not used.

Definition at line 134 of file GLControl.cs.

00135         {
00136             if (context != null)
00137                 context.Dispose();
00138 
00139             if (implementation != null)
00140                 implementation.WindowInfo.Dispose();
00141 
00142             if (DesignMode)
00143                 implementation = new DummyGLControl();
00144             else
00145                 implementation = new GLControlFactory().CreateGLControl(format, this);
00146 
00147             context = implementation.CreateContext(major, minor, flags);
00148             MakeCurrent();
00149 
00150             if (!DesignMode)
00151                 ((IGraphicsContextInternal)Context).LoadAll();
00152 
00153             // Deferred setting of vsync mode. See VSync property for more information.
00154             if (initial_vsync_value.HasValue)
00155             {
00156                 Context.VSync = initial_vsync_value.Value;
00157                 initial_vsync_value = null;
00158             }
00159 
00160             base.OnHandleCreated(e);
00161 
00162             if (resize_event_suppressed)
00163             {
00164                 OnResize(EventArgs.Empty);
00165                 resize_event_suppressed = false;
00166             }
00167         }

override void OpenTK.GLControl.OnHandleDestroyed ( EventArgs  e  )  [protected]

Raises the HandleDestroyed event.

Parameters:
e Not used.

Definition at line 171 of file GLControl.cs.

00172         {
00173             if (context != null)
00174             {
00175                 context.Dispose();
00176                 context = null;
00177             }
00178 
00179             if (implementation != null)
00180             {
00181                 implementation.WindowInfo.Dispose();
00182                 implementation = null;
00183             }
00184 
00185             base.OnHandleDestroyed(e);
00186         }

override void OpenTK.GLControl.OnPaint ( PaintEventArgs  e  )  [protected]

Raises the System.Windows.Forms.Control.Paint event.

Parameters:
e A System.Windows.Forms.PaintEventArgs that contains the event data.

Definition at line 192 of file GLControl.cs.

00193         {
00194             ValidateState();
00195 
00196             if (DesignMode)
00197                 e.Graphics.Clear(BackColor);
00198 
00199             base.OnPaint(e);
00200         }

override void OpenTK.GLControl.OnParentChanged ( EventArgs  e  )  [protected]

Raises the ParentChanged event.

Parameters:
e A System.EventArgs that contains the event data.

Definition at line 227 of file GLControl.cs.

00228         {
00229             if (context != null)
00230                 context.Update(Implementation.WindowInfo);
00231 
00232             base.OnParentChanged(e);
00233         }

override void OpenTK.GLControl.OnResize ( EventArgs  e  )  [protected]

Raises the Resize event. Note: this method may be called before the OpenGL context is ready. Check that IsHandleCreated is true before using any OpenGL methods.

Parameters:
e A System.EventArgs that contains the event data.

Definition at line 208 of file GLControl.cs.

00209         {
00210             // Do not raise OnResize event before the handle and context are created.
00211             if (!IsHandleCreated)
00212             {
00213                 resize_event_suppressed = true;
00214                 return;
00215             }
00216 
00217             if (context != null)
00218                 context.Update(Implementation.WindowInfo);
00219 
00220             base.OnResize(e);
00221         }

void OpenTK.GLControl.SwapBuffers (  ) 

Swaps the front and back buffers, presenting the rendered scene to the screen.

Definition at line 244 of file GLControl.cs.

00245         {
00246             ValidateState();
00247             Context.SwapBuffers();
00248         }


Property Documentation

float OpenTK.GLControl.AspectRatio [get]

Gets the aspect ratio of this GLControl.

Definition at line 308 of file GLControl.cs.

IGraphicsContext OpenTK.GLControl.Context [get, set]

Gets an interface to the underlying GraphicsContext used by this GLControl.

Definition at line 290 of file GLControl.cs.

GraphicsMode OpenTK.GLControl.GraphicsMode [get]

Gets the GraphicsMode of the GraphicsContext attached to this GLControl.

To change the GraphicsMode, you must destroy and recreate the GLControl.

Definition at line 362 of file GLControl.cs.

bool OpenTK.GLControl.IsIdle [get]

Gets a value indicating whether the current thread contains pending system messages.

Definition at line 273 of file GLControl.cs.

bool OpenTK.GLControl.VSync [get, set]

Gets or sets a value indicating whether vsync is active for this GLControl.

Definition at line 325 of file GLControl.cs.

IWindowInfo OpenTK.GLControl.WindowInfo [get]

Gets the OpenTK.Platform.IWindowInfo for this instance.

Definition at line 378 of file GLControl.cs.

 All Classes Functions Variables Enumerations Properties Events

Generated on Tue Mar 9 14:59:19 2010 for The Open Toolkit library by  doxygen 1.6.1