[Request] Custom (procedural) Drawing API

Post Reply
pCountNullMem
Burner Inserter
Burner Inserter
Posts: 7
Joined: Tue Sep 02, 2014 3:03 pm
Contact:

[Request] Custom (procedural) Drawing API

Post by pCountNullMem »

This might've been requested before, but I couldn't find that thread, so I'm creating this. :P Whenever developers get time.

This is a pretty simple request: I want to draw things onto the backbuffer, but before the GUI is drawn.
I'd like to see a drawing API with LUA bindings. This would make me => :D
Perhaps the drawing API must be used within a lua callback, named something like onUserRender(dt) ?

BUT, screen-coordinates-from-entity is a needed API in addition to this. getEntityPos[ X or Y ](entity);

I'd like to draw beams (gradient line) between two points, and their endpoints (gradient circle). (c:color, a:alpha)
- beam (color interpolated line) : drawLineGradient( x1, y1, x2, y2, halfWidth, c1, c2, c3, c4, a1, a2, a3, a4 )
- radial (color interpolated circle) : drawCircleGradient( x, y, radius, color1, color2 )

Additional geometry that could be drawn might include:
- lines : drawLine ( x1,y1, x2,y2, color, alpha, [thickness] )
- circles : drawCircle ( x,y, radius, color, alpha, [bool: filled] )
- rectangles : drawRect ( x,y, w,h, color, alpha, [bool: filled] )
- triangles : drawTriangle ( x1,y1, x2,y2, x3,y3, color, alpha, [bool: filled] )
- *sprites : drawSprite ( sprite, frame, x, y, scaleX, scaleY, rotation, color, alpha ) - example.

* For sprites: When a mod is loaded, the modder is responsible for calling a sprite loading API. Returns an integer handle.

For example, a line shape can easily be created in c++, and that might end up looking like the following code:

Code: Select all

void drawLine( const vec2f& pt1, const vec2f& pt2, float halfWidth, int color, float alpha ) {
    float  a = atan2( pt2.y - pt1.y, pt2.x - pt1.x );
    float  s = halfWidth * sin( a );
    float  c = halfWidth * cos( a );
    vec2f p1 = vec2f( pt1.x + s, pt1.y - c );
    vec2f p2 = vec2f( pt2.x + s, pt2.y - c );
    vec2f p3 = vec2f( pt2.x - s, pt2.y + c );
    vec2f p4 = vec2f( pt1.x - s, pt1.y + c );
    drawTriangle( p1, p2, p3, color, alpha ); //NOTE: Shapes may be batched :)
    drawTriangle( p3, p4, p1, color, alpha ); // - And later actually drawn in a single draw call.
}
This is just a start, but this could be the beginning of some pretty nice visual Factorio modding. :)
I've been programming in C++ for about 11 years now, I could implement this drawing API pretty quickly myself.
This is a fast and simple solution, it works for batching polygons just as well as it works for direct blitting.

This API could definitely get more advanced, for producing more interesting effects, tiled, wrapped, offset UV on shapes, etc.

Anyway, I hope someone see this, read this, and hopefully like this request. Unfortunately I'm not a factorio dev, heh.

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [Request] Custom (procedural) Drawing API

Post by Bilka »

It's been a long time since this request was made, but I implemented this for 0.17: https://lua-api.factorio.com/0.17.0-pre ... ering.html
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Implemented mod requests”