enablerbr's picture

WindowsForm Appliction and GLControl questions.

1: what should i be aware of when creating a New WindowsForm Appliction as a startup project and then dropping a GLControl onto the Form Designer?

2: Are there any modifictions i should do to the project, codewise, before i start my own coding?

3: Are there any limits or pitfalls regarding dropping a GLControl onto the Form Designer?

4: Does OpenTK support 64bit usage?

5: If i convert NeHe lessons over to OpenTK is there any tips that might come in handy?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

1 and 2 - nothing comes to mind.

3 - yes. Some functionality is only available if you derive from GLControl. This includes support for OpenGL 3.0, custom pixel formats and the RecreateHandle() method (which can be useful in some uncommon scenarios).

4 - absolutely.

5 - there's no need to p/invoke platform-specific functions. OpenTK hides all platform-specific functionality behind cross-platform interfaces: DisplayResolution, GraphicsMode and GraphicsContext. These provide everything you need to emulate NeHe, like setting a display mode, selecting a pixel format and creating the OpenGL context (the latter is handled automatically by GLControl).


  • As long as you avoid platform-specific code, you'll be able to copy & paste your project on MacOS or Linux and it will work out of the box (you won't even need to recompile).
  • Add "OpenTK.dll.config" to your project and set it to be copied to the output directory (necessary for cross-platform support).
  • Use the settings designer in Visual Studio to create application settings. You can create a settings GUI trivially by using a PropertyGrid and binding it to the Settings class.
enablerbr's picture

so no way round 3 for accessing OpenGL 3.0, custom pixel formats? so as i want those i'll have to code the GLControl by hand. if i code the GLContorl by hand will that mean i can't drop other windows controls (like buttons, file menus) onto the windows Form Designer?

the Fiddler's picture

No, it's nothing like that. You simply create a new class:

class CustomGLControl : GLControl
    // Request an OpenGL 3.0 context.
    public CustomGLControl()
        : base(GraphicsMode.Default, 3, 0, GraphicsContextFlags.Default)
    { }

Compile the project and this new class will appear in your toolbox - simply drag & drop it instead of a vanilla GLControl.

Edit: the reason for this is that the WinForms designer only uses parameterless constructors. The necessary functionality exists in GLControl, but you can only access it through code, not the designer.

enablerbr's picture

hmm.. must be doing something wrong. did as you said. however there is no CustomGLControl in my toolbox.

the Fiddler's picture

Hm, maybe it needs to be public (rebuild the project afterwards). If it still doesn't appear, right click on the toolbox, select "choose items" and enable the new control there.

enablerbr's picture

was public and it doesn't appear in the "choose items". only the normal GLControl is listed.

Problem solved.

i had to go into Tools> options> Windows Forms Designer> General. under Toolbox turn Auto ToolboxPopulate to true. then CustomGLControl appeared in Toolbox. now i feel like a newbie. :)

i even managed to convert the OpenTk Simple GLControl example as well. after i worked out i needed to change the anchor settings.