bastienleonard / pysfml-cython

A Python 2/3 binding for SFML 2, written with Cython
http://pysfml2-cython.readthedocs.org/
Other
68 stars 8 forks source link

Per-Point Colors #30

Closed mkeeter closed 12 years ago

mkeeter commented 12 years ago

Hi Bastien,

In an earlier version of this library, it was possible to generate a shape with per-point coloring, e.g.

s = sf.Shape()
s.add_point(xLoc, yLoc + 1, sf.Color.WHITE)
s.add_point(xLoc, yLoc + 2, sf.Color(255, 255, 255, 0))
s.add_point(xLoc + 1, yLoc + 2, sf.Color(255, 255, 255, 0))
s.add_point(xLoc + 1, yLoc + 1, sf.Color.WHITE)

Is there a way to do this with the current library version?

bastienleonard commented 12 years ago

This feature has been removed in the new graphics API in SFML 2. I believe VertexArray should be used if you want more features, but I couldn't find a recent Laurent post about this.

Note that I haven't added VertexArray in the Python binding, because I don't feel like it's more useful than calling RenderTarget.draw() with a list of Vertex objects. If I remember correctly, the only thing VertexArray does is remembering the primitive type across draw() calls. But I've never used this kind of stuff in my personal projects, so if someone else needs it I can add it.

mkeeter commented 12 years ago

Rock on - it's easy enough to create a vertex list, so this solves my problem.

For reference, creating a multi-color rectangle is done with the code

target.draw([sfml.Vertex((0,0), sfml.Color(255,255,255)),
             sfml.Vertex((1,0), sfml.Color(255,0,0)),
             sfml.Vertex((1,1), sfml.Color(0,255,0)),
             sfml.Vertex((0,1), sfml.Color(0,0,255))],
             sfml.QUADS)