Some changes to reduce tearing and flickering.

- move calculation of next frame before wait for next frame
- add options in UI to turn off UI output windows