1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include "SDL.h"
#include "SDL_image.h"
#include <Iostream>
#include "SDL_ttf.h"
int main(int argc, char* args[])
{
using namespace std;
bool running = true;
//Init SDL
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
running = false;
}
TTF_Init();
SDL_Surface *screen;
screen = SDL_SetVideoMode(800, 600, 24, SDL_HWSURFACE);
SDL_WM_SetCaption("SDL tutorial", NULL);
if(screen == NULL)
{
running = false;
}
SDL_Event occur;
TTF_Font *times;
SDL_Color white = { 255, 0, 255}; // not really white :P
times = TTF_OpenFont("Times.ttf", 20);
SDL_Surface *message = TTF_RenderText_Solid(times, "This is my text" , white);
while(running == true)
{
SDL_PollEvent(&occur);
if(occur.type == SDL_QUIT)
{
running = false;
}
SDL_FillRect(screen, NULL, 0);
SDL_BlitSurface(message, NULL, screen, NULL);
SDL_FreeSurface(message); // How to use this?
SDL_Flip(screen);
}
TTF_Quit();
//Quit SDL
SDL_Quit();
return 0;
}
|