本文整理匯總了Python中pyglet.graphics方法的典型用法代碼示例。如果您正苦於以下問題:Python pyglet.graphics方法的具體用法?Python pyglet.graphics怎麽用?Python pyglet.graphics使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyglet
的用法示例。
在下文中一共展示了pyglet.graphics方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def __init__(self):
"""Create a graphics batch."""
# Mapping to find domain.
# group -> (attributes, mode, indexed) -> domain
self.group_map = {}
# Mapping of group to list of children.
self.group_children = {}
# List of top-level groups
self.top_groups = []
self._draw_list = []
self._draw_list_dirty = False
# Each Batch encompasses one VAO
self.vao = VertexArray()
if _debug_graphics_batch:
print("Batch created. VAO ID: {0}".format(self.vao.id))
示例2: __init__
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def __init__(self, blend_src, blend_dest, parent=None):
"""Create a Shape group.
The group is created internally. Usually you do not
need to explicitly create it.
:Parameters:
`blend_src` : int
OpenGL blend source mode; for example,
``GL_SRC_ALPHA``.
`blend_dest` : int
OpenGL blend destination mode; for example,
``GL_ONE_MINUS_SRC_ALPHA``.
`parent` : `~pyglet.graphics.Group`
Optional parent group.
"""
super().__init__(_default_program, parent=parent)
self.blend_src = blend_src
self.blend_dest = blend_dest
示例3: _create_vertex_list
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def _create_vertex_list(self):
if self._batch is None:
self._vertex_list = graphics.vertex_list(4,
'v2i/%s' % self._usage,
'c4B', ('t3f', self._texture.tex_coords))
else:
self._vertex_list = self._batch.add(4, GL_QUADS, self._group,
'v2i/%s' % self._usage,
'c4B', ('t3f', self._texture.tex_coords))
self._update_position()
self._update_color()
示例4: __init__
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def __init__(self):
'''Create a graphics batch.'''
# Mapping to find domain.
# group -> (attributes, mode, indexed) -> domain
self.group_map = {}
# Mapping of group to list of children.
self.group_children = {}
# List of top-level groups
self.top_groups = []
self._draw_list = []
self._draw_list_dirty = False
示例5: draw_lane_surface
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def draw_lane_surface(self, lane):
gl.glColor3f(0.4, 0.4, 0.4)
W = 1000
graphics.draw(4, gl.GL_QUAD_STRIP, ('v2f',
np.hstack([lane.p - lane.m * W - 0.5 * lane.w * lane.n,
lane.p - lane.m * W + 0.5 * lane.w * lane.n,
lane.q + lane.m * W - 0.5 * lane.w * lane.n,
lane.q + lane.m * W + 0.5 * lane.w * lane.n])
))
示例6: draw_lane_lines
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def draw_lane_lines(self, lane):
gl.glColor3f(1., 1., 1.)
W = 1000
graphics.draw(4, gl.GL_LINES, ('v2f',
np.hstack([lane.p - lane.m * W - 0.5 * lane.w * lane.n,
lane.p + lane.m * W - 0.5 * lane.w * lane.n,
lane.p - lane.m * W + 0.5 * lane.w * lane.n,
lane.p + lane.m * W + 0.5 * lane.w * lane.n])
))
示例7: on_draw
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def on_draw(self):
self.window.clear()
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glPushMatrix()
gl.glLoadIdentity()
self.camera()
gl.glEnable(self.background.target)
gl.glEnable(gl.GL_BLEND)
gl.glBindTexture(self.background.target, self.background.id)
W = 10000.
graphics.draw(4, gl.GL_QUADS,
('v2f', (-W, -W, W, -W, W, W, -W, W)),
('t2f', (0., 0., W * 5., 0., W * 5., W * 5., 0., W * 5.))
)
gl.glDisable(self.background.target)
for lane in self.world.lanes:
self.draw_lane_surface(lane)
self.draw_lane_lines(lane)
for obj in self.world.objects:
self.draw_object(obj)
for car in self.world.cars:
self.draw_car(car.trajectory[-1], car.color)
gl.glPopMatrix()
self.label.text = self.task_name
self.label.draw()
self.iter +=1
if self.iter%10 == 0:
print('Iterations: ', self.iter)
if self.iter == self.max_iters:
self.event_loop.exit()
示例8: __init__
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def __init__(self, texture, blend_src, blend_dest, program=None, order=0, parent=None):
"""Create a sprite group.
The group is created internally when a :py:class:`~pyglet.sprite.Sprite`
is created; applications usually do not need to explicitly create it.
:Parameters:
`texture` : `~pyglet.image.Texture`
The (top-level) texture containing the sprite image.
`blend_src` : int
OpenGL blend source mode; for example,
``GL_SRC_ALPHA``.
`blend_dest` : int
OpenGL blend destination mode; for example,
``GL_ONE_MINUS_SRC_ALPHA``.
`program` : `~pyglet.graphics.shader.ShaderProgram`
A custom ShaderProgram.
`order` : int
Change the order to render above or below other Groups.
`parent` : `~pyglet.graphics.Group`
Optional parent group.
"""
super().__init__(order, parent)
self.texture = texture
self.blend_src = blend_src
self.blend_dest = blend_dest
self.program = program or _default_program
示例9: batch
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def batch(self):
"""Graphics batch.
The sprite can be migrated from one batch to another, or removed from
its batch (for individual drawing). Note that this can be an expensive
operation.
:type: :py:class:`pyglet.graphics.Batch`
"""
return self._batch
示例10: group
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def group(self):
"""Parent graphics group.
The sprite can change its rendering group, however this can be an
expensive operation.
:type: :py:class:`pyglet.graphics.Group`
"""
return self._group.parent
示例11: _nearest_pow2
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def _nearest_pow2(v):
# From http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
# Credit: Sean Anderson
v -= 1
v |= v >> 1
v |= v >> 2
v |= v >> 4
v |= v >> 8
v |= v >> 16
return v + 1
示例12: create_domain
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def create_domain(shader_program_id, *attribute_usage_formats):
"""Create a vertex domain covering the given attribute usage formats.
See documentation for :py:func:`create_attribute_usage` and
:py:func:`pyglet.graphics.vertexattribute.create_attribute` for the grammar
of these format strings.
:rtype: :py:class:`VertexDomain`
"""
attribute_usages = [create_attribute_usage(shader_program_id, f)
for f in attribute_usage_formats]
return VertexDomain(attribute_usages)
示例13: create_indexed_domain
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def create_indexed_domain(shader_program_id, *attribute_usage_formats):
"""Create an indexed vertex domain covering the given attribute usage
formats. See documentation for :py:class:`create_attribute_usage` and
:py:func:`pyglet.graphics.vertexattribute.create_attribute` for the grammar
of these format strings.
:rtype: :py:class:`VertexDomain`
"""
attribute_usages = [create_attribute_usage(shader_program_id, f)
for f in attribute_usage_formats]
return IndexedVertexDomain(attribute_usages)
示例14: draw
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def draw(self, mode):
"""Draw this vertex list in the given OpenGL mode.
:Parameters:
`mode` : int
OpenGL drawing mode, e.g. ``GL_POINTS``, ``GL_LINES``, etc.
"""
with pyglet.graphics.get_default_batch().vao:
pyglet.graphics.get_default_group().set_state()
self.domain.draw_subset(mode, self)
pyglet.graphics.get_default_group().unset_state()
示例15: vertex_list
# 需要導入模塊: import pyglet [as 別名]
# 或者: from pyglet import graphics [as 別名]
def vertex_list(count, *data):
"""Create a :py:class:`~pyglet.graphics.vertexdomain.VertexList` not associated with a batch, group or mode.
:Parameters:
`count` : int
The number of vertices in the list.
`data` : data items
Attribute formats and initial data for the vertex list. See the
module summary for details.
:rtype: :py:class:`~pyglet.graphics.vertexdomain.VertexList`
"""
# Note that mode=0 because the default batch is never drawn: vertex lists
# returned from this function are drawn directly by their draw() method.
return get_default_batch().add(count, 0, None, *data)