Looking at the R48 Developers' Guide, I see there's a DrawRect, DrawOval, and DrawLine. I notice there's no DrawTriangle which would be very useful for 3D graphics (particularly filled)
Any chance we could ever get that?
While I could certainly draw the triangles with 3 line draws, it then would be a headache to have to try to fill it, where as if we had something similar to the Rect and Oval with Triangle w/fill support it would make doing simple 3D graphics a lot easier.
(Yeah, I am kind of wanting to make a simple flight simulator and/or work on a port of Elite...)
No DrawTriangle?
Re: No DrawTriangle?
I was going through the Vera FX documentation yesterday. It appears to be the go-to for making wireframe or filled polygons for more advanced games like Elite. It's just a line drawing algorithm, though. It's not a triangle based vertex pipeline like you might see in a hardware accelerator. This also means you aren't restricted to triangle based meshes. You can have n-gons and such.
A space flight simulator like Elite would be amazing!
A space flight simulator like Elite would be amazing!
Re: No DrawTriangle?
The algorithms for rectangle, circle, and line are each optimized.
- Rectangle is two straight lines of pixels incremented +1 on x, and two straight lines incremented by +1 on y.
- Circles and ellipses use a midpoint ellipse algorithm.
- Lines use a Bresenham's algorithm.
A fast line routine for triangles or polygons on an 8 bit machine would to include a DrawLineTo so the starting point doesn't need to be reloaded. Saves a few clock cycles if done right.
- Rectangle is two straight lines of pixels incremented +1 on x, and two straight lines incremented by +1 on y.
- Circles and ellipses use a midpoint ellipse algorithm.
- Lines use a Bresenham's algorithm.
A fast line routine for triangles or polygons on an 8 bit machine would to include a DrawLineTo so the starting point doesn't need to be reloaded. Saves a few clock cycles if done right.
Re: No DrawTriangle?
With filled triangles, you'd want to sort the vertices so the top vertex is always drawn first (or the top left if the top edge is horizontal.) This allows for the algorithm to compute the line points so that it's always filling in the same direction (left to right on a line, top to bottom.)codewar65 wrote: ↑Fri Mar 28, 2025 4:26 pm The algorithms for rectangle, circle, and line are each optimized.
- Rectangle is two straight lines of pixels incremented +1 on x, and two straight lines incremented by +1 on y.
- Circles and ellipses use a midpoint ellipse algorithm.
- Lines use a Bresenham's algorithm.
A fast line routine for triangles or polygons on an 8 bit machine would to include a DrawLineTo so the starting point doesn't need to be reloaded. Saves a few clock cycles if done right.
You also have to z-sort polygons so that the polygons in the back get drawn first. (Backface culling is also useful, in that it cuts the number of faces that need to be drawn by roughly 1/2.)