Hi Kevin, 

There are a lot of very inificient things you are doing in your code. 
Calling the draw() method directly on each sprite is not recommended, since 
it has to set/unset the OpenGL state for each and every one.  What you want 
to do instead is to create a batch:  *batch = pyglet.graphics.Batch*, and 
pass this into each sprite on creation. Then, you can draw everything 
together with a single call to *batch.draw()* in your on_draw method. There 
is a bit of information about Batches in the programming guide, but it does 
need more detail: 
http://pyglet.readthedocs.io/en/pyglet-1.2-maintenance/programming_guide/graphics.html#batched-rendering

That said, pyglet can easily render thousands of sprites if batched 
properly.


On Tuesday, February 7, 2017 at 12:06:49 PM UTC+9, Kevin S. wrote:
>
> Hello, I started playing around with Pyglet recently and it was going fine 
> until I started trying to fill the screen with images.  I ended up with an 
> atrocious frame rate, to the point where user mouse clicks weren't working 
> properly and animations looked really bad.  In order to try to test the 
> limitations, I created the following test game to see what would happen:
>
>
>
>
>
>
> *import randomimport pygletfrom pyglet import gl*
> *class Game(object):*
> *    width = 1000*
> *    height = 600*
> *    images = [*
> *        {"filepath": "image100x100.jpeg", "count": 300}*
> *    ]*
> *    background_color = (0.3, 0.3, 0.3, 1)*
> *    report_interval = 5.0*
>
> *    def start(self):*
> *        self.pyglet_window = pyglet.window.Window(width=self.width, 
> height=self.height, vsync=False)*
> *        self.pyglet_window.event(self.on_draw)*
> *        self.initializeGL()*
> *        self.reset_report_timer()*
> *        self.initialize_sprites()*
> *        pyglet.clock.schedule_interval(self.tick, 0.01)*
> *        pyglet.app.run()*
>
> *    def initialize_sprites(self):*
> *        self.sprites = []*
> *        for image_set in self.images:*
> *            filepath = image_set["filepath"]*
> *            count = image_set["count"]*
> *            image = pyglet.image.load(filepath)*
> *            for i in range(count):*
> *                x, y = random.randint(0, self.width), random.randint(0, 
> self.height)*
> *                sprite = pyglet.sprite.Sprite(image, x=x, y=y)*
> *                self.sprites.append(sprite)*
>
> *    def print_report(self):*
> *        print "======================="*
> *        print "  Call count: {}".format(self.num_calls)*
> *        print "  FPS: {}".format(self.num_calls / self.report_interval)*
>
> *    def reset_report_timer(self):*
> *        self.report_timer = 0.0*
> *        self.num_calls = 0*
>
> *    def initializeGL(self):*
> *        gl.glEnable(gl.GL_TEXTURE_2D)*
> *        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, 
> gl.GL_NEAREST)*
> *        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, 
> gl.GL_NEAREST)*
> *        gl.glEnable(gl.GL_BLEND)*
> *        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)*
> *        gl.glPushAttrib(gl.GL_ENABLE_BIT)*
>
> *    def tick(self, seconds_passed):*
> *        self.num_calls += 1*
> *        self.report_timer += seconds_passed*
> *        if self.report_timer >= self.report_interval:*
> *            self.print_report()*
> *            self.reset_report_timer()*
>
>
> *    def on_draw(self):*
> *        self.pyglet_window.clear()*
> *        pyglet.gl.glColor4f(*self.background_color)*
> *        pyglet.graphics.draw(4, pyglet.gl.GL_QUADS,*
> *            ('v2i', (0, 0, self.width, 0, self.width, self.height, 0, 
> self.height))*
> *        )*
> *        pyglet.gl.glColor4f(1, 1, 1, 1)*
> *        self.draw_sprites()*
>
> *    def draw_sprites(self):*
> *        for sprite in self.sprites:*
> *            sprite.draw()*
>
>
> *if __name__ == "__main__":*
> *    game = Game()*
> *    game.start()*
>
> I attached the file I used as well.  The GL commands I used were designed 
> to get pixel perfect graphics, and I set them up a long time ago and don't 
> remember exactly what they do.  If you think those are teh problem please 
> let me know and I will test it out.
>
> The results were pretty crumby.  I found that with 100 images I was 
> sitting at about 60 fps, with 200 images I went down to 30 fps, with 300 
> images I was down to 20 fps.
>
> I wanted to test out some features like the atlas and resource packages, 
> but I figured I would double check to make sure I am not making any obvious 
> mistakes here.  Can anyone confirm that the limitations I am experiencing 
> are normal?  If not, what can I try to get things working a bit better?
>
> My specs are:
>
>    - MacBook Pro (15-inch, Mid 2012)
>    - Processor - 2.6 GHz Intel Core i7
>    - Memory - 8 GB 1600 MHz DDR3
>    - Graphics - NVIDIA GeForce GT 650M 1024 MB
>    
>

-- 
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to