Hello,
I am having some problem with getting a image to blit. The FPS text image shows up or is blitted, but when I try to blit the point text image to the surface it won’t blit. I’ll post my code.
Code:
#include “main.h”
SDL_Surface* Screen;
SDL_Event event;
TTF_Font* Font;
int ThisTime = 0;
int LastTime = 0;
float DeltaTime = 0.0f;
const int WIDTH = 800;
const int HEIGHT = 600;
const int DEPTH = 32;
const char* TITLE = “Tower Defense”;
SDL_Color textColor = {255,255,0};
int TowerHealth = 100;
int Points = 0;
SDLKey keyPressed;
SDLKey keyReleased;
bool keysHeld[323] = {false};
bool GameRunning = true;
SDL_Surface* Backdrop;
SDL_Rect BackdropRect;
SDL_Surface* FPS;
SDL_Rect FPSRect;
char fps[10];
SDL_Surface* POINT;
SDL_Rect POINTRect;
char point[6];
bool GameScreen = true;
int main(int argc, char* argv[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}
Screen = SDL_SetVideoMode(WIDTH,HEIGHT,DEPTH, SDL_HWSURFACE);
SDL_WM_SetCaption(TITLE,NULL);
if(TTF_Init() == -1)
{
return 1;
}
if(Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096) == -1)
{
return 1;
}
Backdrop = IMG_Load("Backdrop.png");
BackdropRect.x = 0;
BackdropRect.y = 0;
BackdropRect.w = 800;
BackdropRect.h = 600;
Font = TTF_OpenFont("Arial.ttf",20);
FPSRect.x = 1;
FPSRect.y = 1;
FPSRect.w = 0;
FPSRect.h = 0;
POINTRect.x = 1;
POINTRect.y = 60;
POINTRect.w = 0;
POINTRect.h = 0;
while(GameRunning)
{
ThisTime = SDL_GetTicks();
DeltaTime = (float)(ThisTime - LastTime) / 1000;
LastTime = ThisTime;
sprintf(fps,"FPS: %.4f", DeltaTime);
FPS = TTF_RenderText_Solid(Font,fps,textColor);
sprintf(point,"Points: %.3d", Points);
POINT = TTF_RenderText_Solid(Font,point,textColor);
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
GameRunning = false;
}
if(event.type == SDL_KEYDOWN)
{
keyPressed = event.key.keysym.sym;
if(keyPressed == SDLK_ESCAPE)
{
GameRunning = false;
}
}
}
if(SDL_Flip(Screen) == -1)
{
return 1;
}
SDL_FillRect(Screen,NULL,SDL_MapRGB(Screen->format,0,0,0));
SDL_BlitSurface(Backdrop,NULL,Screen,&BackdropRect);
SDL_BlitSurface(FPS,NULL,Screen,&FPSRect);
SDL_BlitSurface(POINT,NULL,Screen,&POINTRect);
}
free(fps);
free(point);
SDL_FreeSurface(FPS);
SDL_FreeSurface(Backdrop);
SDL_FreeSurface(POINT);
TTF_CloseFont(Font);
TTF_Quit();
Mix_CloseAudio();
SDL_Quit();
return 0;
}
This is what is displayed in the debugger.
Code:
Output to Display…
"[New Thread 3992.0x12dc]\n"
Stopped - signal received
Thread 1 stopped in ?? at line 5823711 in with Segmentation fault
Debugger closed.
[/code]