Drew Smathers(e)k dio:
> On Sat, Jul 5, 2008 at 11:21 AM, altern <[EMAIL PROTECTED]> wrote:
>> hi all
>>
>> today i am trying to catch up with the newest pyglet API. It looks very
>> nice although a bit weird at the first moment. I am working on this
>> simple example where many instances of an object are rendered on random
>> locs on screen. On my Desktop this takes almost 80% CPU, i am pretty
>> sure i am doing something wrong because most of the CPU time is taken by
>> the render method, (If I comment render() out it drops to 4% CPU).
>>
>> any suggestions? I am on Debian, on a PIV at 1.7 gz . Below i paste the
>> script i am working in.
>>
> 
> I would suggest using pyglet.graphics.Batch to store vertex lists and
> just modify the vertex data, rather than calling OpenGL transform
> calls for moving your quads - this might not solve you cpu utilization
> problem completely since you still have to update 500 quads for each
> frame (*), but your framerate should increase by a significant factor.
>   There is sgood documentation on this in the graphics section of the
> programming guide for 1.1.

interesting... i attach a test, could anyone please have a look at it 
and tell me if i am going in the right direction?. CPU usage has dropped 
to 15% with around 20 FPS. Very nice indeed.

I add the vertexes into a batch and at the same time I keep the vertexes 
into a list, then loop the list replacing the content of them every 
frame. Not sure if this is a good solution.

How can i limit the framerate? in the previous pyglet release there was 
some system to limit it with clock.set_fps_limit(12) but this does not 
seem to work now any more. Or do i need to use my own main loop? I 
checked the docs on this but I did not understand how to achieve this

> (*) If you have to update lots of things at a rapid rate, you're going
> to use the CPU.  Unless you're doing something fancy like CUDA.
> 
> Also, unrelated to your problem, but pyglet already sets up an
> orthographic projection for you in the window's on_resize() - you
> don't have to do this in your setup() function.

many thanks for the tip!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

import pyglet
pyglet.options[ 'debug_gl' ] = False # increase performace when using opengl. disables error checking

from pyglet.gl import *
from pyglet import clock

from random import Random
seed = Random()


width, height = 800,600
count = 0
w = 10


try:
    config = Config(sample_buffers=1, samples=4, depth_size=16, double_buffer=True,)
    window = pyglet.window.Window(width, height, resizable=True, config=config)
except pyglet.window.NoSuchConfigException:
    print "applying safe configuration"
    window = pyglet.window.Window(resizable=True)


fps_display = pyglet.clock.ClockDisplay()



def rand_v() :
    x = seed.random() * width
    y = seed.random() * height
    return    x-w, y-w, \
                 x+w, y-w, \
                 x+w, y+w, \
                 x-w, y+w



def setup() :
    clock.set_fps_limit(12)
    
    glClearColor(1, 1, 1, 1)

    global batch, stack
    batch = pyglet.graphics.Batch()
    stack = []
    
    for i in xrange(500) :
        v = rand_v()

        vertexlist = batch.add(
            4, pyglet.gl.GL_QUADS, None,
            ('v2f', v),
            ('c3B/static', (255, 0, 0,  255, 0, 0 , 255, 0, 0, 255, 0, 0))
            )
        stack.append(vertexlist)



@window.event
def on_draw() :
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    fps_display.draw()
    batch.draw()



def update(dt) :
    global count
    count += 1
    if count > 100:
        import sys; sys.exit()

    for v in stack : 
        v.vertices = rand_v()



setup()
pyglet.clock.schedule_interval(update, 1./12)
pyglet.app.run()

Reply via email to