Text Rendering In OpenGL // OpenGL Tutorial #46.1

Поделиться
HTML-код

Комментарии • 39

  • @OGLDEV
    @OGLDEV  5 месяцев назад

    Clone the sources:
    git clone --recurse-submodules github.com/emeiri/ogldev.git
    If you want to get the same version that was used in the video you can checkout the tag 'TUT_46_FREETYPEGL'.
    Build on Windows:
    Open the Visual Studio solution: ogldev\Windows\ogldev_vs_2022\ogldev_vs_2022.sln
    Build the project 'OpenGL Tutorials\Tutorial46_FreetypeGLDemo'

  • @cacheman
    @cacheman Год назад +2

    For comparison, if you _just_ want to draw basic text with OpenGL, using Freetype to load and render out (SDF) glyphs is maybe 100ish lines of code plus a 10-line shader.
    Freetype is pretty easy to work with.

    • @OGLDEV
      @OGLDEV  Год назад

      Thanks.

    • @OGLDEV
      @OGLDEV  2 месяца назад

      Sure, but FreetypeGL is based on Freetype and provides more bells and whistles. I dare say that it will take less time for most people to integrate FreetypeGL instead of Freetype directly.

  • @nimrod7785
    @nimrod7785 Год назад

    Thank you for the video. I love your content even if I work on Metal. I had to do everything from scratch for text rendering since libraries are not a thing in Metal.

    • @OGLDEV
      @OGLDEV  Год назад +1

      Thanks! Hope to get to Metal some day...

    • @nimrod7785
      @nimrod7785 Год назад +1

      @@OGLDEV all the same apart from the initial setup. It will be nothing for you to catchup!

  • @EgorChebotarev
    @EgorChebotarev Год назад +1

    interesting and important topic in computer graphics

  • @Vicente_Lopes_Senger
    @Vicente_Lopes_Senger Год назад +2

    I like to do everything from scratch. In my current indie game project I have hand drawn the font characters to a texture (atlas) in Gimp. Then I set structs with the characters info containing their UV coords and pointer to their opengl texture. So I have an array of reusable text structs that can contain a maximum of 2048 characters per text. Then I have functions to create texts that find a free text in the text array and set them to the desired text. When drawing the text I merge all character and UI sprites into a single mesh with their correct draw order, then I can draw all of the UI and text with one draw call. I also use vertex colors on the character's and UI sprites, so I can set colors and gradients to the the text and sprites individually still keeping them in a single draw call. Because I do it all in a single draw call I can draw about 90k sprites per frame at 60fps in my reasonably old (10+ years old) PC. (I'm working in C)

    • @OGLDEV
      @OGLDEV  Год назад

      Nice, but that does sound like quite a lot of work...

    • @Vicente_Lopes_Senger
      @Vicente_Lopes_Senger Год назад

      ​@@OGLDEV Yes, I guess. It took me about a week to do, including drawing the font characters (all letters upper and lowercase, numbers and the useful symbols), plus more of bug fixing (pointer/array issues, etc). But I think when you are making a quality game this may be important (maybe it's not). I try to think of a hypothetical situation where I have to draw hundreds or even thousands of sprites, for instance if I have multiple inventory windows open on the screen at the same time with a hundred slots of inventory each and every inventory slot is a sprite and every item inside each slot is another sprite on top of that. If you think about these cases, you can imagine situations where having the most optimal way to draw the sprites would matter. And having my own system to draw text working with the other UI sprites allows me to have parts of some windows overlapping parts of texts in other windows and other complicated situations like that without giving me too much headache. Also knowing all the systems allows me to optimize or fix them with relative ease if I need to. So I try to make everything I can myself.

    • @OGLDEV
      @OGLDEV  Год назад +1

      Well, I guess one week total including debugging is not that bad. I agree that if this is a major part of the system and a potential bottleneck then writing a system tailored for your needs is preferable.

    • @Vicente_Lopes_Senger
      @Vicente_Lopes_Senger Год назад

      @@OGLDEV Yes, I don't think that is too much effort for something that could potentially be used by players for years to come (hopefully) . I like to do everything I can custom, so it has a "bespoke", a "handmade" feel to it. I find these types of logical systems fairly easy to do, and I don't mind putting the extra effort to make them good. Usually I struggle more with math, linear algebra and trigonometry. I'm not good at math, so 3D math problems are the sort of things I can spend a lot of time on and still not find the solution which is much more frustrating. Your channel is a valuable resource on that front, thanks for the videos.

    • @OGLDEV
      @OGLDEV  Год назад +1

      Glad to help :-)
      Can I ask you what sort of asset file type you are using? I guess you've implemented the loader yourself here too.

  • @samuelappiagyei1327
    @samuelappiagyei1327 4 месяца назад

    when I run the demos it said it can not find or open the file screenshot-util.obj and shader.obj

    • @OGLDEV
      @OGLDEV  4 месяца назад

      Are you referring to my code or the FreetypeGL demos?

  • @laurapeterson146
    @laurapeterson146 Год назад

    Hi, thanks for your content :)
    Does any of your series teach about things like normal maps etc...?
    I mean very basic gamedev concepts but I just would like to know so that I can follow them.
    I tried searching that in both your beginner and intermediate OpenGL series but can't find it.

    • @OGLDEV
      @OGLDEV  Год назад

      I don't have a video on normal mapping but I have a written tutorial on my website: ogldev.org/www/tutorial26/tutorial26.html. I will probably make a video about it in the future.

  • @tematoscybersage5626
    @tematoscybersage5626 5 месяцев назад

    Thank you.
    Wooooah, I tried to use ftgl lib which looks like pretty similar, but it just won't to read lib definitions, I think it is just too old.
    Is it possible to generate vertices from fonts with that library to generate 3D volumetric fonts?

    • @OGLDEV
      @OGLDEV  5 месяцев назад

      You mean with the FreetypeGL library? I don't think you can generate vertices from fonts with that. AFAIK the standard font files are only 2D. If you need a 3D fonts then I guess you need a model for each letter and then render it as usual. I'm pretty sure that someone already modeled most languages and you can simply re-use this work.

    • @tematoscybersage5626
      @tematoscybersage5626 5 месяцев назад

      ​@@OGLDEV Yep, that one that you used.
      Thank you.
      I wasn't able to find similar lib yet. And I was surprised about that, pretty generic feature. Also on Khronos site I saw on page where they show libs for text rendering, that with some of libs they generate 3D text(I can't attach links here).
      Maybe this library encapsulates some functionality of FreeType for this task.
      I think the process of making 3D text from fonts should be next:
      1) filter edges of letter.
      2) make it vertices that forms plane of letter(and optimize it ammount).
      3) duplicate this plane and flip to 3.14 rads and join both planes with perpendicular faces.
      4) and then pack this all in vertex buffer and render as normal 3D model.

    • @OGLDEV
      @OGLDEV  5 месяцев назад

      I would place the font image as a background picture in Blender and simply model it in 2D and then extend it backward to create the 3D volume. Can't tell which method is preferable. Highly depends on how much time you spend developing that algorithm.

    • @tematoscybersage5626
      @tematoscybersage5626 5 месяцев назад

      ​@@OGLDEV yep, I think you right. no sense to spend so much time on it if there is not so much need.
      I think I will be using this freetypeGL lib to put 2d text notes, to explain something in 3D scenes, projecting rectangle with this text texture.
      Yeah, much easier to make some kind of 3D askii table of letters and signs, and pick up needed one by interpreting chars, to render 3D text.
      Thank you)

  • @TiramisuCorleone
    @TiramisuCorleone Год назад

    I was looking to render symbols like integrals on textures with Latex, but it turned out to be too complicated for me.

    • @OGLDEV
      @OGLDEV  Год назад

      Unfortunately, I haven't tried rendering symbols other than text so far. I'm familiar a bit with Latex but I don't know if there's a user friendly library that can take the burden off when it comes to generating a texture with Latex output.

  • @LumenBrewer
    @LumenBrewer 6 месяцев назад

    14:47
    This is where I have problems. I do not know how to correctly input my path to the different directories.

    • @OGLDEV
      @OGLDEV  6 месяцев назад +1

      You can use $(SolutionDir) or $(ProjectDir) as the base where the corresponding file exists (the solution file or the project file, respectively) and use a relative path from there. Whenever I run into such problems I often start with the absolute path (which is easier) and then change it into a relative path (which is more generic).

  • @PaulMetalhero
    @PaulMetalhero Год назад +1

    hahahaa you just reminded me what a nightmare is to program under windows LOL

    • @OGLDEV
      @OGLDEV  Год назад +3

      In some respects, yes, but Visual Studio is very comfortable.

  • @ukr-apelsin-
    @ukr-apelsin- Год назад

    very cool!)

    • @OGLDEV
      @OGLDEV  Год назад +1

      Thanks :-)

  • @AlbertRyanstein
    @AlbertRyanstein 7 месяцев назад

    hey man, house the city now? Ryan, your british friend (ill visit in may for a beer! or coffee with my g/f)

    • @OGLDEV
      @OGLDEV  7 месяцев назад

      afaik it's ok, but you probably know better. The last time I was there was ~5 years ago...