Wood36's picture

Building a Windows.Forms + GLControl based application

hi,

This tutorial assumes familiarity with Windows.Forms application development in Visual Studio 2005/C#, and at least basic knowledge of OpenGL. It also assumes a top-to-bottom readthrough; it is a guide and not a reference.

To begin with, it is quite a different approach one has to take when designing a game/application using the GLControl in a Windows.Form compared to using the GameWindow. GLControl is more low-level than GameWindow so you'll have to pull the strings on for example time measurements by yourself. In GameWindow, you get more for free!

Just as in the GameWindow case, GLControl uses the default OpenGL driver of the system, so with the right drivers installed it will be hardware accelerated. However, with large windows it will be slower than the corresponding fullscreen GameWindow, because of how the underlying windowing system works [someone with more detailed knowledge than me may want to elaborate on this..].

If you come from a "main-loop-background" (C/SDL/Allegro etc.) when it comes to coding games, you'll have to rethink that fundamentally. You'll have to change into a mindset of "what event should I hook into, and what events should I trigger, and when?" instead.

___________________
pregnancy yoga classes online


Comments

Comment viewing options

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

Tips for getting the GLControlSimple example to work as an independent project:

  1. If the parent form resizes and the GLControl doesn't and the resize callback doesn't even get fired, check to see that the GLControl's Dock property is set to Fill like it is in the example project.
  2. If the buttons don't position themselves the way they do in the example after a parent form resize, make sure you change each of the buttons' Anchor properties to Top-Right, the way it is in the example project.
  3. If your KeyDown handler for the GLControl doesn't do what you think it should, that could be because the button you just clicked still has focus. Click somewhere in the GLControl to establish focus there, and then hit your key. (Note that the example program has the same problem.) This problem can be taken care of by adding code to your handlers that addresses focus.

I had a devil of a time resolving these problems until I took the time to compare properties of the controls between my project and the example project. I hope recording my finds here will help out some other poor lost soul in the future.

Walt

kanato's picture

You can solve #3 by setting the Form's KeyPreview property to true, then all key events will go through the Form's KeyDown etc. events and you don't have to worry about which control has focus.