Busata | 22 May 2013 10:15
Picon

Pyglet - Sprite - Integrating into an entity-component system

Dear,


I just started using Pyglet but would like to integrate it into a sort of entity - component system.
I'm trying to create a 2D side scrolling game to start with, so ended up by using sprites and the batch drawing system in 1.1, as I have little experience with OpenGL.

I started from the idea of having a "Renderable" component & "Position" component and let the renderer use those two to do the work.

The problem however is that the pyglet's Sprite's position is used to render and I'm a bit unsure if it's fairly easy to seperate it while still using the batch feature?

I.e. Anyone has a suggestion on how to split Sprite and its position while still being able to add it to the batch?

Thanks in advance!

--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Busata | 22 May 2013 10:39
Picon

Entity component system + Sprite

Hello,

I've just started using Pyglet for creating a small 2D sidescrolling game, and as a test to get an entity/component system running.

I was trying to use a Position and Renderable component, in order for my Renderer system to render the sprites/tiles.

Now, the problem is that to render the sprites, I was hoping to use the Sprite / Batch system that's present in Pyglet, but the position of the Sprite
is updated in the Sprite itself. I was hoping I could draw it by taking the data from the Position component.

Any suggestions if there's an easy way to split the Sprite image data and its position while still allowing the batch to draw them correctly?
I would like to avoid having to update both (Sprite/Position). I assume its a bit overdesigning but I would like to maintain the possiblity for entities to have a Position
without having to be rendered and curious if it can be solved the way I want it :-)


Thanks in advance!

--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Juan J. Martínez | 18 May 2013 20:28
Gravatar

Success stories (commercial games using pyglet)

Hello,

I had a problem the other day with Pyglet and when I was googling for
some help I found something like a bug report in a commercial game, and
apparently it uses Pyglet:

http://www.aceofspades.com/

Well, I'm truly impressed! I was wondering if someone else knows any
other "success story" of a commercial game using Pyglet.

Regards,

Juan

PS: wouldn't it be nice if pyglet.org had some links to these?

-- 
jjm's home: http://www.usebox.net/jjm/
blackshell: http://blackshell.usebox.net/

--

-- 
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Paul Pittlerson | 16 May 2013 18:38
Picon
Gravatar

error trying to load sprites

I'm trying to learn pyglet, and have installed 1.2alpha with python3.3.2 64bit edition.

I have a simple script for loading an image form a sprite sheet and displaying it as a large map.

class grid(pyglet.image.ImageGrid):
    def __init__(self, sprite):
        super(grid, self).__init__(sprite, 3, 1, 96, 96)

class map_tile(pyglet.sprite.Sprite):
    def __init__(self, file):
        super(map_tile, self).__init__(pyglet.resource.image(file))
    
class screen(pyglet.window.Window):
    def __init__(self, w, h):
        super(screen, self).__init__(w, h)
        self.clock = pyglet.clock.ClockDisplay()
        pyglet.clock.schedule_interval(self.update, 1/60.)
        
        raw = pyglet.image.load('images/map_sprites.png')
        raw_seq = pyglet.image.ImageGrid(raw, 3, 1, 96, 96)
        
        self.batch = pyglet.graphics.Batch()
        self.collection = []
        x, y = 0, 0
        
        for i in range(100):
            for j in range(100):
                sprite = pyglet.sprite.Sprite(raw_seq[2], batch = self.batch)
                sprite.x = x
                sprite.y = y
                self.collection.append(sprite)
                x += 96
            y += 96
            x = 0
        
    def update(self, dt):
        pass
        
    def on_draw(self):
        self.clear()
        self.batch.draw()
        self.clock.draw()
        pyglet.clock.tick()

if __name__ == '__main__':
    s = screen(1600, 900)
    pyglet.app.run()

However, when trying to run this, I get the following error:
Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\pyglet\__init__.py", line 332, in __getattr__
    return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'ImageGrid'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Pittler\Desktop\Dev\extra\pyglet experimentation\bullet_client.py", line 12, in <module>
    class grid(pyglet.image.ImageGrid):
  File "C:\Python33\lib\site-packages\pyglet\__init__.py", line 338, in __getattr__
    __import__(import_name)
  File "C:\Python33\lib\site-packages\pyglet\image\__init__.py", line 189
    except codecs.ImageDecodeException, e:
                                      ^
SyntaxError: invalid syntax

The program worked fine in python2.7 32bit, but now it's not working. What might the problem be and how do I fix it?

--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Anna Mária Nagy | 15 May 2013 09:02
Picon

(unknown)


--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
elliot | 15 May 2013 01:50
Picon

Feedback on a pyglet with pymunk tutorial I'm starting

Hello,


I wrote the first part of a tutorial on integrating pyglet, pymunk, Numpy and OpenCV.  Any feedback would be appreciated. 


-videos-
 

In case you don't end up reading it but have some insight, the bottleneck in my code right now is translating the dynamic vertices and updating batches.  I have 300+ polygons that are updated every frame, having their vertices rotated and translated.  This runs at 60 fps on my not so great laptop.  Am I doing the best I can?

The update function is only this:

def translate(self): px,py = self.body.position theta = self.body.angle initiald = self.initial_data cost, sint = cos(theta), sin(theta) #Just a bunch of multiplication and addition, optimized pts = [(px+x+r*(xhelper*(cost-1)-sint*yhelper),py+y+r*(yhelper*(cost-1)+sint*xhelper)) for x,y,r,xhelper,yhelper in initiald] #flatten and assign as tuple to batch vertices self.vertlist.vertices = tuple(map(int,[val for subl in pts for val in subl]))  

ncalls tottime percall cumtime percall filename:lineno(function) 1 0.019 0.019 49.193 49.193 poly_demo.py:1(<module>) ... 1911 0.035 0.000 44.047 0.023 poly_demo.py:122(on_draw) 1911 3.940 0.002 42.308 0.022 entities.py:12(step) 620979 2.838 0.000 37.946 0.000 entities.py:268(update)

So this function takes up 86% of my run time.  The second to last line takes up 2/3 of that, and the last line 1/3.


Thanks everyone,
Elliot

--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Everett Walls | 9 May 2013 04:49
Picon
Gravatar

Modifying vertex list data after adding it to a batch.

Hello. 

I have searched for a while and I can not quite find the solution to this issue I am having. Probably because I do not know what what I am looking for.

My issue is as follows:
I'd like to modify a primitive's vertex data after it has been added to a batch. I've tried modifying the list of vertex data every frame, but that only seems to directly modify the list. Everything added to the batch remains static for me.
I've tried changing the 'v2f' to 'v2f/stream,' but the batch draw seems to only draw what was added initially, disregarding any changes made to the vertex data after I have updated it with the vertices position attribute.

I am using pymunk and updating the position of the vertices to draw at every frame. It works with the straight pyglet.graphics.draw.

My code resembles the following:
# Init add
def __init__(self)
self.box_verts = self.body_poly.get_points()
self.vertlist = []
for v in self.box_verts: # transforms a list of tuple coords (Vec2d(x,y),Vec2d(x,y), etc) 
         self.vertlist.append(v.x) # to a list that pyglet can draw to [x,y, x,y, etc]
         self.vertlist.append(v.y)
self.player = batch.add(4, pyglet.gl.GL_POLYGON,
                            ('v2f', (self.vertlist)),
                            ('c3B', (55,55,50,255,255,255,255,255,255,55,55,50))
                            )
#Update the vertices 
def update(self, dt):
self.box_verts = self.body_poly.get_points()
self.vertlist = []
for v in self.box_verts: # transforms a list of tuple coords (Vec2d(x,y),Vec2d(x,y), etc) 
        self.vertlist.append(v.x) # to a list that pyglet can draw to [x,y, x,y, etc]
        self.vertlist.append(v.y)
self.newvertlist = self.vertlist.update()
self.player.vertices = self.newvertlist
def on_draw(self):
self.clear()
batch.draw()

I am using pymunk and updating the position of the vertices to draw at every frame. It works with the straight pyglet.graphics.draw.

If my problem does not make sense please let me know and I will attempt to clarify.

Thank you for your time and patience.

--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Isaac Freeman | 11 May 2013 19:47
Picon

Segfault on glDrawArrays

I'm getting a strange segfault using VBOs/VAOs when I call glDraw array.... I've run out of ideas how to fix it.. Any suggestions would be greatly appreciated.

the code is here:

http://dpaste.com/1141633/

The debug log says:

libGL: AtiGetClientDriverName: 9.0.2 fglrx (screen 0)
libGL: OpenDriver: trying /usr/lib/fglrx/dri/fglrx_dri.so
ukiDynamicMajor: found major device number 250
ukiDynamicMajor: found major device number 250
ukiOpenByBusid: Searching for BusID PCI:1:0:0
ukiOpenDevice: node name is /dev/ati/card0
ukiOpenDevice: open result is 10, (OK)
ukiOpenByBusid: ukiOpenMinor returns 10
ukiOpenByBusid: ukiGetBusid reports PCI:1:0:0
glGetString(7936)
glGetString(7937)
glGetString(7939)
glGetString(7938)
glGetString(7936)
glGetString(7937)
glGetString(7939)
glGetString(7938)
gluGetString(100801)
gluGetString(100800)
glEnable(2884)
glEnable(2929)
glGenBuffers(1, <pyglet.gl.gl.LP_c_u)
glGetString(7936)
glGetString(7937)
glGetString(7939)
glGetString(7938)
glClearColor(0.0, 0.0, 0.0, 1.0)
 * Converting cverts to GLfloat data
 * Creating VBO
glGenBuffers(1, c_uint(2L))
glPushClientAttrib(2)
glBindBuffer(34962, 2L)
glBufferData(34962, 768, None, 35040)
glPopClientAttrib()
 * Creating VAO
 * Compiling shaders
glCreateProgram()
glCreateShader(35633)
glShaderSource(2L, 1, <pyglet.gl.glext_arb, None)
glCompileShader(2L)
glGetShaderiv(2L, 35713, <cparam 'P' (0x7f750)
glAttachShader(1L, 2L)
glCreateShader(35632)
glShaderSource(3L, 1, <pyglet.gl.glext_arb, None)
glCompileShader(3L)
glGetShaderiv(3L, 35713, <cparam 'P' (0x19f32)
glAttachShader(1L, 3L)
glLinkProgram(1L)
glGetProgramiv(1L, 35714, <cparam 'P' (0x19f32)
 * Binding shaders
glUseProgram(1L)
 * Starting app loop
glViewport(0, 0, 800, 800)
glMatrixMode(5889)
glLoadIdentity()
glOrtho(0, 800, 0, 800, -1, 1)
glMatrixMode(5888)
 * update called
glBindBuffer(34962, 2L)
glPushClientAttrib(2)
glBindBuffer(34962, 2L)
glBufferData(34962, 768, <__main__.c_float_Ar, 35040)
glPopClientAttrib()
glBindBuffer(34962, 0)
 * on_draw called
glClearColor(0.0, 0.0, 0.0, 1.0)
glClear(16384)
   * binding verts
glBindBuffer(34962, 2L)
   * binding attrs
glEnableClientState(32884)
   * drawing arrays
Segmentation fault


--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
elliot | 11 May 2013 05:54
Picon

KeyStateHandler not compatible with on_key_press?

If I set up a KeyStateHandler, then using on_key_press seems to make all the entries in the handler dictionary false.  If i delete the on_key_press function, the handler dictionary works as expected.  I tried subclassing the KeyStateHandler and trying to use it separately as a dictionary (seperate from the <at> window.event decorated on_key_press), and I tried defining my on_key_press in there, and in both cases the presence on an on_key_press function makes everything in the dictionary false.


If I want to use both ('on key press' and 'is the button still held down'), do I have to use the on press and on release functions to maintain my own dictionary?  This seems silly.

This is the code I expect to work:

window = pyglet.window.Window(width=width, height=height)
keyboard = key.KeyStateHandler()
window.push_handlers(keyboard)

<at> window.event
def on_key_press(button, modifiers):
   print "pressed:", keyboard[key.UP]

def player_input(dt):
    print keyboard[key.UP]

pyglet.clock.schedule(lambda _: None)
pyglet.clock.schedule_interval(player_input,.15)

pyglet.app.run()

No matter what I am holding, there is a steady stream of Falses and pressing a key prints a false.  If I delete the on_key_press function, I get a steady stream of Trues and Falses as I would expect.


--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Gerardo Marset | 7 May 2013 07:11
Picon
Gravatar

Offscreen blitting

It is my understanding that the blit method usually blits to the current OpenGL Context.
Can I do something like this?


window = pyglet.window.Window()
canvas = OpenGLContext()

<at> window.event
def on_draw():
    pyglet.gl.Context.set_current(canvas)
    some_function_that_blits_stuff()
    window.switch_to()
    canvas.blit(0, 0)


Otherwise is there any class I can use to blit everything into, before blitting it to the window? I don't want my game objects to blit to the window directly.

--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Doug Linder | 6 May 2013 14:29
Picon
Gravatar

problems with the font api

Hey there,

I'm having a lot of trouble with the font api.

Basically it comes down to this:

1) If you have a font, and you call add_file() on it, you have no idea what the associated font name is.

2) If you call either pyglet.font.load() for pyglet.font.base.Font.have_font(), these return a font / true in all circumstances.

The only way I've found to determine if we're successfully using a font or not is:

        pyglet.font.add_file(path)
        font = pyglet.font.load(name=font_name, size=1)
        span = font.ascent + font.descent
        if span > 5:
          print("ID %s did not match a known font name" % self.font)

This seems absolutely ridiculous to me.

I mean, what the heck is this nonsense?

    <at> classmethod
    def have_font(cls, name):
        '''Determine if a font with the given name is installed.

        :Parameters:
            `name` : str
                Name of a font to search for

        :rtype: bool
        '''
        return True

!!! Why does the call even exist?

I appreciate loading fonts cross platform is tricky, and I suppose it's vaguely nice having access to the default system fonts, but this api is really really hard to use.


Am I doing something wrong?
Why is using fonts so difficult?

~
Doug.

--
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 pyglet-users+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gmane