1
0
mirror of https://github.com/krislamo/Trololo synced 2024-09-19 20:20:36 +00:00

Added SDL_ttf and welcome text

This commit is contained in:
Kris Lamoureux 2012-10-28 15:01:33 -07:00
parent ccd677f77c
commit 8db540e110
4 changed files with 42 additions and 4 deletions

View File

@ -2,7 +2,7 @@
I'm building this while learning from [Lazy Foo' Productions' SDL Tutorials](http://lazyfoo.net/SDL_tutorials/). I'm building this while learning from [Lazy Foo' Productions' SDL Tutorials](http://lazyfoo.net/SDL_tutorials/).
## About ## About
Trololo is written in C++ with SDL 1.2.12 (32 bit) with the SDL extension library: SDL_image (1.2.12). Trololo is written in C++ with SDL 1.2.15 (32 bit) with the SDL extension libraries: SDL_image (1.2.12) and SDL_tff (2.0.11).
## License ## License
This software is released under the GNU General Public License Version 3. Please read the LICENSE file to know your rights before continuing. This software is released under the GNU General Public License Version 3. Please read the LICENSE file to know your rights before continuing.

View File

@ -1,6 +1,7 @@
// SDL + Extensions // SDL + Extensions
#include "SDL/SDL.h" #include "SDL/SDL.h"
#include "SDL/SDL_image.h" #include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
// Standard // Standard
#include <cstdio> #include <cstdio>
@ -37,7 +38,14 @@ SDL_Surface *StartUp(const char *title, int x, int y)
return NULL; return NULL;
} }
SDL_WM_SetCaption(title, NULL ); SDL_WM_SetCaption(title, NULL);
//Initialize SDL_ttf
if(TTF_Init() == -1)
{
fprintf(stderr, "True Type Font initialization failed: %s", SDL_GetError());
return NULL;
}
// Success: return video surface // Success: return video surface
return screen; return screen;

BIN
images/ttf/CaviarDreams.ttf Normal file

Binary file not shown.

View File

@ -1,6 +1,7 @@
// SDL + Extensions // SDL + Extensions
#include "SDL/SDL.h" #include "SDL/SDL.h"
#include "SDL/SDL_image.h" #include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
// Common SDL functions for general processing. // Common SDL functions for general processing.
#include "commonSDL.h" #include "commonSDL.h"
@ -13,6 +14,8 @@ SDL_Surface *screen = NULL;
SDL_Surface *background = NULL; SDL_Surface *background = NULL;
SDL_Surface *characters = NULL; SDL_Surface *characters = NULL;
SDL_Surface *message = NULL;
// Image filenames // Image filenames
const char *background_image = "stage1.bmp"; const char *background_image = "stage1.bmp";
const char *characters_image = "characters.bmp"; const char *characters_image = "characters.bmp";
@ -55,10 +58,37 @@ int main(int argc, char* args[])
apply_image(0, 0, background, screen); apply_image(0, 0, background, screen);
// Blit troll image // Blit troll image
apply_image(0, 0, characters, screen, &clip[0]); apply_image(700, 40, characters, screen, &clip[0]);
// Blit codfish image // Blit codfish image
apply_image(300, 300, characters, screen, &clip[1]); apply_image(150, 300, characters, screen, &clip[1]);
// Setup welcome text
SDL_Color whitecolor = { 255, 255, 255 };
TTF_Font *font = TTF_OpenFont("CaviarDreams.ttf", 80);
const char* text = "Welcome to Trololo";
if(!font)
{
fprintf(stderr, "TTF_OpenFont: %s\n", TTF_GetError());
}
/*
Checks if font or text is NULL due to the documentation:
NULL font into this function will cause a segfault.
NULL text into this function will result in undefined behavior.
*/
if(font != NULL && text != NULL)
message = TTF_RenderText_Solid(font, text, whitecolor);
else
fprintf(stderr, "TFF Render Text Solid Error: init error\n");
// Apply message
if(message != NULL)
apply_image(100, 200, message, screen);
else
fprintf(stderr, "TFF Render Text Solid Error: apply error\n");
if(screen != NULL) if(screen != NULL)
SDL_Flip(screen); SDL_Flip(screen);