Refactor setting of viewport and rendering of triangles