Yeah, you have to reverse the order of the vertices, like so:
surface.setVertices(OpenStudio::reverse(surface.vertices))