Replies: 1 comment
-
Is this code correct? Shape::Bounds shapeBounds = shape.getBounds();
constexpr double kScale = 64.0;
const double kMargin = static_cast<double>(pixelRange + 2); // pixels
const double kTranslate = kMargin / kScale; // relative margin
const double kOffsetPixels = pixelRange;
const double kOffsetUnits = kOffsetPixels / kScale;
const double shapeWidth = shapeBounds.r - shapeBounds.l;
const double shapeHeight = shapeBounds.t - shapeBounds.b;
const uint32_t bitmap_width = static_cast<uint32_t>(kScale * shapeWidth + 2. * kMargin + 0.5);
const uint32_t bitmap_height = static_cast<uint32_t>(kScale * shapeHeight + 2. * kMargin + 0.5);
// Vertex bounds
data.vertexBounds.left = shapeBounds.l - kOffsetUnits;
data.vertexBounds.right = shapeBounds.r + kOffsetUnits;
data.vertexBounds.bottom = shapeBounds.b - kOffsetUnits;
data.vertexBounds.top = shapeBounds.t + kOffsetUnits;
double startX = scale.x * translate.x;
double startY = scale.y * translate.y;
double left = startX + kScale * shapeBounds.l - kOffsetPixels;
double right = startX + kScale * shapeBounds.r + kOffsetPixels;
double bottom = startY + kScale * shapeBounds.b - kOffsetPixels;
double top = startY + kScale * shapeBounds.t + kOffsetPixels;
// UV bounds
data.uvBounds.left = kInvTextureWidth * left;
data.uvBounds.right = kInvTextureWidth * right;
data.uvBounds.bottom = kInvTextureHeight * bottom;
data.uvBounds.top = kInvTextureHeight * top;
Vector2 scale(kScale);
Vector2 translate(kTranslate);
translate.x += -shapeBounds.l;
translate.y += -shapeBounds.b;
Range range(static_cast<double>(pixelRange));
range /= scale.x;
// Generate MSDF floating point bitmap
Bitmap<float, 3> msdf(bitmap_width, bitmap_height);
edgeColoringSimple(shape, 3.0);
SDFTransformation t(Projection(scale, translate), range);
generateMSDF(msdf, shape, t); It works, but I still don't know how bitmap is being generated, so additional margin is required. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. You posted the example of usage:
How do I properly calculate rects for rendering (shape rect and UV rect), like you did in
msdf-atlas-gen
?I need to write analogs of your functions
GlyphGeometry::getQuadPlaneBounds
andGlyphGeometry::getQuadAtlasBounds
.Beta Was this translation helpful? Give feedback.
All reactions