SFML community forums
Help => General => Topic started by: tom64 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.
-
You can draw to a texture (sf::RenderTexture) and retrieve the result in your own pixel array.
-
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?
-
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().
Also, could I do all of this without having to import OpenGL?
?? ???
-
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.
-
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?
-
Because I may be using DirectX and don't want to also load OpenGL, especially if it might interfere with DX.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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?
-
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?
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?
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.
-
I'm gonna try and see if maybe DirectX has something useful.
-
if maybe DirectX has something useful.
;D
So you really think DirectX wouldn't be able to draw some text? Have you ever played a DirectX game?
-
So you really think DirectX wouldn't be able to draw some text? Have you ever played a DirectX game?
There's a difference between being able to render textured quads that represent glyphs, and loading those glyphs from a font file, rasterizing them, and laying them out correctly ;)
OpenGL is only able to do the first thing, that's why we need FreeType. tom64 needs a similar tool, but chances are that DirectX utilities already provide one, based on GDI.
-
I changed my mind. I'm going to export the fonts manually as images and load them myself. I checked DX it cannot be done without getting the data from video memory, which basically means:
1) It will be slow
2) If I want to change API it won't work because I can't be switching back and forth between APIs.
It's always frustrating to me when it's easier for me (a beginner) to do something manually from scratch the long way, than to use someone else's library (freetype) which is supposed to make the job simpler.
Oh well.
-
I checked DX it cannot be done without getting the data from video memory
Why? If you want to draw the text, it can stay in video memory. I thought you just wanted to draw text, which DirectX utilities (should) make easy. If you want to do different things, please explain.
It's always frustrating to me when it's easier for me (a beginner) to do something manually from scratch the long way, than to use someone else's library (freetype) which is supposed to make the job simpler.
FreeType is not impossible to use, just spend a few hours trying to understand how things work (especially font metrics and how to layout the glyphs), and you'll get something working quickly. And it's a good things to know in general, anyway.
Look at SFML source code, or one of the millions other examples that you can find with Google.
If you're stuck with Windows (since you use DirectX), you can also use GDI. It could be a little simpler than FreeType, since it has functions to draw complete strings (so you don't have to lay out glyphs yourself).
-
Alright.. I will give it a long hard try to get freetype to work. If I have any problems I'll ask here.
UPDATE: I only just started the tutorial and already have problems.
EDIT: No screw it, it's too hard. I can't understand what they've typed. Their tuts has errors all over the place. It's not a tut for a C++ beginner. I'll do it the long way, at least I know how.
-
It's always frustrating to me when it's easier for me (a beginner) to do something manually from scratch the long way, than to use someone else's library (freetype) which is supposed to make the job simpler.
You make it sound like it's the fault of others, that with your quite basic understanding of C++ and programming in general, can't understand the API and docs of other libraries.
Programming can be quite frustrating at times and one often wishes to get a simple approach to thongs, but in the end it's not a problem of the library, but a lack of knowledge on ones own side. ;)
Doing things on your own can teach you a lot and since you'll run into similar problems the other libraries had as well and might slowly start to understand how those library work, but it will probably take longer to get a properly working version and depending on the complexity you'll fail. :)
-
If you want something which is extremely simple (but limited), you can try this code:
http://www.nothings.org/stb/stb_truetype.h
-
It's always frustrating to me when it's easier for me (a beginner) to do something manually from scratch the long way, than to use someone else's library (freetype) which is supposed to make the job simpler.
You make it sound like it's the fault of others, that with your quite basic understanding of C++ and programming in general, can't understand the API and docs of other libraries.
Programming can be quite frustrating at times and one often wishes to get a simple approach to thongs, but in the end it's not a problem of the library, but a lack of knowledge on ones own side. ;)
Doing things on your own can teach you a lot and since you'll run into similar problems the other libraries had as well and might slowly start to understand how those library work, but it will probably take longer to get a properly working version and depending on the complexity you'll fail. :)
Well to be honest, it is (half) the fault of others. The better someone is at programming, the worse they seem to be at tutoring and making good (simple/instinctive) libraries. If someone makes a tutorial and I do the exact same thing as them and it doesn't work, then it is a bad tutorial. And if I also don't understand it then it's even worse. I have seen some people that are very good and very bad at it. I think there would be many more, and good programmers out there if people designed their libraries and tuts a bit better. It's bad enough computers can be a pain in the butt, but that doesn't mean tuts and libraries should be.
If you want something which is extremely simple (but limited), you can try this code:
http://www.nothings.org/stb/stb_truetype.h
Thanks Laurent, I'll give that a shot and see how it goes.
I can't get that to work either... It's humorous in a way:
"Complete program (this compiles)"
No it doesn't! ;D >:(
A ton of errors all over the place.
"Complete program: print "Hello World!" banner, with bugs"
Great!
"Incomplete text-in-3d-api example"
How incomplete?
"// This uses a very crappy packing."
LOL
"I provide an API for this, but I don't recommend it"
Me too!
The world of programming, (and computers) is in need of a revolution I think...
A file/lib that is buggy which I don't understand is the last thing a beginner needs in their program. I'll go back to my original idea of sprite-fonts.
You may close this thread now. I'm done here.
-
Well to be honest, it is (half) the fault of others. The better someone is at programming, the worse they seem to be at tutoring and making good (simple/instinctive) libraries.
By that logic, Laurent must make some pretty horrible tutorials... :o Strange that you seem to understand them.
If someone makes a tutorial and I do the exact same thing as them and it doesn't work, then it is a bad tutorial.
Do you really think the people over at FreeType provided example code that still doesn't work after all the years FreeType has been around? There are probably millions of users of FreeType and they all learnt more or less from those pages if not from some other derived tutorial somewhere. Accusing them for your own errors without absolute certainty is just plain rude.
And if I also don't understand it then it's even worse. I admit that I'm not good at reading tuts and other peoples code, but I have seen some people that are very good and very bad at it.
Yeah, I've seen these people too. And I'm more annoyed at these "good" tutorials, because they seem to want to teach you everything about C or C++ as well as the library the tutorial should be about. Face it, the tutorial should only be concerned with getting people familiar with the library. If you can't program in C or C++ stop reading it and go learn the basics first. There is no "shortcut" way to learn everything at the same time. It would be annoying for experienced programmers who just want to know the essence of the libraries and it would be useless for beginners who would be overloaded with information and just forget most of it after copy&pasting or even worse, not understanding what belongs to the library and what to the programming language.
I think there would be many more, and good programmers out there if people designed their libraries and tuts a bit better. It's bad enough computers can be a pain in the butt, but that doesn't mean tuts and libraries should be.
This is so wrong... A good programmer isn't one who can follow tutorials and achieve something in the short term. A good programmer is one who strives to get a better understanding of how to write good code, who cares about the language and all its concepts, who is eager to learn more by themselves without people holding their hands. A good programmer is one who doesn't rely on tutorials to learn something, but instead reads specifications and library/language reference documents to make their own deductions on how best to do something. Whoever thinks they are good programmers because they proved to themselves that they can follow a few tutorials will cost their employer more money than they think and really should not ever be allowed to contribute to FOSS in any way. There are too many of those out in the wild already if you ask me. I know from first hand experience.
If you ask me, it's the bad libraries that make good programmers. Because they need to invest more effort to get something working, and as everybody knows, practice makes perfect. I am not saying that whoever uses well written libraries is not a good programmer. Because the libraries are written so well, they don't leave room for error, hence the user will not learn much because there is simply nothing that can be done wrong.
What I still don't understand is this: You seem to want to manipulate a DirectX drawing surface and draw some arbitrary buffer of pixels containing some font of your choosing onto it. The effort you have to put into that is significantly more than the effort you would have to invest in getting FreeType working properly. I'm just curious, where did you learn to use DirectX? I find Microsoft's documentation and naming conventions more daunting than those of FreeType IMHO.