Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dxDrawRing #1081

Open
Ceeserxx opened this issue Sep 5, 2019 · 3 comments
Open

dxDrawRing #1081

Ceeserxx opened this issue Sep 5, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@Ceeserxx
Copy link

Ceeserxx commented Sep 5, 2019

I would love to have this function in addition to dxDrawCircle.
The difference here would be you have a clear ring while the center is empty (unlike in dxDrawCircle where you can just make a color gradient fading out towards the center / outside).
Right now you can only make a ring using images or with a ton of dxDrawLines, but no matter how many calls you make you still see pixels

Example function (like it would be in wiki):
bool dxDrawRing ( float posX, float posY, float outerRadius [, float ringWidth = 5, float startAngle = 0.0, float stopAngle = 360.0, int startColor = white, int stopColor = startColor, int segments = 32, int ratio = 1.0, bool postGUI = false ] )

Required Arguments:
posX, posY -- like dxDrawCircle
outerRadius -- The outer/max radius of the ring

Optional arguments:
ringWidth -- The thickness of the ring, expanding towards the center of the ring (so max allowed should be the 'outerRadius', that would make a full circle)
startAngle, stopAngle -- like dxDrawCircle
startColor -- The color to start at startAngle
stopColor -- The color to end with at stopAngle (That gives the oppertunity to make a ring with a color gradient or a fading-out ring towards the end)
segments, ratio, postGUI -- like dxDrawCircle

Thanks for reading and huge thanks in advance if this gets into the game!

@Ceeserxx Ceeserxx added the enhancement New feature or request label Sep 5, 2019
@Ceeserxx
Copy link
Author

Ceeserxx commented Sep 5, 2019

This is the best way to render a ring in mta at the moment without using an image file - render your own ring by pixels. But this takes quite long, even for just creating a renderTarget/texture its about 400ms with this sizes / detaillevel

SX, SY = guiGetScreenSize();

local sin = math.sin;
local cos = math.cos;
local txd = nil;

function dxDrawRing(posX, posY, outerRadius, ringWidth, startAngle, stopAngle, detailLevel, r, g, b, a)
local pixels = dxGetTexturePixels(dxCreateTexture(outerRadius * 2, outerRadius * 2));

for i = startAngle, stopAngle, 1 / detailLevel do
    local iRad = math.rad(i);

    for radius = outerRadius - ringWidth, outerRadius do
        x = posX + cos(iRad) * radius;
        y = posY + sin(iRad) * radius;

        dxSetPixelColor(pixels, x, y, r, g, b, a);
    end
end

return dxCreateTexture(pixels);

end

txd = dxDrawRing(SY / 4, SY / 4, SY / 4, 10, 0, 360, 10, 255, 165, 0, 64);

function render()
dxDrawImage(SX / 2 - SY / 8, SY / 2 - SY / 8, SY / 4, SY / 4, txd);
end
addEventHandler("onClientRender", root, render);

@Einheit-101
Copy link

There is a dxDrawCircle shader that supports drawing rings and its performance is very good.

@Pirulax
Copy link
Contributor

Pirulax commented Sep 9, 2019

Yep, use shaders, they're fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants