I've been talking with Radnen and Rahkiin on IRC. We've been speaking of what a more modern API would actually look like.
Here is an example of what I would like to do with the graphics API (the descendant of the SpriteBatcher). I've included a demo mock-up of it.
There are two concepts that are really different from Sphere Classic here. One, that there aren't really primitives anymore, and two that
everything is textured. A `primitive' is a collection of vertices, a masking color, and a texture. To be untextured, you would just use a one-color texture. Shapes would be objects, which can be blit (much like images), although their location on screen is inherent to them.
For example, this:
Rectangle(16, 16, 48, 48, CreateColor(255, 0, 0));
would be duplicated as so:
var s = new Shape([new Vertex(16, 16), new Vertex(64, 16), new Vertex(64, 64), new Vertex(16, 64)], new Color(255, 0, 0), new Image(1, 1, new Color(255, 255, 255))
s.blit();
this:
Triangle(16, 16, 16, 64, 64, 64 CreateColor(255, 0, 0));
would be duplicated as so:
var s = new Shape([new Vertex(16, 16), new Vertex(64, 16), new Vertex(64, 64)], new Color(255, 0, 0), new Image(1, 1, new Color(255, 255, 255))
s.blit();
And here:
LoadImage(...).blit(10, 10);
as so:
var im = new Image(...)
var s = new Shape([new Vertex(0, 0), new Vertex(im.width, 0), new vertex(im.width, im.height), new Vertex(0, im.height)], new Color(255, 255, 255), im)
s.translate(10, 10);
s.blit();
While that is obviously more verbose for such a simple example, it makes the API much more generalized, which would make any scripts to simplify it or provide shorthand notations much more useful. It would also be trivial to make a shim that presented a 1.5-like API on top of this.
Shapes can share their textures (which are image objects), although their vertices are unique to each one (identity-wise, not value-wise).
Shapes have member functions like Rotate, Translate, Skew, etc. that are similar to what is provided for Images and Surfaces right now.
This idea has several obvious advantages:
- This unifies images and primitives
- All primitives are now one kind of object that has permanence.
- This makes the API vastly simpler, and removes dozens of now redundant functions
- This is how computers actually work, while still being very object-based
It makes the API nicer, and gives every single drawing operation many of the advantages of the old SpriteBatcher idea I had. It also makes the SpriteBatcher much simpler and nicer to use.
Moved from the TurboSphere topic ~FlyingJester