The Stack Overflow podcast is back! Listen to an interview with our new CEO.
11

Could someone ELI5 to me, what is an index buffer and how is it related to vertex buffers Your vertex buffer contains the X and Y coordinates of 5 vertices. They are: index | X | Y 0 | 0.0 | 0.0 1 | 1.0 | 0.0 2 | 0.0 | 0.6 3 | 1.0 | 0.6 4 | 0.5 | 1.0 Your index buffer contains information about which lines to draw between these ...


10

The difference in which pixels are covered depending on the vertex order is related to rasterization rules. They're the rules that the GPU hardware uses to determine exactly which pixels are covered by a primitive. Rasterization rules are a bit subtle. One of their goals is to ensure that whenever you draw multiple primitives that are connected water-...


9

Since a logarithmic spiral is defined by $r=e^{a\cdot\theta}$, the inverse of the equation is this: $\theta=\frac{\ln{r}}{a}$. If we want to be able to control our step value, we can multiply it by a scalar ($a\cdot k$) before taking the logarithm, like so: $\theta=\frac{\ln (ak\cdot r)}{a}$ Therefore, if we take the natural log of theta multiplied ...


9

Is there a similarly fast way to draw antialiased lines? No, because by definition an anti-aliased line touches more pixels. Such algorithms will be slower. In a software rasterizer, the ubiquitous way to draw anti-aliased lines is Xiaolin Wu's line algorithm. It's not hard to implement, and anyway there's unusually high-quality pseudocode at that link. ...


7

What you (probably) want to achieve is something like this: When having a closer look at one of the corners and add a few lines, we see this: The black lines indicate that the center points of the circles along the borders of the red and blue boxes is the same. If the outer radius of the red box, for example, is $50px$, and the distance between the outer ...


6

Trick is, to move the entire object so that the point about which you want to rotate is at the center. Then rotate and after that counter move it so that the point is were it was. In fact this is not so much of a trick, as such, nearly all graphics engines work this way. It is just abstracted away in many cases. Most often you will see it done in matrix ...


6

If you are in a hurry to get your renderer working and you already have the filled polygonal routine functioning correctly, can I suggest an alternative, possibly easier approach? Though I'm not familiar with Lua, it seems you are solving for the exact intersection of a scan line with the quadratic Bezier which, though admirable, is possibly overkill. ...


5

If you have a vertex buffer like this: var vertices = [ 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.6, 0.0, 1.0, 0.6, 0.0, 0.5, 1.0, 0.0 ] And simply draw it as it is: // Create an empty buffer object var vertex_buffer = gl.createBuffer(); // Bind appropriate array buffer to it gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer); // Pass the vertex data to ...


4

is it important with modern GPU architectures to avoid floating point operations in favor of integer operations? Almost certainly not. CPUs have a long history where for many years they only handled integers natively and floating point operations were all done with slow math libraries. That changed about 20-25 years ago, but the thinking has remained ...


4

This question should most probably be asked on GD.SE or UX.SE. These sites specialize in how to design the graphics and how to choose the graphics for your purpose. But since you are here basic options are: Routes dont overlap but are parallel like electronic layouts (image 1, A), Works well unless you have many overlapping things. Space interleaved lines, ...


4

Instead of using cubic Bezier spline, you should use cubic Hermite spline. For cubic Hermite curve you specify the segment end points and tangents, which is what you then control in the tool. Hermite spline is almost the same as Bezier spline but with different $B$ matrix, so if you already understand Bezier, then understanding Hermite is a trivial step. So ...


4

The shape you’re trying to draw is called a catenary: it’s the shape that a cable/cord of constant density takes when supported at each end. You’ll have to do some research to find a parametric equation for its shape—this page has a start, though it doesn’t let you substitute in the endpoints so you’ll need some additional work there. Once you have an ...


3

Note that the approach you appear to be taking will only work for lines with a slope in a single octant. For the other seven octants the algorithm requires changing the approach, for example by changing the roles of x and y. Wikipedia gives a table of cases that can be used for this conversion. For this answer I will assume you are simply trying to get the ...


3

Well you can render at higher resolution and sample down thhis is called FSAA and should just work without much change to render code. FSAA has the benefit of not having a conflation problem whereas smoothing does. No, something has to emit this info. You take the derivate (the gfx card does this for you) of the surface varying to determine how far the step ...


2

You could: Draw them all with different widths and make each transparent (fiddling with alpha blend to make it look nice). Or make the depth proportional to the width, so the widest is always drawn at the bottom of the pyramid. The naive implementation would suffer with many routes. Not do anything special at intersections, and expect the user to infer what ...


2

Since you have a limited set of tools you are not actually doing a classical fitting. What you have is a discrete problem. And since you are looking for a somewhat easily drawn fit, no more than twice segmented for example. One way to approach this is to find all the points that match your curvature requirements. Then find the point x units away from point ...


2

The worst case is when the line is at a 45-degree angle; then its length (in pixel-sized units) is a factor of $\sqrt{2}$ times the number of pixels, or about 40% longer. You can see this if you imagine starting with a vertical line of say 50px, then gradually sliding the endpoint away horizontally. Note that the number of pixels drawn doesn't change! You ...


2

e = (float)(delta_x / delta_y) - 1.0; e += (float)delta_x / delta_y; Either of these lines will cause a divide-by-zero error when delta_y is zero, which is when the line is horizontal (or zero-length). You need to check for this condition and have some special-case code. As an aside, I don't know why people still teach Bresenham's algorithm to new CG ...


2

You're actually already doing color interpolation in the code you posted, in these expressions: qRgb( 255-I, 255, 255-I ) qRgb( I, 255, I ) The first one is interpolating from white to green by I, and the second one from green to white by I. In both cases I is acting as an integer form of the variable $\alpha$ from the equation. I note that you ...


1

The problem you are seeing, i.e. "jaggies" or "staircasing", is an example of the more general problem known as "aliasing" and, in the graphics field, the term you want to search for is "Antialiasing". Aliasing occurs when you undersample a signal. If a signal contains frequencies at or above the Nyquist Frequency, which is 1/2 the sampling frequency, ...


1

Well, for the first octant you can either step EAST or NORTH-EAST. Depending on the distance to the actual line you choose the appropriate. In many integer implementations, this is done with regard to the sign of D.


1

You have a background color and the color of your line, an antialiased line has additional lines drawn on either side of the first that are simply part way between the color and brightness of your origonal line and the background. If the line you are drawing is horizontal or vertical the additional antialiasing lines (however many, depending upon the ...


1

Frankly, your implementation doesn't make much sense. It basically iterates x coordinate through i variable and increments y variable at each step. Since the parameter doesn't cross the 0 boundary, it generates the diagonal points you can see on your picture. You also compute and update the parameter variable somehow, but don't use it anywhere.


1

I am a bit unsure if my calculations are correct, but on my scribbling paper it seemed to work out. P1 and P2 lie on a circle around M. This allows us to measure the distance of the two points by just taking the radius (which is half the line length) of the circle and constructing two rectangular triangles. The accepted answer here provides a sketch for ...


1

The endpoint of the line doesn't extend out to the edge of the box because you're using the circle equation with a fixed radius: double x2 = x1 + (lenght * cos(radians)); double y2 = y1 + (lenght * sin(radians)); This makes the endpoint trace out a circle as the angle is changed. If you want the endpoint to be on the edge of the box, one way is to set up ...


Only top voted, non community-wiki answers of a minimum length are eligible