Sorry its not a working example, but here's a piece of code that shows how
I wind the vertices and draw them with a triangle strip.  Yes if you draw
the vertices with a triangle strip in order, you get a hallow circle.  But
if you wind them up so each triangle spans the width of the shape, you can
fill out the area.  repeating the first and last vertices makes empty
triangles between successive shapes so you don't see anything connecting
them.

    def polyOfN(self,radius,n):
        r=radius
        if n < 3:
            n=3
        da = 2*pi/(n)     #angle between divisions
        return [[r*cos(da*x),r*sin(da*x)] for x in range(n)]

    def initializeVertices(self,radius,n):
        pts = self.polyOfN(radius,n)
        l = len(pts)
        #wind up the vertices, so we don't have to do it when speed counts.
        #I dont really know which is clock wise and the other counter clock
wise, btw
        cw = pts[:l//2]
        ccw = pts[l//2:][::-1]
        flatverts = [None]*(l)
        flatverts[::2]=ccw
        flatverts[1::2]=cw
        wound = [flatverts[0]]+flatverts+[flatverts[-1]] #make
        verts = tuple(map(int,[val for subl in pts for val in subl]))
#flatten list of lists
        self.n=len(verts)//2
        self.set_colors()
        self.vertlist = main_batch.add(self.n, gl.GL_TRIANGLE_STRIP,None,
  ('v2i,',verts),('c3b',self.colors))



On Thu, Jan 21, 2016 at 5:25 AM, Daniel Gillet <[email protected]>
wrote:

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

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