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

Author Topic: Is it possible to draw fonts without an SFML window?  (Read 2503 times)

0 Members and 1 Guest are viewing this topic.

GraphicsWhale

  • Full Member
  • ***
  • Posts: 131
    • View Profile
Is it possible to draw fonts without an SFML window?
« on: June 06, 2015, 09:35:11 am »
What I mean specifically is, is it possible to draw them with just OpenGL? The tutorials teach how to draw fonts with SFML's window. But I assume they're drawn with OpenGL behind the scenes, but how?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10881
    • View Profile
    • development blog
    • Email
AW: Is it possible to draw fonts without an SFML window?
« Reply #1 on: June 06, 2015, 10:06:30 am »
The window is your "canvas", where would you draw otherwise?
SFML uses freetype to interprete the font and then creates textures of the font, which then can be used with OpenGL to draw to a window.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

GraphicsWhale

  • Full Member
  • ***
  • Posts: 131
    • View Profile
Re: Is it possible to draw fonts without an SFML window?
« Reply #2 on: June 06, 2015, 10:23:54 am »
I want to be able to use it draw to an OpenGL context that is not created with SFML (and therefore doesn't have an SFML window). So I am limited to OpenGL as the API for drawing (no SFML window to draw to).
« Last Edit: June 06, 2015, 10:25:28 am by GraphicsWhale »

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Is it possible to draw fonts without an SFML window?
« Reply #3 on: June 06, 2015, 01:13:04 pm »
Without wanting to sound like an ass, but if you are not using sfml, this is not the right place to ask.
To show you my goodwill take a look at this:
http://www.learnopengl.com/#!In-Practice/Text-Rendering

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Is it possible to draw fonts without an SFML window?
« Reply #4 on: June 06, 2015, 01:51:51 pm »
Without wanting to sound like an ass, but if you are not using sfml, this is not the right place to ask.
To show you my goodwill take a look at this:
http://www.learnopengl.com/#!In-Practice/Text-Rendering
You know... maybe before completely driving people away from using SFML, you should actually consider everything the poster could have meant if what they said was even slightly ambiguous.

The fact that what is described in that article is exactly what sf::Font conveniently wraps makes your reply less helpful than you might think.

GraphicsWhale, even when rendering the text yourself using OpenGL, you can still use sf::Font as a convenient way to load fonts and get access to its OpenGL glyph texture atlas and metrics.

Here is the sf::Font example slightly modified to demonstrate basic OpenGL interoperation:
// Declare a new font
sf::Font font;
// Load it from a file
if (!font.loadFromFile("arial.ttf"))
{
    // error...
}

const sf::Glyph& glyph = font.getGlyph('A', size, isBold);
float glyphAdvance = glyph.advance;
sf::FloatRect glyphBounds = glyph.bounds;
// The glyph texture coordinates are not normalized (they are in pixels).
sf::IntRect glyphTextureCoords = glyph.textureRect;

sf::Texture::bind(&font.getTexture());

// your OpenGL rendering using the texture here
// normalize the texture coordinates using the actual size of the texture you just bound

sf::Texture::bind(0);

For more information regarding how to use sfml-graphics objects with OpenGL, refer to the documentation of the respective sfml-graphics classes.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Is it possible to draw fonts without an SFML window?
« Reply #5 on: June 06, 2015, 03:32:13 pm »
I didn't want to drive him away from sfml, from my point of view he was specifically asking how to draw fonts in an opengl context which is not created by sfml.

If I understood his intentions wrong(which may very well be) i'm sorry. When I was reading it it didn't seem ambiguous, my bad.