There is another solution that doesn't require render targets, and it's closer to dxDrawImageSection in the way it works: dxDrawMaterialPrimitive. dxDrawImageSection only operates on rectangular sections. dxDrawMaterialPrimitive allows you to draw triangles, specifying the texture coordinates for each vertex, and since triangles can be put together to form other shapes, you can do what dxDrawImageSection does but not limited to rectangular sections.
There isn't an example in the wiki page on how to use it, but dxDrawPrimitive has one, and dxDrawMaterialPrimitive works in a similar way, only it takes image as second argument, and each vertex has 5 parameters instead of 3 (2 extra parameters are for image coordinates).
I came up with some function, for drawing a radially cut out section of an image. I only tested it as much as I could test it in standalone Lua interpreter so I don't know if it works in MTA, but if it does, someone may put it on useful functions page in wiki ? It uses trianglefan primitive type, puts the first vertex in the center and other vertices around it.
local white = tocolor(255, 255, 255, 255)
local degToRad = math.pi/180
local function makeVertexAtAngle(centerX, centerY, halfWidth, halfHeight, angle, color)
local angleRad = angle*degToRad
local xAdd, yAdd = math.sin(angleRad), -math.cos(angleRad)
local maxAdd = math.max(math.abs(xAdd), math.abs(yAdd))
xAdd, yAdd = xAdd/maxAdd, yAdd/maxAdd
return {
centerX+xAdd*halfWidth, centerY+yAdd*halfHeight,
color,
0.5+xAdd*0.5, 0.5+yAdd*0.5
}
end
function dxDrawRadialImageSection(posX, posY, width, height, image, startAngle, stopAngle, color, postGUI)
if color == nil then
color = white
end
if postGUI == nil then
postGUI = false
end
local halfWidth, halfHeight = width*0.5, height*0.5
local centerX, centerY = posX+halfWidth, posY+halfHeight
local roundedStartAngle = math.floor((startAngle-45)/90+1)*90+45
local roundedStopAngle = math.ceil((stopAngle-45)/90-1)*90+45
local vertices = {{centerX, centerY, color, 0.5, 0.5}}
table.insert(vertices, makeVertexAtAngle(centerX, centerY, halfWidth, halfHeight, startAngle, color))
for angle = roundedStartAngle, roundedStopAngle, 90 do
table.insert(vertices, makeVertexAtAngle(centerX, centerY, halfWidth, halfHeight, angle, color))
end
table.insert(vertices, makeVertexAtAngle(centerX, centerY, halfWidth, halfHeight, stopAngle, color))
dxDrawMaterialPrimitive("trianglefan", image, postGUI, unpack(vertices))
end
This example should display a looping 5-second animation of image going from 0 to 360 (if I didn't screw anything up):
function drawAnimatedRadialSection()
local angle = (getTickCount() % 5000) / 5000 * 360
dxDrawRadialImageSection(100, 100, 200, 200, "your_image.png", 0, angle)
end
addEventHandler("onClientRender", root, drawAnimatedRadialSection)