nythrix's picture

[Solved] GameWindow size [0;0] until shown

Hi,
I was wondering. What goes on with the size properties of the window until it is shown? I mean Width and Height return 0 unless the window is visible AFAICT. I'm curious about the logic behind it. Because this code

window = new GameWindow( 640, 480 )
engine = new Engine( window );

blows up since the engine expects the window to have a size of a sort. Surprisingly what you see is not what you get. Hooking Load didn't work either. So when is GameWindow completely ready (including GL context)?
On Resize?

Many thanks.


Comments

Comment viewing options

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

Now that I think of it, it does make sense in the GUI world. However it's very weird from a general standpoint. Visibility shouldn't affect other properties IMHO.

the Fiddler's picture

I think this should be fixed in trunk (which will become OpenTK 0.9.9 as soon as I manage to get svn merge to work - trying for 3 days now and it's still failing).

There are two issues here:

  • Size should be set to the correct value as soon as the window is created (i.e. in the constructor).
  • A Resize event should be generated - the question is when. This is more difficult than it sounds, because raising the event from the constructor can be dangerous.

The current implementation binds the Size property with the Resize event. The Size property is updated whenever a Resize event is generated and the first Resize event is only generated when you call the Run() method.

The new implementation (in trunk) does an additional step and sets the size during window creation. This means Size should return the correct value at all times.

nythrix's picture

The new implementation (in trunk) does an additional step and sets the size during window creation. This means Size should return the correct value at all times.
Thanks. I was afraid this is caused by underlying APIs and whatnots. I've never been a friend of GUIs. Sometimes I find them more challenging than 3D.

It's good to hear 0.9.9 is coming out. Great job!

the Fiddler's picture

0.9.9 is now out for testing. Word of warning: this is purely for testing purposes, so backup your project first! (or put it in version control)

The stable branch is 0.9.8-1, which is also released.

Edit: If OpenTK 0.9.9 still suffers from this issue, please create an issue report.

nythrix's picture

Edit: If OpenTK 0.9.9 still suffers from this issue, please create an issue report.
[0.9.9.0] fixed.
[0.9.8.1] still suffers from it.

the Fiddler's picture

Right, thanks for testing.

0.9.9 comes with some very extensive changes to the GameWindow implementation, which cannot be backported to 0.9.8. If you haven't noticed any abnormal behavior in 0.9.9, it should be safe to stay with that (if you can suffer through the 'obsolete' warnings for keyboard/mouse, that is).