I now have another problem xP with my C++ and SDL.
Im now learning to use the ttf library and Ive linked all the libraries together, and theirs no issues with the compiler trying to find the functions or anything, but when I try to load a font, the ttf_openfont command cant find "lazy.ttf" and returns null, so I end up with the message that the program returned 4, meaning the font failed to load.
Any help as to why the program cant find the font?
Thanks!
Heres the source for it:
[source lang="cpp"]//The headers#include "SDL/SDL.h"#include "SDL/SDL_image.h"#include "SDL/SDL_ttf.h"#include <string>//Screen settingsconst int SCREEN_WIDTH = 640;const int SCREEN_HEIGHT = 480;const int SCREEN_BPP = 32;//The surfacesSDL_Surface *background = NULL;SDL_Surface *message = NULL;SDL_Surface *screen = NULL;//The event structureSDL_Event event;//The font that's going to be usedTTF_Font *font = NULL;//The color of the fontSDL_Color textColor = { 255, 255, 255 };SDL_Surface *load_image( std::string filename ){ //The image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image loadedImage = IMG_Load( filename.c_str() ); //If the image loaded if( loadedImage != NULL ) { //Create an optimized image optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); } return optimizedImage;}bool init(){ //Initialize all SDL subsystems if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return false; } //Set up the screen screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); //If there was an error in setting up the screen if( screen == NULL ) { return false; } //Initialize SDL_ttf if( TTF_Init() == -1 ) { return false; } //Set the window caption SDL_WM_SetCaption( "TTF Test", NULL ); //If everything initialized fine return true;}bool load_files(){ //Load the background image background = load_image( "background.png" ); //Open the font font = TTF_OpenFont( "lazy.ttf", 28 ); return true;}bool backgroundLoad(){ //If there was a problem in loading the background if( background == NULL ) { return false; } else { return true; }}bool fontLoad(){ //If there was an error in loading the font if( font == NULL ) { return false; } else { return true; }}void clean_up() { //Free the surfaces SDL_FreeSurface( background ); SDL_FreeSurface( message ); //Close the font that was used TTF_CloseFont( font ); //Quit SDL_ttf TTF_Quit(); //Quit SDL SDL_Quit(); }void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ){ //Temporary rectangle to hold the offsets SDL_Rect offset; //Get the offsets offset.x = x; offset.y = y; //Blit the surface SDL_BlitSurface( source, NULL, destination, &offset );}int main( int argc, char* args[] ){ bool quit = false; if( init() == false ) { return 1; } if( load_files() == false ) { return 2; } if( backgroundLoad() == false ) { return 3; } if( fontLoad() == false ) { return 4; } //Render the text message = TTF_RenderText_Solid( font, "The quick brown fox jumps over the lazy dog", textColor ); //If there was an error in rendering the text if( message == NULL ) { return 5; } //Apply the images to the screen apply_surface( 0, 0, background, screen ); apply_surface( 0, 150, message, screen ); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 6; } while( quit == false ) { while( SDL_PollEvent ( &event ) ) { if( event.type == SDL_QUIT ) { quit == true; } } } //Clean up clean_up(); return 0;}[/source]






