I have some basics set up in my game but I came to a point where I want to include font rendering (initially for debug output to the screen).
Looking at various tutorials and the SDL_ttf library I require clarification on something. The SDL_ttf will give you an SDL_Surface which you can then create a texture from to allow for hardware rendering. The whole process though requires a font file loading.
My main question is - Is it safe to leave the font file open until the font is no longer needed?
I saw a tutorial which closed the font file immediately after creating the SDL_Texture. My thoughts were if this was used for frequently updated text e.g. a frame rate counter, this would be highly inefficient and it would be better to hold the font file open (assuming there is no negative impact).
And the follow up from this would be if the font file is held open, would it be locked so no other font could use it?
From feedback it is now clear that when opening a font file using TTF_OpenFont the file on disk does not remain open. Therefore once the font has been opened it is in memory for use as normal and can then be released with TTF_CloseFont when no longer required.
The initial question was a result of confusion around the file remaining open (or not as it turned out) after the call to TTF_OpenFont
Credit to #Armin for this
Related
I'd like to use UrhoSharp to build a command-line tool that draws some stuff and saves the output to a PNG file.
I've figured out how to draw what I want in a window, and I can save it (after waiting for a couple of updates) with Graphics.TakeScreenshot. But I'd prefer it to run without showing a window at all, so that I can use the tool in my build pipeline without windows popping up all the time.
I've also figured out that I can start the Urho engine in headless mode by adding AdditionalFlags = "-headless" to my ApplicationOptions. But I can't figure out how to trigger the 3D engine to run in this case, or where the output goes. It looks like the graphics subsystem may not be initialized at all in this mode.
Is there a way to make UrhoSharp render into an offscreen buffer of a specified size? Alternatively, it might be okay if I simply keep the window hidden; is there a portable way to do that?
After some digging through the UrhoSharp and Urho3D source, it looks like this is not possible:
In headless mode, no GPU context is created ("headless" means no GPU, not just no window)
In normal mode, an SDL window is always created. SDL has no portable mechanism for creating a windowless GPU context
I can create my own window before initializing Urho and pass in the OS window handle; but:
For a start that needs some OS-specific code
It has to be an SDL_Window, not any kind of offscreen buffer
I think the best that can be done without modifying Urho and/or SDL is to hide the window as soon as possible. I'm not sure if I can avoid having the window flash onscreen briefly. If I can figure it out I'll comment further here!
I'm using SFML 1.6 to make a small game, and I need to display some text, so I use the sf::String class. The problem is, when I increase the size to 96pt, the edges appear a little blurry. When I increase the size of text in Microsoft Word though, it appears very clean and has crisp edges. Is there a way to do that with SFML?
Looking at the SFML sources, it appears that it is using the embedded Arial font. Yes, it can also load the .ttf font file, but I guess you didn't load it yet.
So the problem is tht SFML tries to scale the fixed-size bitmap when you are rendering the text.
To get rid of the aliasing try following this sample http://www.sfml-dev.org/tutorials/1.4/graphics-fonts.php and load the .ttf manually.
I am working on an embedded platform (STM32F407) with a TFT LCD as a display (480x800px) and would like to make my user interface somewhat customizable to the end user. I figured the best source of fonts would be windows compatible as their the most common.
My current implementation uses my own custom drawn font in a binary format and a descriptor table giving the character width and ascii value but having to draw my own font bit by bit is tedious.
I would like to read in a True Type Font file from an SD card and be able to use the different sized glyphs inside it but I have not seen a strait forward implementation on how to actually achieve this magic. Can somebody point me to a good c/c++ example of what I am looking for?
Even better as a way to iron out the kinks I would like to make a simple gcc command line program that will print out my input with a selected font using '#' as pixels. That way I can just worry about implementation and not any other random bugs that might pop up.
Can anybody help me out?
Perhaps you can use the Freetype library.
As duskwuff says: TTF is primarily a vector format, would need to write a renderer. Better off using an image file to define the font, or using a bitmap font format like FNT (Windows) or BDF (UNIX).
Here is my answer to my own question: AngelCode's BMFont & Useage. This makes choosing selective characters from the installed char set, mix in a font and exports an image with a map file to each character. Simple to use.
I'm using SFML 1.6 to make a small game, and I need to display some text, so I use the sf::String class. The problem is, when I increase the size to 96pt, the edges appear a little blurry. When I increase the size of text in Microsoft Word though, it appears very clean and has crisp edges. Is there a way to do that with SFML?
Looking at the SFML sources, it appears that it is using the embedded Arial font. Yes, it can also load the .ttf font file, but I guess you didn't load it yet.
So the problem is tht SFML tries to scale the fixed-size bitmap when you are rendering the text.
To get rid of the aliasing try following this sample http://www.sfml-dev.org/tutorials/1.4/graphics-fonts.php and load the .ttf manually.
In our MDI application - which is written in MFC - we have a function to save a screenshot of the MDI client area to file. We are currently doing a BitBlt from the screen into a bitmap, which is then saved. The problem is that some of the MDI child windows have their content rendered by OpenGL, and in the destination bitmap these areas show up as blank or garbled.
I have considered some alternatives:
- Extract the OpenGL content directly (using glReadPixels), and draw this to the relevant portions of the screen bitmap.
- Simulate an ALT+PrtScr, since doing this manually seems to get the content just fine. This will trash the clipboard content, though.
- Try working with the DWM. Appart from Vista and Win7, this also needs to work on Win2000 and XP, so this probably isn't the way to go.
Any input will be appreciated!
The best way to get a bitmap from an OpenGL window is to draw the content to a bitmap 'window'. See PFD_DRAW_TO_BITMAP for more information on how to do this.
If you want to go with the Alt+PrtScr way, you have to consider that many users have their own print screen tool installed which reacts on that very same hotkey. So you can't be sure that this hotkey will copy the content to the clipboard. It may just open the window of the installed print screen tool/utility.
Use the glReadPixels() approach. This question is asked quite often, here, on the gamedev.net forums and on other places, so google should show you code samples easily, but the glReadPixels() approach is the generally recommended approach.
Simulating keypresses is a recipe for disaster, I would stay away from that.