-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support for subpixel correct drawing ? #425
Comments
Before I start converting draw commands internal position type from short to float could you test something for me. struct nk_convert_config {
/* ... */
enum nk_anti_aliasing line_AA;
unsigned circle_segment_count;
unsigned arc_segment_count;
unsigned curve_segment_count;
/* ... */
}; First could try turning line_AA anti-aliasing on and off. If that does not help please try to set higher values for each of the segment counts. These basically dictate out of how many triangles shapes/lines generated out of. Also for any curved shapes or lines I would highly recommend overriding If your problem still persist then I will change internal command types from |
I think I might not have been clear with my statement. The problem is not in using the predefined circle/arc/curve-primitives, but with doing my own out of multiple lines. I first stumbled across this problem when trying to draw an arc without the begin/and strokes from the center (really JUST the arc). Since there was no primitive for this I tried to draw a bunch of lines whose coords I calc myself (using the precise stdlib sin/cos). However the resulting arc looks horrorbly deformed due to each start and endpoint of each line segment snapping to fill pixels, because of the internal short conversion. |
Sorry to bring this issue up again...I'm also facing a similar situation where I would like to have some custom widget displaying a function plot. Below is a screenshot of my attempt drawing Internally, Nuklear does float-to-short conversion: Lines 390 to 391 in 8f5c1be
The conversion results in heavily aliased curve, as shown in my screenshot. As a proposal, there could be a global macro like |
@LennertSchneider @itsuhane could you maybe first try disabling the conversion from |
Sure, I've tried some PoC. Please see the screenshot below: Unfortunately, most of the commands are using To make the In the definition of Lines 4234 to 4240 in 181cfd8
Then I had a subpixel version for NK_API void
nk_stroke_polyline_subpixel(struct nk_command_buffer *b, float *points, int point_count,
float line_thickness, struct nk_color col)
{
int i;
nk_size size = 0;
struct nk_command_polyline *cmd;
NK_ASSERT(b);
if (!b || col.a == 0 || line_thickness <= 0) return;
size = sizeof(*cmd) + sizeof(float) * 2 * (nk_size)point_count; // has to be sizeof(float)
cmd = (struct nk_command_polyline*) nk_command_buffer_push(b, NK_COMMAND_POLYLINE, size);
if (!cmd) return;
cmd->color = col;
cmd->point_count = (unsigned short)point_count;
cmd->line_thickness = line_thickness;
for (i = 0; i < point_count; ++i) {
cmd->points[i].x = points[i*2]; // no type-casting
cmd->points[i].y = points[i*2+1];
}
} |
My changes are on top of version 509c75b. |
@itsuhane thank you for the reaction. Now I'm thinking again about your proposal:
As that actually seems to be the way to go. Make a pull request and I'll merge it 😉. |
Hi,
I'm trying to render a waveform using nk_stroke_line, but it looks quite horrible, because all the float precision in the supplied coords is lost due to internal conversion to short.
I have the same problem with some other custom controls where I want to use lines and circles to construct them.
Is there a reason this has been done ? Is this really necessary to abandon the float precision internally ?
Cheers.
The text was updated successfully, but these errors were encountered: