An sdl_mesh holds triangles that the SDL renderer draws without
Cairo, using SDL_RenderGeometry(). An sdl_layer shows it if it is the
sdl_layer<-mesh
of the layer. Each corner (vertex) of a triangle has a position,
a colour and a position in the texture of the layer. The colours are
interpolated over the triangle and multiplied by the texture. Without a
texture, the triangle shows the colours only.
Positions are in the coordinates of the window and mapped through
sdl_layer<-transform,
so a whole mesh can be moved, rotated and scaled. Positions in the
texture are in its pixels. The layer's
sdl_mesh<-alpha, sdl_mesh<-tint, sdl_mesh<-blend
and sdl_mesh<-scale_mode apply; its sdl_mesh<-area, sdl_mesh<-scale,
sdl_mesh<-source, sdl_mesh<-angle, sdl_mesh<-flip, sdl_mesh<-offset
and sdl_mesh<-slices are ignored.
Meshes are good for:
.g., coloured
plots.
.g., a camera image
on a deformed grid.
Small meshes can be built using sdl_mesh->append
and sdl_mesh->triangle.
For large meshes that change on every frame, use the predicate
pce_sdl_mesh_set/3, which replaces all
vertices and triangles in one call:
pce_sdl_mesh_set(+Mesh, +Vertices, +Indices)
Vertices is a list of v(X,Y), v(X,Y,U,V) or
v(X,Y,U,V,rgba(R,G,B,A)), where U,V is the position in the
texture and R, G, B and A are integers 0..255. The default colour is
opaque white. Indices is a list of indices of Vertices, three per
triangle, counting from 0. If Indices is [], each three
consecutive vertices make a triangle. For example, a rectangle with a
red and a blue side:
new(M, sdl_mesh),
pce_sdl_mesh_set(M,
[ v(0,0,0,0,rgba(255,0,0,255)),
v(100,0,0,0,rgba(0,0,255,255)),
v(100,50,0,0,rgba(0,0,255,255)),
v(0,50,0,0,rgba(255,0,0,255))
],
[0,1,2, 0,2,3]),
new(L, sdl_layer),
send(L, mesh, M),
send(Window, append, L).
The edges of the triangles are not anti-aliased. frame<-image
draws meshes with Cairo; a textured triangle whose corners have
different colours is drawn using their average colour.
point(0,0)), and colour its colour (default opaque white).
The index of the new vertex is the old sdl_mesh<-count.