[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freetype
Subject:    Re: [ft] Can't get offset of glyphs right.
From:       Erlend Langseth <3rlendhl () gmail ! com>
Date:       2015-06-07 19:07:10
Message-ID: CAEoNDKhe-7avk6jho0eh8QozH8Ba5g-oDUBfV=BdpMmcLmwh7A () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I solved it. It was just a mismatch between OpenGL's normalized device
coordiante system, where the origin is at (-1, -1) and the coordinate
system of the glyph, where the origin would be top left.

On Sun, Jun 7, 2015 at 11:41 AM, Erlend Langseth <3rlendhl@gmail.com> wrote:

> Hi!
>
> I'm trying to render text, using FreeType 2. My problem is in offsetting
> each glyph with respect to their own origin. In this mail, with "offset", I
> refer to what is called bearingX and bearingY in this
> <http://www.freetype.org/freetype2/docs/tutorial/metrics.png>
> illustration.
>
> I first render all glyphs, storing necessary metrics, then use the results
> to render text.
> Given an unsigned char c, this is how I render glyphs, and need to obtain
> the correct offsets (C++):
>
> FT_Face face;
>
> if (!FT_Load_Char(face, c, 0)) {
>       if (!FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL)) {
>              if (!FT_Get_Char_Index( face, c )) continue;
>                    // Set offset of glyphs accessing face->glyph here.
>
> I have tried to use face->glyph->bitmap_left (and bitmap_top), and also
> face->glyph->metrics.horiBearingX / 64.0f (and Y), but the results always
> look arbitrary:
>
> http://a.pomf.se/iudwvo.png      And with inverted yoffset:
> http://a.pomf.se/jlkngl.png
>
> This <https://bpaste.net/show/4c7b4fa88e67> is how I render text at the
> moment (no kerning yet). (Additional question: is width, height, xadvance,
> yadvance, xoffset and yoffset all metrics I need to render text?)
>
> On lines 27 and 28, you see how I apply the offset. size is the pixel size
> of the font (note that I "normalize" the metrics by dividing by pixel size
> in the first place).
>
> Thanks in xadvance!
>

[Attachment #5 (text/html)]

<div dir="ltr">I solved it. It was just a mismatch between OpenGL&#39;s normalized \
device coordiante system, where the origin is at (-1, -1) and the coordinate system \
of the glyph, where the origin would be top left.<br></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 7, 2015 at 11:41 AM, \
Erlend Langseth <span dir="ltr">&lt;<a href="mailto:3rlendhl@gmail.com" \
target="_blank">3rlendhl@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div \
dir="ltr"><div><div><div><div><div><div><div>Hi!<br><br></div>I&#39;m trying to \
render text, using FreeType 2. My problem is in offsetting each glyph with respect to \
their own origin. In this mail, with &quot;offset&quot;, I refer to what is called \
bearingX and bearingY in <a \
href="http://www.freetype.org/freetype2/docs/tutorial/metrics.png" \
target="_blank">this</a> illustration.<br><br></div><div>I first render all glyphs, \
storing necessary metrics, then use the results to render text.<br></div>Given an \
unsigned char c, this is how I render glyphs, and need to obtain the correct offsets \
(C++):<br><br>FT_Face face;<br><br>if (!FT_Load_Char(face, c, 0)) {<br>           if \
(!FT_Render_Glyph(face-&gt;glyph, FT_RENDER_MODE_NORMAL)) {<br>                       \
if (!FT_Get_Char_Index( face, c )) continue;<br></div>                                \
// Set offset of glyphs accessing face-&gt;glyph here.<br><br></div>I have tried to \
use face-&gt;glyph-&gt;bitmap_left (and bitmap_top), and also \
face-&gt;glyph-&gt;metrics.horiBearingX / 64.0f (and Y), but the results always look \
arbitrary:<br><br><a href="http://a.pomf.se/iudwvo.png" \
target="_blank">http://a.pomf.se/iudwvo.png</a>           And with inverted yoffset: \
<a href="http://a.pomf.se/jlkngl.png" \
target="_blank">http://a.pomf.se/jlkngl.png</a><br><br></div><a \
href="https://bpaste.net/show/4c7b4fa88e67" target="_blank">This</a> is how I render \
text at the moment (no kerning yet). (Additional question: is width, height, \
xadvance, yadvance, xoffset and yoffset all metrics I need to render \
text?)<br><br></div>On lines 27 and 28, you see how I apply the offset. size is the \
pixel size of the font (note that I &quot;normalize&quot; the metrics by dividing by \
pixel size in the first place).<br><br></div>Thanks in xadvance!<br></div> \
</blockquote></div><br></div>



_______________________________________________
Freetype mailing list
Freetype@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic