Reworked viewport_render()

Rewritten logic of viewport_render(), hopefully it's now easier to figure what's going on.

Has anyone figured out, why is the hight of a single paint limited to 384? I've commented that while conditional and I haven't noticed any changes in the graphics.