PDA

View Full Version : using freetype library with Qt



saman_artorious
28th August 2013, 09:25
To render text with OpenGL, I need the FreeType library. I found out that this library is included with Qt 3rd party packages, located in :
/opt/Qt5.0.1/5.0.1/Src/qtbase/src/3rdparty/freetype/include/freetype

To test if the library is successfully working, I ran the below code snippet:




#include <ft2build.h>
#include FT_FREETYPE_H

FT_Library ft;

if(FT_Init_FreeType(&ft)) {
fprintf(stderr, "Could not init freetype library\n");
return 1;
}


However, I get the following errors:


/usr/local/include/freetype2/freetype/freetype.h:298: error: 'FT_Pos' does not name a type
/usr/local/include/freetype2/freetype/freetype.h:34: error: #include expects "FILENAME" or <FILENAME>
/usr/local/include/freetype2/freetype/freetype.h:656: error: a function call cannot appear in a constant-expression
.
.
.


any hints would be appreciable.

Cheers,

wysota
28th August 2013, 10:21
Your code is invalid and apart from that you're not including proper files thus it does not work.

saman_artorious
28th August 2013, 10:38
Your code is invalid and apart from that you're not including proper files thus it does not work.

Before reading your code, I thought the error was because headers are not included from fresh libraries installed, but rather it includes QT freetype headers. If I want to tell qt not to read its own freetype and read the one installed on the system, how can I do that?

about your post, it is the first time I am dealing with freetype, how can I get a valid code? and what are the proper headers I should add? (by the way I followed this tutorial for the above code file:///home/saman/Desktop/OpenGL%20...en%20world.htm)

wysota
28th August 2013, 10:41
it is the first time I am dealing with freetype, how can I get a valid code?

A good place to start would be reading compiler errors and correcting them, starting with e.g. this line:

#include FT_FREETYPE_H

saman_artorious
28th August 2013, 11:29
A good place to start would be reading compiler errors and correcting them, starting with e.g. this line:

#include FT_FREETYPE_H

Yes, you are right, I change the include directives with their equivalent header files as such:



//#include FT_CONFIG_CONFIG_H
//#include FT_SYSTEM_H
//#include FT_IMAGE_H

#include "freetype2/freetype/ftsystem.h"
#include "freetype2/freetype/config/ftconfig.h"
#include "freetype2/freetype/freetype.h"


That solved my problem Wysota, thanks for your hint.
I still have one more quetions regarding this problem, when I changed the headers to their equivalents, there are two type of header, as an example for

//#include FT_IMAGE_H
I can add both:

#include "freetype2/freetype/ftimage.h" or simply

#include "ftimage.h"

I think this is because, I have this library both on Qt 3rd party and have separately installed it as well. is that correct? So, now how do I know which one is for QWt and which one is what i Installed using apt-get :D.

wysota
28th August 2013, 11:51
Your question is unrelated to Qt. Please post C++ questions in the General Programming forum. If you are having trouble understanding how your compiler works, then a good place to look for information would be to read the compiler manual. Assuming you are using GCC the manual can be found on gcc.gnu.org