Clipping a polygon to only draw within a circle in Love2D - graphics

I'm trying to draw a circle with filled, randomly generated polygons drawn on top of it, but I can't work out how to make it so that the polygons are only drawn on top of the circle.
Here's a mockup as an example:
I have a achieved the random polygons drawn on a circle, using the love.graphics.polygon() function with a set of randomly generated points, but I'm looking for a way of clipping them when they're drawn so that they're only filled in on top of the circle.
Here's what I've actually got so far:
So, my question is: is there a function that I can call in the love.draw function that clips parts of the polygon drawn outside of a range, or is it going to be harder to fix than that?
Thanks in advance!

It turns out that I could have just spent a minute looking at the love.graphics documentation. Anyway, the love.graphics.stencil() function and its counterpart love.graphics.setStencilTest() are just what I needed.
You can pass the draw function for the circle to the love.graphics.stencil() function, and the using the setStencilTest(), you can make it not draw pixels outside that circle function. The documentation has some good examples.

Related

Clipping a circle with svg... or?

Currently I am using canvas to draw the gold circle, then snip off the areas half way to adjacent stars with globalCompositeOperation : destination-out, then paste the result into the main canvas.
I am contemplating changing to svg for this.
The closest method I have found is clip masks. I would have to create a set of clip-masks for each circle (star), this seems excessive if there were 2000 stars.
Another way would be to create polygons, but the math required to calculate the path may be beyond my capabilities.
So before I go down either of these routes, I would like to know if there is a better way or which of the above methods are recommended.

fill between two radius of circle by geometry shader with radius

I'm confused in using geometry shader for solve this problem:
I have two radius of a circle that every radius is a line and I called that's a line. every line is made of list of points that every points have a color.
so how fill between two lines with lines that's color of every point on a line has between colors of points of two lines on a equal radius.
it is so may be complex so I show it with a picture:
gradient Radiuses
.
I think best way of solving this problem is geometry shader but if you know better way that have good performance, I listen.
thanks.

rounded edges/corners in DirectX (D3D9)

I created my own little 2D-Engine with DirectX (okey, should be more like a GUI in the end) and tried to create rounded edges for a simple Rectangle. Since I never done this with a graphics framework before I had no idea how to supply this.
For now, I just overlapped 5 Rectangles and 4 circles (the circles are used for the rounded edges). It does work with opaque colors but if I add alpha into the rectangles the circles are making problems. (Shown in the image below - i should have choose another colors...)
<# Open Image #>
I can't find a solution myself (I googled and whondered I found nothing about rounded edges in DirectX) and I do believe there is a much powerful and faster method doing this. So my final question is, what are the common algorythm to create a rectangle with rounded edges in Direct3D9 ?
The common way to draw rounded quads is the use of textures with an alphachannel. It's very easy and the most of the gui's uses images to achieve a specific look. If you draw only single-colored boxes it may look very generic after a while (even if they have fancy rounded corners ;) ).
But if you want to draw rounded quads directly, I would suppose to generate a custom geometry, which fits the desired area directly without overlapping (need for alphablending). In you case it would be something like this:
The more triangles you're using for the corner the smoother it will look.

How to draw a cylinder geometry using webgl?

I need to draw a cylinder geometry using webgl, but don't know how to realize it. The parameters may be radius,subdivisions and two central point of bottom faces.Any ideas will be appreciated,thanks~
Fundamentally, you will build it with triangles. It would be easiest to think of it more as an "n-sided" prism. The top and bottom faces will need to be made of triangle "fans", where each triangle shares one point in the center.
You will need to use simple math (including trigonometry) to calculate the locations of the points for each triangle.
If you don't know how to draw triangles with WebGL, check out NeHe's excellent WebGL guide at learningwebgl.com.

How to draw the heightmap onto the screen?

I'm using DirectX10 to simulate a water surface, and I'm now with a height map,which is a 2D array of the heights(y) at the points (x,z). But to draw it on the screen, I must turn it into a mesh or have a index to draw triangle topology.
But the data is too large to do it manually. Are there any methods for me to draw it on the screen. I hope it's easy to implement. If there is function included in DirectX10 which can make it, the it's the best one for me.
Create a mesh that format a grid of squares (each made of two triangles) and set all vertices y = 0. In the vertex shader sample the heightmap and add the value stored in the heightmap to the y of the vertice.
This might help you.
P.S: If the area you want it to cover is too big you should take a look at terrain LOD techniques (should work the same for water).
I'm sure you can make a mesh out of it. I doubt you can generate the heightmap for a water surface that is too large to "meshify".
Why are you looking at Diamond square. For a 512x512 heightmap all you need to do is define a set of point and then generate the triangles for it. Its really very simple.

Resources