Hi Jonathon,
Rather than trying to turn GL primitives in to an image to use with a
Sprite, you could also make a Sprite-like class for the various shapes.
This can get tricky if you want to rotate them, as you'll have to add your
own math to do that work, but as an example I'll post a simple Rectangle
class below. You can make similar classes for a variety of shapes:
class Rectangle:
def __init__(self, x, y, width, height, color=(255, 255, 255, 255),
batch=None, group=None):
self._x = x
self._y = y
self._size = [width, height]
self._color = color
self._batch = batch
self._group = group
self._vertex_list = batch.add(6, GL_TRIANGLES, group, 'v2f', 'c4B')
self._update_vertex_list()
def _update_vertex_list(self):
x = self._x
y = self._y
w, h = self._size
one = x, y
two = x + w, y
three = x + w, y + h
four = x, y + h
self._vertex_list.vertices[:] = one + two + three + three + one + four
self._vertex_list.colors[:] = self._color * 6
@property
def width(self):
return self._size[0]
@width.setter
def width(self, value):
self._size[0] = value
self._update_vertex_list()
@property
def height(self):
return self._size[1]
@height.setter
def height(self, value):
self._size[1] = value
self._update_vertex_list()
On Wednesday, March 4, 2020 at 12:29:55 AM UTC+9, Jonathon Parker wrote:
>
> The Sprite class takes an image and all the examples I have seen use an
> image file. Instead of using an image file, is it possible to use anything
> from pyglet.graphics to define an image? How do I do this? My goal is to
> take advantage of all the functions of a Sprite with a custom image created
> from multiple geometric shapes.
>
> FYI, I did successfully define an image (a green square) using
> SolidColorPattern, convert it to a texture, and pass it to a Sprite. After
> that I got stuck.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyglet-users/48d5c49e-9c55-4ea1-ae99-c6dd73e574a7%40googlegroups.com.