hello,
I am quite new to the SLD_ttf lib and I have been following the Lazy Foo' tuts on it but the text is not appearing. I have found out that it is not loading the font as I have added in the code saying if it has failed.
Code:
font = TTF_OpenFont( "lazy.ttf", 28 );
if( font == NULL )
{
return false;
}
i have saved this font in the project (project name/project name/lazy.ttf). I am wondering if any1 knows how to fix this problem
Have you initialized SDL_ttf? (using TTF_Init() ? )
Also, make sure to have the font in the same directory as the generated executable, not just as your project. So if your generated executable is in, e.g. : " project name/project name/Debug/ ", your font should be :
In VS, which I assume the OP is using due to the typical project path, the working directory is usually not the one the executable is in. By default, it's the directory the project file is in.
What I would suggest doing is creating a file in your code that you know doesn't exist
ofstream out("test");
then checking to see whether that file is created in the same directory where lazy.ttf is residing. If it is, then lazy.ttf is in the correct directory. If it's not, then lazy.ttf is not in the correct directory.
Good point cire, I agree, that would definitely clarify the issue. I am using Visual Studio myself and I have noted that running a compiled program from inside Visual Studio and running it outside of Visual Studio can produce different behavior regarding the working directory.
I find my default working directory for a VS project is specified in Project Properties -> Configuration Properties -> Target Name (which is set as the macro $(ProjectName) by default).
I find my default working directory for a VS project is specified in Project Properties -> Configuration Properties -> Target Name (which is set as the macro $(ProjectName) by default).
Well, that's the name of the executable file. For the Junk project $(ProjectName) is "Junk"
The working directory is found in
Project Properties -> Configuration Properties -> Debugging -> Working Directory
and it is the macro $(ProjectDir) by default. Of course, you can check the value of the macro by clicking on the dropdown list for the option and choosing <edit> then clicking the Macros >> button in the resulting dialog. The macros and what they expand to are all listed. You just have to scroll down to the one you want to find.
And yes, if you run the executable outside of the IDE, the working directory will be the directory the executable is in.
This example simply opens and closes a file. [...] If the constructor is not successful in opening the file, the object is still created although no file is associated to the stream buffer and the stream's failbit is set (which can be checked with inherited member fail).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// using ofstream constructors.
#include <iostream>
#include <fstream>
usingnamespace std;
int main () {
ofstream outfile ("test.txt");
// >> i/o operations here <<
outfile.close();
return 0;
}
//Initialize SDL_ttf
TTF_Init();
//declare a TTF_Font
TTF_Font *font;
//load the font
font = TTF_OpenFont( "c:\\users\\user1\\desktop\\lazy.ttf", 28 );
//...
//Close the font
TTF_CloseFont(font);
//Quit SDL_ttf
TTF_Quit();
// and then probably followed by SDL_Quit();
I don't think SDL_image has initialization and quit functions.
ive got another problem with SDL :(
i made the screen bigger (640 x 480 to 1920 x 1080) which worked but then when an object moves outside the original area (640 x 480) the object seems to not get rid of its old position. it still moves but make a long line of where it has previously been. any ideas on how to fix it?
ive got another problem with SDL :(
i made the screen bigger (640 x 480 to 1920 x 1080) which worked but then when an object moves outside the original area (640 x 480) the object seems to not get rid of its old position. it still moves but make a long line of where it has previously been. any ideas on how to fix it?
Sounds like the screen is not cleared properly and frames are drawn on top of each other. It probably has to do with how you call SDL_SetVideoMode(). See the SDL_RESIZABLE flag for SDL_SetVideoMode().