Moved a few gl calls out of main loop