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

Author Topic: Loading fonts to a custom surface?  (Read 8048 times)

0 Members and 1 Guest are viewing this topic.

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Loading fonts to a custom surface?
« on: April 09, 2013, 12:44:33 pm »
If I make my own surface (a 2D pixel array), is it possible to draw text to that surface instead of directly to the window?

Or if I could at least get the pixel information about the 'text' then I could just place it on-top of my surface myself?

For example, if I'm using DirectX and have my own surface that gets sent to a backbuffer (to be displayed onto the screen), if I wanted to draw text on the screen I would either have to make sure SFML can draw text ontop of the backbuffer (unlikely if I had to guess since SFML is OpenGL), otherwise I was hoping SFML can read font files and text and provide the pixel info so I can place the text ontop myself.

Thanks in advance,
Tom.
« Last Edit: April 09, 2013, 12:51:22 pm by tom64 »
Newbie to C++ and SFML

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Loading fonts to a custom surface?
« Reply #1 on: April 09, 2013, 12:49:22 pm »
You can draw to a texture (sf::RenderTexture) and retrieve the result in your own pixel array.
Laurent Gomila - SFML developer

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #2 on: April 09, 2013, 12:54:26 pm »
You can draw to a texture (sf::RenderTexture) and retrieve the result in your own pixel array.
Would that also provide me the total dimensions (w, h) of the entire string in pixels?

Also, could I do all of this without having to import OpenGL?
Newbie to C++ and SFML

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Loading fonts to a custom surface?
« Reply #3 on: April 09, 2013, 12:57:12 pm »
Quote
Would that also provide me the total dimensions (w, h) of the entire string in pixels?
The dimensions of the text are easy to get with sf::Text::getGlobalBounds().

Quote
Also, could I do all of this without having to import OpenGL?
?? ???
Laurent Gomila - SFML developer

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #4 on: April 09, 2013, 01:26:28 pm »
Quote
Also, could I do all of this without having to import OpenGL?
?? ???
[/quote]

Sorry, it's just that SFML is so closely connected with OpenGL I don't know what parts of it will include/require it or not. I guess the font thing is completely separate then.
Newbie to C++ and SFML

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Loading fonts to a custom surface?
« Reply #5 on: April 09, 2013, 02:02:37 pm »
If you draw something, you use OpenGL behind the scenes. There's no "pure software drawing". But you shouldn't worry about that... what's your problem with OpenGL?
Laurent Gomila - SFML developer

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #6 on: April 09, 2013, 02:28:28 pm »
Because I may be using DirectX and don't want to also load OpenGL, especially if it might interfere with DX.
Newbie to C++ and SFML

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Loading fonts to a custom surface?
« Reply #7 on: April 09, 2013, 02:31:30 pm »
But then what do you use SFML for, if you already draw with DirectX?

SFML will create an OpenGL context for any window that you create with it. But it doesn't interfere with DirectX, unless you do weird things with them.
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Loading fonts to a custom surface?
« Reply #8 on: April 09, 2013, 04:17:18 pm »
http://en.sfml-dev.org/forums/index.php?topic=10975.msg76143#msg76143
I didn't know I had an inherent ability to tell the future :P.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #9 on: April 10, 2013, 12:26:00 am »
http://en.sfml-dev.org/forums/index.php?topic=10975.msg76143#msg76143
I didn't know I had an inherent ability to tell the future :P.
You jinxed it. You monster.
I use the latest build of SFML2

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #10 on: April 10, 2013, 02:08:26 am »
But I thought maybe I could just use some of the 'modules' of SFML to do smaller stuff like loading only the fonts and getting the pixel info without the other stuff loaded also.
Newbie to C++ and SFML

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #11 on: April 10, 2013, 03:32:55 am »
That makes no sense.. Freetype will give you the raw pixel data, SFML uses freetype's raw data to draw text WITH OpenGL.

Take a look at SFML source, namely at Font.cpp and Glyph.cpp I believe.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Loading fonts to a custom surface?
« Reply #12 on: April 10, 2013, 07:59:18 am »
There are plenty of other ways to render text to a pixel array. If you use DirectX you may even use Win32 functions directly, they are very simple to use and you'll find many examples on the internet. Maybe DirectX utils even have helper functions wrapped around Win32 code.
Laurent Gomila - SFML developer

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #13 on: April 11, 2013, 03:18:38 am »
Does anyone understand how to use freetype 2?

I'm reading the documentation but its kinda over my head..

All I want to do is load a font from HDD into memory and then write/draw to custom surface. I don't get why they complicate the library so much. I'm surprised anyone can understand this.

Would it be easier for me to just use the files/code/functions from SFML?
« Last Edit: April 11, 2013, 03:28:53 am by tom64 »
Newbie to C++ and SFML

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Loading fonts to a custom surface?
« Reply #14 on: April 11, 2013, 08:14:18 am »
Quote
I'm reading the documentation but its kinda over my head..
It's so widely used, can't you find simpler tutorials, other than the official documentation?

Quote
All I want to do is load a font from HDD into memory and then write/draw to custom surface
There are probably better ways of doing this if you use DirectX / Win32, as I said earlier. Have you looked at the examples in the DirectX SDK?

Quote
Would it be easier for me to just use the files/code/functions from SFML?
SFML use of FreeType is fairly simple, you should definitely have a look at the sources.
Laurent Gomila - SFML developer