short simple SDL font program has flaw somwhere

i have been fiddling with the font programming just a bit to see how it works, i have the font linkers installed corctly and the font in the folder, the tutorial works but my short version of the code does not, there is some hole in my learning...or i keep missing something and im sure the answers very simple heres the code...


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
#include "SDL/SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#include <string>

SDL_Surface *background = NULL;
  SDL_Surface *screen = NULL;
SDL_Surface *message = NULL;



void dotherectthing (int x, int y, SDL_Surface *source,SDL_Surface *destination, SDL_Rect *clip=NULL)
{
    SDL_Rect therect;
    therect.x=x;
    therect.y=y;
    SDL_BlitSurface (source,clip,destination,&therect);
}


SDL_Surface *getimage (std::string filename)
{
    SDL_Surface *tempimage =NULL;
    SDL_Surface *optimized =NULL;

    tempimage = IMG_Load (filename.c_str());
    optimized = SDL_DisplayFormat (tempimage);
    SDL_FreeSurface (tempimage);

    return optimized;
}


int main(int argc, char *args[])
{

    SDL_Init(SDL_INIT_EVERYTHING);



    screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);//find out what the last argument is
        SDL_WM_SetCaption ("squidley fonty test",NULL);
  background = getimage("background.png");

    TTF_Font *font = NULL;

    font = TTF_OpenFont ("valium.ttf",28);

    SDL_Color textcolor = {255,255,255};


    message= TTF_RenderText_Solid (font,"REVENGE", textcolor);

  dotherectthing(0,0,background,screen);
    dotherectthing(0,50,message,screen);
    SDL_Flip (screen);

    SDL_Delay (3000);
  SDL_FreeSurface (background);
  SDL_FreeSurface (message);
  TTF_CloseFont (font);
  return 0;
}
Last edited on
You have to call TTF_Init.
!?
thank you very much, im getting to learn it at last
Topic archived. No new replies allowed.