Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def render_lights_debug(self, camera_matrix, projection):
"""Render outlines of light volumes"""
self.ctx.enable(moderngl.BLEND)
self.ctx.blend_func = moderngl.SRC_ALPHA, moderngl.ONE_MINUS_SRC_ALPHA
for light in self.point_lights:
m_mv = matrix44.multiply(light.matrix, camera_matrix)
light_size = light.radius
self.debug_shader.uniform("m_proj", projection.tobytes())
self.debug_shader.uniform("m_mv", m_mv.astype('f4').tobytes())
self.debug_shader.uniform("size", light_size)
self.unit_cube.draw(self.debug_shader, mode=moderngl.LINE_STRIP)
self.ctx.disable(moderngl.BLEND)
x = np.linspace(-1.0, 1.0, 50)
y = np.random.rand(50) - 0.5
r = np.ones(50)
g = np.zeros(50)
b = np.zeros(50)
vertices = np.dstack([x, y, r, g, b])
vbo = ctx.buffer(vertices.astype('f4').tobytes())
vao = ctx.simple_vertex_array(prog, vbo, 'in_vert', 'in_color')
fbo = ctx.simple_framebuffer((512, 512))
fbo.use()
fbo.clear(0.0, 0.0, 0.0, 1.0)
vao.render(moderngl.LINE_STRIP)
Image.frombytes('RGB', fbo.size, fbo.read(), 'raw', 'RGB', 0, -1).show()
import numpy
import moderngl
from demosys import context
from demosys.opengl import types
# For sanity checking draw modes when creating the VAO
DRAW_MODES = {
moderngl.TRIANGLES: 'TRIANGLES',
moderngl.TRIANGLE_FAN: 'TRIANGLE_FAN',
moderngl.TRIANGLE_STRIP: 'TRIANGLE_STRIP',
moderngl.TRIANGLES_ADJACENCY: 'TRIANGLES_ADJACENCY',
moderngl.TRIANGLE_STRIP_ADJACENCY: 'TRIANGLE_STRIP_ADJACENCY',
moderngl.POINTS: 'POINTS',
moderngl.LINES: 'LINES',
moderngl.LINE_STRIP: 'LINE_STRIP',
moderngl.LINE_LOOP: 'LINE_LOOP',
moderngl.LINES_ADJACENCY: 'LINES_ADJACENCY',
}
class BufferInfo:
"""Container for a vbo with additional information"""
def __init__(self, buffer: moderngl.Buffer, buffer_format: str, attributes=None, per_instance=False):
"""
:param buffer: The vbo object
:param format: The format of the buffer
"""
self.buffer = buffer
self.attrib_formats = types.parse_attribute_formats(buffer_format)
self.attributes = attributes
self.per_instance = per_instance
-width, -height, -depth,
width, height, -depth,
width, -height, -depth,
-width, -height, -depth,
width, height, -depth,
-width, -height, -depth,
-width, height, -depth,
width, height, -depth,
-width, height, -depth,
width, height, depth,
-width, height, -depth,
-width, height, depth,
width, height, depth,
], dtype=numpy.float32)
vao = VAO(name or "geometry:cube", mode=moderngl.LINE_STRIP)
vao.buffer(pos, '3f', [attr_names.POSITION])
return vao
import numpy
import moderngl
import moderngl_window as mglw
from moderngl_window.opengl import types
# For sanity checking draw modes when creating the VAO
DRAW_MODES = {
moderngl.TRIANGLES: 'TRIANGLES',
moderngl.TRIANGLE_FAN: 'TRIANGLE_FAN',
moderngl.TRIANGLE_STRIP: 'TRIANGLE_STRIP',
moderngl.TRIANGLES_ADJACENCY: 'TRIANGLES_ADJACENCY',
moderngl.TRIANGLE_STRIP_ADJACENCY: 'TRIANGLE_STRIP_ADJACENCY',
moderngl.POINTS: 'POINTS',
moderngl.LINES: 'LINES',
moderngl.LINE_STRIP: 'LINE_STRIP',
moderngl.LINE_LOOP: 'LINE_LOOP',
moderngl.LINES_ADJACENCY: 'LINES_ADJACENCY',
}
class BufferInfo:
"""Container for a vbo with additional information"""
def __init__(self, buffer: moderngl.Buffer, buffer_format: str, attributes=None, per_instance=False):
"""
:param buffer: The vbo object
:param format: The format of the buffer
"""
self.buffer = buffer
self.attrib_formats = types.parse_attribute_formats(buffer_format)
self.attributes = attributes
self.per_instance = per_instance
-width, -height, -depth,
width, height, -depth,
width, -height, -depth,
-width, -height, -depth,
width, height, -depth,
-width, -height, -depth,
-width, height, -depth,
width, height, -depth,
-width, height, -depth,
width, height, depth,
-width, height, -depth,
-width, height, depth,
width, height, depth,
], dtype=numpy.float32)
vao = VAO("geometry:cube", mode=moderngl.LINE_STRIP)
vao.buffer(pos, '3f', ["in_position"])
return vao
def render_lights_debug(self, camera_matrix, projection):
"""Render outlines of light volumes"""
self.ctx.enable(moderngl.BLEND)
self.ctx.blend_func = moderngl.SRC_ALPHA, moderngl.ONE_MINUS_SRC_ALPHA
for light in self.point_lights:
m_mv = matrix44.multiply(light.matrix, camera_matrix)
light_size = light.radius
self.debug_shader["m_proj"].write(projection.tobytes())
self.debug_shader["m_mv"].write(m_mv.astype('f4').tobytes())
self.debug_shader["size"].value = light_size
self.unit_cube.render(self.debug_shader, mode=moderngl.LINE_STRIP)
self.ctx.disable(moderngl.BLEND)