th's picture

White window on startup, before any content appears (0.9.9-2b)


I was wondering if its possible to get rid of that white screen that shows up for about 1 second. Does anybody know how to do it or what is the cause of the problem? Any idea would be very appreciated... Thanks in advance


Comment viewing options

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

Can you please share some information about your operating system, CPU, video card and your video drivers?

A small startup delay is to be expected, while the JIT is compiling code and OpenTK is initializing OpenGL, querying available resolutions and other system information. Right now, this should be in the order of 100-500ms for debug builds of OpenTK and slightly less for release builds (expect improvements in the near future).

On top of that, applications will typically need to load some resources from disk, which takes a non-trivial amount of time. For example, I have a moderately complex application that takes about 4 seconds to load 200MB worth of (4:1 compressed) textures, compile ~20 shaders, create an amount of procedural geometry and generate a number of FBOs.

There are several ways to improve your startup times, but the first step is to time your Load method and find which parts take the most time to load (a profiler would help a lot here). Once you have this information, you can try to optimize the loading code, move it to a different thread or even defer these resources to load at a later time, allowing the application to start rendering faster, thus avoiding the 'white screen' issue. If you are still not satisfied with startup times, you will have to take more drastic measures: use the mono linker to reduce the size of your application (typical applications use only 300-500KB out of the 3.5MB OpenTK.dll), run ilmerge to merge the dlls into the exe and run ngen during deployment to precompile your application to native code (this can work wonders on startup times).

Another little trick is to place a call to GL.ClearColor(...); GL.Clear(...); SwapBuffers(); near the beginning of the Load method. This will simply change the 'white screen' to another color, which might be a better fit for your application (yes, this is a hack, but it can be less jarring for the user).

th's picture

Win 7 Pro - 64 bit
Intel Core 2 Duo 2GHz
Geforce 8400M 256MB
Vido driver version:

White screen is still showing first, before my screen content appears, although the OnLoad method is empty.

Some library, like "Tao" doesn't need this time to initialize. Why is that?

I have tried that trick with color changed, but i couldn't get it to work. Here is what i put in OnLoad method, and i tried to put it in constructor, too.
Here is the code:

GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

My app shows only two primitives...
project to download

the Fiddler's picture

I timed your project with the latest version of OpenTK and it needs 0.5-0.55 seconds to initialize (Quadro 135NVS, equivalent to your 8400, Ubuntu, Core 2 Duo 1.8GHz).

Out of those, ~0.3 seconds are spent querying OpenGL entry points (Nvidia drivers tend to be the slowest of the bunch in this part, my Ati card needs less than 0.2 seconds for this). The rest are spent in the platform abstraction layer for tasks like querying connected monitors, available resolutions, graphics modes and checking for 3.x support.

Tao.OpenGL initializes slightly faster than OpenTK.Graphics, simply because it is limited to OpenGL 2.1. OpenTK.Graphics supports OpenGL 3.2, which both ~30% larger and requires a more complex initialization path. Tao.Glfw/Tao.Sdl have roughly the same complexity as OpenTK.Platform but have the advantage of native code (which doesn't need to be JITted). Tao.Platform.Windows.SimpleOpenGlControl is a child's toy compared to GLFW/SDL or OpenTK.NativeWindow/GLControl (it doesn't even support multisampling, not to mention any kind of platform abstraction!)

Finally, you have to consider that OpenTK is more than double the size of Tao and has a much wider scope (Tao is a pure binding - OpenTK is not).

While I don't consider a 0.5 second startup time unreasonable there's certainly room left for improvement: lazy loading of entry points, simpler code for GraphicsMode queries, removal of unused code in the platform bindings (win32, xlib, etc) could bring this to under 0.3 seconds (which would match Tao). I'd suggest filing a feature request for startup time improvements, linking to this thread.