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

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

0 Members and 1 Guest are viewing this topic.

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #15 on: April 11, 2013, 02:47:39 pm »
I'm gonna try and see if maybe DirectX has something useful.
Newbie to C++ and SFML

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11039
    • View Profile
    • development blog
    • Email
Re: Loading fonts to a custom surface?
« Reply #16 on: April 11, 2013, 03:22:15 pm »
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?
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: Loading fonts to a custom surface?
« Reply #17 on: April 11, 2013, 03:27:15 pm »
Quote
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.
Laurent Gomila - SFML developer

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #18 on: April 12, 2013, 03:46:22 am »
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.
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 #19 on: April 12, 2013, 08:12:03 am »
Quote
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.

Quote
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).
Laurent Gomila - SFML developer

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Loading fonts to a custom surface?
« Reply #20 on: April 12, 2013, 10:42:10 am »
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.
« Last Edit: April 12, 2013, 11:44:47 am by tom64 »
Newbie to C++ and SFML

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11039
    • View Profile
    • development blog
    • Email
AW: Re: Loading fonts to a custom surface?
« Reply #21 on: April 12, 2013, 02:33:05 pm »
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. :)
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: Loading fonts to a custom surface?
« Reply #22 on: April 12, 2013, 03:02:14 pm »
If you want something which is extremely simple (but limited), you can try this code:
http://www.nothings.org/stb/stb_truetype.h
Laurent Gomila - SFML developer

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: AW: Re: Loading fonts to a custom surface?
« Reply #23 on: April 12, 2013, 03:23:11 pm »
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.

Quote
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.
« Last Edit: April 12, 2013, 04:52:08 pm by tom64 »
Newbie to C++ and SFML

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 #24 on: April 12, 2013, 04:55:43 pm »
Quote
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.

Quote
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.

Quote
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.

Quote
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.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).