So, I forgot how tedious these sub-pixel primitive routines are to write. It makes me wish I had documented my techniques for producing them better. Anyway, after chatting with one of my fellow coders, I was able to get alpha blending (translucency) up and running. Big props to syn9 for showing me the way on that one.
Alpha blending is an essential step for producing sub-pixel primitives, and with that step realized, I decided to prototype a sub-pixel circle fill routine. These results show promise, but I'm getting some artifacts. At certain radius sizes there are some pixels that get rendered out of place. Also, you might notice those two white diagonal lines. I have no idea where they're coming from, but I'm getting some sort of screen tearing as a result of them. Hopefully I can isolate and rid these issues so I can move forward with a finalized routine.
As far as my approach, I went with something quick and dirty just to get some approximate results. First I created a pixel drawing routine. It's funny, because GL takes a geometry based approach to rendering, so you really don't have direct pixel level access when it comes to custom rendering. So, to simulate pixel drawing, my pixel routine simply produces a GL line from (x,y)-(x+1,y+1). I'm almost certain there's a better and faster way to do this, but this works for now.
As far as generating the primitive, I'm using a brute force sampling technique. Any circle can be bounded by a box with length and height equal to twice the circle's radius. After determining the coordinates of this bounding box, I test each pixel in the box. If the pixel lies outside the circle, we don't draw it. If it lies inside the circle, we draw it using the circle color. If it lies near the circle we draw it using a percentage of the circle color. These "percentage" pixels, if you will, are what produce the visually pleasing quality of a sub-pixel primitive.
As for the pixel test, the circle and the bounding box both share the same center. By definition, every point on a circle is the same distance from its center. This distance is known as the radius. Using the distance formula, we test the distances of each pixel from the center point. A distance greater than the radius means that the pixel lies outside the circle, while a distance less than the radius means the pixel lies inside the circle. A distance near the radius means the pixel lies close to or on the circle.
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment