Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: overlaying text onto graphics  (Read 1947 times)

0 Members and 1 Guest are viewing this topic.

Andres

  • Newbie
  • *
  • Posts: 2
    • View Profile
overlaying text onto graphics
« on: August 14, 2014, 08:12:46 am »
While I was searching for some text libraries for linux I came upon SFML and it really looks nice. This appears to have one of the cleanest and nicest OO/C++ APIs that I have ever seen.  Very nice indeed.

I am currently developing a video application that uses several camera feeds. My code directly deals with the raw video data usually in RGB 24 bit format.  I need to be able to overlay text on top of the video. I have the overlay part working in that I have picture-in-picture working and now I want to add alpha blended text overlays on top of the video.

What I am looking for is a way to generate the rendered text in a raw buffer so I can overlay it on top of my video and I am wondering if this API will work for me.  However, it appears that this API is so well designed that I do not see how I can access the raw buffer pointers of the sf::Font and sf::Text classes.  I need to be able to render the dynamic text (which it appears SFML will do very nicely) and then have access to a pointer to the internal buffer of the rendered text so I can alpha blend the rendered text buffer onto my video buffer.  I have all of the alpha blending working--all I need is the text rendering part.

Can this be easily done with the SFML libs?

Thanks,
-Andres

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: overlaying text onto graphics
« Reply #1 on: August 14, 2014, 09:17:08 am »
I'm not fully sure what you want to achieve with alpha blending. Can you explain that a bit more?
So are your video feeds not rendered with SFML?

The text information lives on the GPU, so you want ever get a "CPU" pointer. What you could do - not sure if it's enough - is render things on a render texture, that way you can for sure access the texture information.

If you explain more, maybe someone else with more deeper understanding of the inners of SFML will be able to help you further. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: overlaying text onto graphics
« Reply #2 on: August 14, 2014, 11:11:34 am »
What you mean is that you need to render text into a memory buffer, because drawing it on top of your video uses something else than SFML, right?

If this is what you want to do, then you can, as eXpl0it3r said, render to a sf::RenderTexture, copy it to a sf::Image and then access the pixel buffer. But this is not optimal, I'm sure you can find text libraries that can rasterize glyphs directly in memory, without having to render it with OpenGL and the graphics card ;) For example, SFML uses FreeType for rasterizing glyphs.
Laurent Gomila - SFML developer

Andres

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: overlaying text onto graphics
« Reply #3 on: August 14, 2014, 05:15:22 pm »
Thank you for the replies.

I currently use the Intel IPP library for my image processing. It has routines for alpha blending one image on top of another image. I have that all implemented and working in my code--I can overlay a smaller camera feed on top of a larger background camera feed. I am not currently using SFML so none of my current code uses SFML for any rendering.

I did not realize that text is render in the GPU. My application is a headless multi-Xeon server app and currently does not have a graphics card installed in it. In my code development, I only use the motherboard graphics to display the System Monitor so I can monitor the thread usage. (I have considered adding a dedicated GPU for image processing if the Xeons run out of cycles--but for now I still have plenty of unused cycles because the Xeons are all multi-core).

Laurent, you are correct in that the alpha blending code is not SFML as I explained above.  Currently my need is for a text rendering library. You have stated my intent more clearly than I did in that the need is to be able to render text directly to memory. The SFML API is so nicely designed that I was attracted to it and was wondering if it would fit my needs.

Thanks again for all your counsel and help.

-Andres