Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoran56 committed Mar 24, 2023
2 parents 72c273a + 04626fa commit 676c3be
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 48 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![pypi](https://badge.fury.io/py/pyglet.svg)](https://pypi.python.org/pypi/pyglet) [![rtd](https://readthedocs.org/projects/pyglet/badge/?version=latest)](https://pyglet.readthedocs.io) [![PyTest](https://github.com/pyglet/pyglet/actions/workflows/unittests.yml/badge.svg)](https://github.com/pyglet/pyglet/actions/workflows/unittests.yml)

![logo_large.png](https://bitbucket.org/repo/aejyXX/images/3385888514-logo_large.png)
![logo_large.png](https://github.com/pyglet/pyglet/blob/54a8c8b7e701b1692c6a10dd80f94ec837c27bd3/examples/opengl/pyglet.png)

# pyglet

Expand Down Expand Up @@ -101,7 +101,7 @@ it is a sign that the docs should be improved.
If you want to contribute to pyglet, we suggest the following:

* Fork the [official repository](https://github.com/pyglet/pyglet/fork).
* Checkout the branch you wish to contribute to (such as *pyglet-1.4-maintenance*).
* Checkout the branch you wish to contribute to (such as *pyglet-1.5-maintenance*).
* Apply your changes to your fork.
* Submit a [pull request](https://github.com/pyglet/pyglet/pulls) describing the changes you have made.
* Alternatively you can create a patch and submit it to the issue tracker.
Expand Down
6 changes: 3 additions & 3 deletions examples/sprite/multi_texture_sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MultiTextureSpriteGroup(pyglet.sprite.SpriteGroup):
"""A sprite group that uses multiple active textures.
"""

def __init__(self, textures, blend_src, blend_dest, program=None, order=0, parent=None):
def __init__(self, textures, blend_src, blend_dest, program=None, parent=None):
"""Create a sprite group for multiple textures and samplers.
All textures must share the same target type.
Expand All @@ -82,7 +82,7 @@ def __init__(self, textures, blend_src, blend_dest, program=None, order=0, paren
self.textures = textures
texture = list(self.textures.values())[0]
self.target = texture.target
super().__init__(texture, blend_src, blend_dest, program, order, parent)
super().__init__(texture, blend_src, blend_dest, program, parent)

def set_state(self):
self.program.use()
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(self,
self._texture = list(textures.values())[0]

self._batch = batch or graphics.get_default_batch()
self._group = self.group_class(textures, blend_src, blend_dest, self._program, 0, group)
self._group = self.group_class(textures, blend_src, blend_dest, self._program, group)
self._subpixel = subpixel
self._create_vertex_list()

Expand Down
8 changes: 4 additions & 4 deletions pyglet/input/linux/x11_xinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ def open(self, window=None, exclusive=False):
super(XInputDevice, self).open(window, exclusive)

if window is None:
self.is_open = False
self._is_open = False
raise DeviceOpenException('XInput devices require a window')

if window.display._display != self.display._display:
self.is_open = False
self._is_open = False
raise DeviceOpenException('Window and device displays differ')

if exclusive:
self.is_open = False
self._is_open = False
raise DeviceOpenException('Cannot open XInput device exclusive')

self._device = xi.XOpenDevice(self.display._display, self._device_id)
if not self._device:
self.is_open = False
self._is_open = False
raise DeviceOpenException('Cannot open device')

self._install_events(window)
Expand Down
8 changes: 4 additions & 4 deletions pyglet/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def __init__(self, material, program, order=0, parent=None):

class TexturedMaterialGroup(BaseMaterialGroup):
default_vert_src = """#version 330 core
in vec3 vertices;
in vec3 position;
in vec3 normals;
in vec2 tex_coords;
in vec4 colors;
Expand All @@ -235,7 +235,7 @@ class TexturedMaterialGroup(BaseMaterialGroup):
void main()
{
vec4 pos = window.view * model * vec4(vertices, 1.0);
vec4 pos = window.view * model * vec4(position, 1.0);
gl_Position = window.projection * pos;
mat3 normal_matrix = transpose(inverse(mat3(model)));
Expand Down Expand Up @@ -286,7 +286,7 @@ def __eq__(self, other):

class MaterialGroup(BaseMaterialGroup):
default_vert_src = """#version 330 core
in vec3 vertices;
in vec3 position;
in vec3 normals;
in vec4 colors;
Expand All @@ -304,7 +304,7 @@ class MaterialGroup(BaseMaterialGroup):
void main()
{
vec4 pos = window.view * model * vec4(vertices, 1.0);
vec4 pos = window.view * model * vec4(position, 1.0);
gl_Position = window.projection * pos;
mat3 normal_matrix = transpose(inverse(mat3(model)));
Expand Down
4 changes: 2 additions & 2 deletions pyglet/model/codecs/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ def decode(self, filename, file, batch, group=None):
texture = pyglet.resource.texture(material.texture_name)
matgroup = TexturedMaterialGroup(material, program, texture, parent=group)
vertex_lists.append(program.vertex_list(count, GL_TRIANGLES, batch, matgroup,
vertices=('f', mesh.vertices),
position=('f', mesh.vertices),
normals=('f', mesh.normals),
tex_coords=('f', mesh.tex_coords),
colors=('f', material.diffuse * count)))
else:
program = pyglet.model.get_default_shader()
matgroup = MaterialGroup(material, program, parent=group)
vertex_lists.append(program.vertex_list(count, GL_TRIANGLES, batch, matgroup,
vertices=('f', mesh.vertices),
position=('f', mesh.vertices),
normals=('f', mesh.normals),
colors=('f', material.diffuse * count)))
groups.append(matgroup)
Expand Down
61 changes: 31 additions & 30 deletions pyglet/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def on_draw():


vertex_source = """#version 150 core
in vec2 vertices;
in vec2 position;
in vec2 translation;
in vec4 colors;
in float rotation;
Expand All @@ -82,7 +82,7 @@ def on_draw():
m_rotation[1][0] = -sin(-radians(rotation));
m_rotation[1][1] = cos(-radians(rotation));
gl_Position = window.projection * window.view * m_translate * m_rotation * vec4(vertices, 0.0, 1.0);
gl_Position = window.projection * window.view * m_translate * m_rotation * vec4(position, 0.0, 1.0);
vertex_colors = colors;
}
"""
Expand Down Expand Up @@ -181,6 +181,7 @@ class ShapeBase(ABC):
_num_verts = 0
_vertex_list = None
_draw_mode = GL_TRIANGLES
group_class = _ShapeGroup

def __del__(self):
if self._vertex_list is not None:
Expand Down Expand Up @@ -394,7 +395,7 @@ def group(self):
def group(self, group):
if self._group.parent == group:
return
self._group = _ShapeGroup(self._group.blend_src,
self._group = self.group_class(self._group.blend_src,
self._group.blend_dest,
self._group.program,
group)
Expand Down Expand Up @@ -476,7 +477,7 @@ def __init__(self, x, y, radius, segments=None, angle=math.tau, start_angle=0,

self._batch = batch or Batch()
program = get_default_shader()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand Down Expand Up @@ -511,7 +512,7 @@ def _update_vertices(self):
chord_points = *points[-1], *points[0]
vertices.extend(chord_points)

self._vertex_list.vertices[:] = vertices
self._vertex_list.position[:] = vertices

@property
def rotation(self):
Expand Down Expand Up @@ -599,7 +600,7 @@ def __init__(self, *points, t=1.0, segments=100, color=(255, 255, 255, 255), bat

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand Down Expand Up @@ -640,7 +641,7 @@ def _update_vertices(self):
line_points = *coords[i], *coords[i + 1]
vertices.extend(line_points)

self._vertex_list.vertices[:] = vertices
self._vertex_list.position[:] = vertices

@property
def points(self):
Expand Down Expand Up @@ -707,7 +708,7 @@ def __init__(self, x, y, radius, segments=None, color=(255, 255, 255, 255),

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand Down Expand Up @@ -737,7 +738,7 @@ def _update_vertices(self):
triangle = x, y, *points[i - 1], *point
vertices.extend(triangle)

self._vertex_list.vertices[:] = vertices
self._vertex_list.position[:] = vertices

@property
def radius(self):
Expand Down Expand Up @@ -796,7 +797,7 @@ def __init__(self, x, y, a, b, color=(255, 255, 255, 255),

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand Down Expand Up @@ -825,7 +826,7 @@ def _update_vertices(self):
line_points = *points[i], *points[i + 1]
vertices.extend(line_points)

self._vertex_list.vertices[:] = vertices
self._vertex_list.position[:] = vertices

@property
def a(self):
Expand Down Expand Up @@ -918,7 +919,7 @@ def __init__(self, x, y, radius, segments=None, angle=math.tau, start_angle=0,

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand Down Expand Up @@ -949,7 +950,7 @@ def _update_vertices(self):
triangle = x, y, *points[i - 1], *point
vertices.extend(triangle)

self._vertex_list.vertices[:] = vertices
self._vertex_list.position[:] = vertices

@property
def angle(self):
Expand Down Expand Up @@ -1049,7 +1050,7 @@ def __init__(self, x, y, x2, y2, width=1, color=(255, 255, 255, 255),

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand All @@ -1062,7 +1063,7 @@ def _create_vertex_list(self):

def _update_vertices(self):
if not self._visible:
self._vertex_list.vertices[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
self._vertex_list.position[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
else:
x1 = -self._anchor_x
y1 = self._anchor_y - self._width / 2
Expand All @@ -1081,7 +1082,7 @@ def _update_vertices(self):
dx = x1 * cr - y2 * sr
dy = x1 * sr + y2 * cr

self._vertex_list.vertices[:] = (ax, ay, bx, by, cx, cy, ax, ay, cx, cy, dx, dy)
self._vertex_list.position[:] = (ax, ay, bx, by, cx, cy, ax, ay, cx, cy, dx, dy)

@property
def x2(self):
Expand Down Expand Up @@ -1148,7 +1149,7 @@ def __init__(self, x, y, width, height, color=(255, 255, 255, 255),

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand All @@ -1161,14 +1162,14 @@ def _create_vertex_list(self):

def _update_vertices(self):
if not self._visible:
self._vertex_list.vertices[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
self._vertex_list.position[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
else:
x1 = -self._anchor_x
y1 = -self._anchor_y
x2 = x1 + self._width
y2 = y1 + self._height

self._vertex_list.vertices[:] = x1, y1, x2, y1, x2, y2, x1, y1, x2, y2, x1, y2
self._vertex_list.position[:] = x1, y1, x2, y1, x2, y2, x1, y1, x2, y2, x1, y2

@property
def width(self):
Expand Down Expand Up @@ -1282,7 +1283,7 @@ def __init__(self, x, y, width, height, border=1, color=(255, 255, 255),

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand All @@ -1299,7 +1300,7 @@ def _update_color(self):

def _update_vertices(self):
if not self._visible:
self._vertex_list.vertices[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
self._vertex_list.position[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
else:
bx1 = -self._anchor_x
by1 = -self._anchor_y
Expand All @@ -1311,7 +1312,7 @@ def _update_vertices(self):
ix2 = bx2 - b
iy2 = by2 - b

self._vertex_list.vertices[:] = (ix1, iy1, ix2, iy1, ix2, iy2, ix1, iy2,
self._vertex_list.position[:] = (ix1, iy1, ix2, iy1, ix2, iy2, ix1, iy2,
bx1, by1, bx2, by1, bx2, by2, bx1, by2)

@property
Expand Down Expand Up @@ -1461,7 +1462,7 @@ def __init__(self, x, y, x2, y2, x3, y3, color=(255, 255, 255, 255),

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand All @@ -1474,15 +1475,15 @@ def _create_vertex_list(self):

def _update_vertices(self):
if not self._visible:
self._vertex_list.vertices[:] = (0, 0, 0, 0, 0, 0)
self._vertex_list.position[:] = (0, 0, 0, 0, 0, 0)
else:
x1 = -self._anchor_x
y1 = -self._anchor_y
x2 = self._x2 + x1 - self._x
y2 = self._y2 + y1 - self._y
x3 = self._x3 + x1 - self._x
y3 = self._y3 + y1 - self._y
self._vertex_list.vertices[:] = (x1, y1, x2, y2, x3, y3)
self._vertex_list.position[:] = (x1, y1, x2, y2, x3, y3)

@property
def x2(self):
Expand Down Expand Up @@ -1581,7 +1582,7 @@ def __init__(self, x, y, outer_radius, inner_radius, num_spikes, rotation=0,

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand Down Expand Up @@ -1619,7 +1620,7 @@ def _update_vertices(self):
triangle = x, y, *points[i - 1], *point
vertices.extend(triangle)

self._vertex_list.vertices[:] = vertices
self._vertex_list.position[:] = vertices

@property
def outer_radius(self):
Expand Down Expand Up @@ -1692,7 +1693,7 @@ def __init__(self, *coordinates, color=(255, 255, 255, 255), batch=None, group=N

program = get_default_shader()
self._batch = batch or Batch()
self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)
self._group = self.group_class(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, program, group)

self._create_vertex_list()
self._update_vertices()
Expand All @@ -1706,7 +1707,7 @@ def _create_vertex_list(self):

def _update_vertices(self):
if not self._visible:
self._vertex_list.vertices[:] = tuple([0] * ((len(self._coordinates) - 2) * 6))
self._vertex_list.position[:] = tuple([0] * ((len(self._coordinates) - 2) * 6))
else:
# Adjust all coordinates by the anchor.
trans_x, trans_y = self._coordinates[0]
Expand All @@ -1720,7 +1721,7 @@ def _update_vertices(self):
triangles += [coords[0], coords[n + 1], coords[n + 2]]

# Flattening the list before setting vertices to it.
self._vertex_list.vertices[:] = tuple(value for coordinate in triangles for value in coordinate)
self._vertex_list.position[:] = tuple(value for coordinate in triangles for value in coordinate)

@property
def rotation(self):
Expand Down

0 comments on commit 676c3be

Please sign in to comment.