Properly restore all the OpenGL states properly and added a sanity check.

Also set the proper viewport value at startup.
Merge pull request #27 from Orphis/viewportfix

Properly restore all the OpenGL states properly and added a sanity check