Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changing line width #244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pyrender/offscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class OffscreenRenderer(object):
The size of screen-space points in pixels.
"""

def __init__(self, viewport_width, viewport_height, point_size=1.0):
def __init__(self, viewport_width, viewport_height, point_size=1.0, line_width=1.0):
self.viewport_width = viewport_width
self.viewport_height = viewport_height
self.point_size = point_size
self.line_width = line_width

self._platform = None
self._renderer = None
Expand Down Expand Up @@ -148,7 +149,7 @@ def _create(self):
))
self._platform.init_context()
self._platform.make_current()
self._renderer = Renderer(self.viewport_width, self.viewport_height)
self._renderer = Renderer(self.viewport_width, self.viewport_height, self.point_size, self.line_width)

def __del__(self):
try:
Expand Down
9 changes: 8 additions & 1 deletion pyrender/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Renderer(object):
Size of points in pixels. Defaults to 1.0.
"""

def __init__(self, viewport_width, viewport_height, point_size=1.0):
def __init__(self, viewport_width, viewport_height, point_size=1.0, line_width=1.0):
self.dpscale = 1
# Scaling needed on retina displays
if sys.platform == 'darwin':
Expand All @@ -46,6 +46,7 @@ def __init__(self, viewport_width, viewport_height, point_size=1.0):
self.viewport_width = viewport_width
self.viewport_height = viewport_height
self.point_size = point_size
self.line_width = line_width

# Optional framebuffer for offscreen renders
self._main_fb = None
Expand Down Expand Up @@ -599,6 +600,12 @@ def _bind_and_draw_primitive(self, primitive, pose, program, flags):
if primitive.mode == GLTF.POINTS:
glEnable(GL_PROGRAM_POINT_SIZE)
glPointSize(self.point_size)

# Set line width if needed
glDisable(GL_LINE_SMOOTH)
if primitive.mode == GLTF.LINES or primitive.mode == GLTF.LINE_LOOP or primitive.mode == GLTF.LINE_STRIP:
glEnable(GL_LINE_SMOOTH)
glLineWidth(self.line_width)

# Render mesh
n_instances = 1
Expand Down