• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
DaShwimp

TTF Problem

5 posts in this topic

Hello again
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? [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

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 settings
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//The surfaces
SDL_Surface *background = NULL;
SDL_Surface *message = NULL;
SDL_Surface *screen = NULL;

//The event structure
SDL_Event event;

//The font that's going to be used
TTF_Font *font = NULL;

//The color of the font
SDL_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]
0

Share this post


Link to post
Share on other sites
[quote name='DaShwimp' timestamp='1344649976' post='4968284']
Hello again
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? [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Thanks!

[/quote]

The ttf file needs to be where the executable can find it. Is it in the same directory as the exe? Edited by Lazy Foo
0

Share this post


Link to post
Share on other sites
The SDL_ttf.dll and libfreetype-6.dll are in the same directory as the .exe., if those are the ones you're talking about.
There is another zlib1.dll that came with ttf but Im using the one that came with SDL_image, if that matters.
Thanks for the reply :) I love your tutorial so far!
0

Share this post


Link to post
Share on other sites
[quote name='DaShwimp' timestamp='1344649976' post='4968284']
Hello again
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? [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Thanks!

[/quote]

do you have the font file in the save directory as the project file? by font file i mean the actual lazy.ttf file, not the dll's. if the error is due to the program being unable to load the font file it means the compiler cant find the lazy.ttf file. just make sure the lazy.ttf file is in the same directory as your compiler's project file if you are running the program through the compiler. if you run it using the .exe file put the lazy.ttf file in the same directory as the .exe.
1

Share this post


Link to post
Share on other sites
Wow Im sorry xD I cant believe I didnt think of it before.
Thank you! I downloaded your media and source for that tutorial and right there was the .ttf to put in xP

Thanks again. Hopefully I wont need to post super often xP
0

Share this post


Link to post
Share on other sites
[quote name='DaShwimp' timestamp='1344663544' post='4968341']
Wow Im sorry xD I cant believe I didnt think of it before.
Thank you! I downloaded your media and source for that tutorial and right there was the .ttf to put in xP

Thanks again. Hopefully I wont need to post super often xP
[/quote]

no problem, i also had the same problem when i was first learning SDL(although im still learning).
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0