Hi,

The problem you have is that both vertices lists have the same *domain*, 
which means same format, same group and same OpenGL mode. The doc 
<http://pyglet.readthedocs.org/en/latest/api/pyglet/pyglet.graphics.html#drawing-modes>
 
says

> However, because of the way the graphics API renders multiple primitives 
> with shared state, GL_POLYGON, GL_LINE_LOOP and GL_TRIANGLE_FAN cannot be 
> used — the results are undefined.


In order to make different filled polygons (in your case 24 sided polygons) 
live together in a batch, you will have to use an OpenGL mode like 
GL_TRIANGLE and make instead an indexed vertex list to mimic a triangle fan 
behaviour.

Here is a sample code based on your previous code.

import pyglet, math, random
from pyglet.gl import *

window = pyglet.window.Window(800,600)
batch = pyglet.graphics.Batch()

def create_circle(x, y, radius, batch):
    circle, indices = create_indexed_vertices(x, y, radius)
    vertex_count = len(circle) // 2
    vertex_list = batch.add_indexed(vertex_count, pyglet.gl.GL_TRIANGLES, 
None,
                    indices,
                    ('v2f', circle), 
                    ('c4f', (1, 1, 1, 0.8) * vertex_count))

def create_indexed_vertices(x, y, radius, sides=24):
    vertices = [x, y]
    for side in range(sides):
        angle = side * 2.0 * math.pi / sides
        vertices.append(x + math.cos(angle) * radius)
        vertices.append(y + math.sin(angle) * radius)
    # Add a degenerated vertex
    vertices.append(x + math.cos(0) * radius)
    vertices.append(y + math.sin(0) * radius)

    indices = []
    for side in range(1, sides+1):
        indices.append(0)
        indices.append(side)
        indices.append(side + 1)
    return vertices, indices

for i in range(2):
    create_circle(window.width*random.random(), 
window.height*random.random(), 20, batch)


@window.event
def on_draw():
    window.clear()
    batch.draw()
 
pyglet.app.run()

There may be a better way, but at least this works. :)

Dan.

-- 
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