Jump to content
  • Advertisement
Sign in to follow this  
tracy_Coder

SDL and BFont

This topic is 4967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am fairly new to SDL but i have been programming for a couple of years now I am trying to create a simple pacman game by using only a 2D array for tiles no animations or anything yet i am mostly doing it to try to get a better understanding of how to use tiles with SDL. My problem is i can not for the life of me get it to draw text onto the screen. I have tried SDL_ttf, i tried using the files from the font tutorial on cone3D and now im on BFont I have all of the libraries linked to the compiler and as far as i know all of the compiler settings are correct. I just recently updated to SDL 1.2.8 because i read in a couple other threads that the problem im having might be because of SDL not being this version. When i compile my program i get 0 errors I am using VC++ but i have also tried it in Dev C++ and in both when i run the game i get an error message saying Procedure entry point SDL_Error could not be located in dynamic link library SDL.dll. A screen shot of my error can be found here http://tracycoder.cjb.net/errorscreen.JPG Here is how i am using BFont in my program: BFont_Info *Font1 = NULL; Font1 = LoadFont("font01.png"); if (Font1 == NULL) { fprintf(stderr, "Couldnt load font file"); exit(1); } PutStringFont ( g_window , Font1,513,10 , "Score" ); Before i included the files for BFont and linked the SDL_image library the program ran fine with no errors. Can you please tell me if its something i am doing wrong in my code or if its some kind of compiler setting i need to fix. Any suggestions would be great and if you have a better font library that is pretty easy to use please let me know.

Share this post


Link to post
Share on other sites
Advertisement
Thank you for you reply I downloaded the newest version of SDL_image this morning and im still getting the error but only when i include the BFont files into my project as long as i dont include those files the SDL_image lib works could i maybe have the wrong version of BFont?

Share this post


Link to post
Share on other sites
I downloaded SDL_ttf and looked through my data structures for game programmers book to see a reference on how to use it without using the freetype library I have compiled and ran a program from that book that is using SDL_ttf and it ran fine but when i run mine i am getting now Fatal Signal: Segment Fault <SDL Parachute Deployed> Here is the code I am using:


#include <SDL.h>
#include <stdlib.h>
#include "SDLGUI.h"

//Global Constant Variables
const char PROGRAM_NAME[] = "PacMan";

const int WIDTH = 640;
const int HEIGHT = 480;
const int ARIAL = 0;

//Map Variables
const int TILESIZE = 32;
const int MAPWIDTH = 16;
const int MAPHEIGHT = 16;
const int TILES = 12;
int currentX = 8;
int currentY = 11;
int oldX = 0;
int oldY = 0;
int temp = 0;

//Global Variables
SDL_Surface* g_window = 0;
SDL_Surface* g_tiles[TILES];
SDL_Surface* g_lives[4];
SDLGUI* g_gui;


int g_tilemap[MAPWIDTH][MAPHEIGHT];

//Game Variables
bool paused = false;
bool gameover = false;
int score = 0;
int level = 0;
int currentTile = 0;

//93 total dots;
int dots = 0;


//Functions


//Assigns Each Array value with its proper tile
void DrawMap() {
int x,y;
//Assign tiles to there map positions
//Fill entire map with dots
for (y=0;y<MAPHEIGHT;y++) {
for (x=0;x<MAPWIDTH;x++) {
g_tilemap[x][y] = 2;
}
}

//Draw Left Wall
for (y=0;y<16;y++) {
g_tilemap[0][y] = 1;
}

//Draw Right Wall
for (y=0;y<16;y++) {
g_tilemap[15][y] = 1;
}

//Draw top wall
for (x=1;x<15;x++) {
g_tilemap[x][0] = 1;
}
// Draw Bottom wall
for (x=1;x<15;x++) {
g_tilemap[x][14] = 1;
}

// Draw inner map
for (x=1;x<7;x++) {
g_tilemap[x][2] = 1;
}

for (y=1;y<3;y++) {
g_tilemap[8][y] = 1;
}

for (x=10;x<15;x++) {
g_tilemap[x][2] = 1;
}

for (x=1;x<7;x++) {
g_tilemap[x][12] = 1;
}
for (y=12;y<14;y++) {
g_tilemap[8][y] = 1;
}

for (x = 10;x<15;x++) {
g_tilemap[x][12] = 1;
}

//Draw inner box for ghost
for (x=4;x<12;x++) {
g_tilemap[x][6] = 1;
}
for (y=5;y<9;y++) {
g_tilemap[4][y+2] = 1;
}
for (x=4;x<12;x++) {
g_tilemap[x][10] = 1;
}
for (y=5;y<9;y++) {
g_tilemap[11][y+2] = 1;
}

for (y=7;y<10;y++) {
for (x=5;x<11;x++) {
g_tilemap[x][y] = 0;
}
}
for (y=4;y<11;y++) {
g_tilemap[2][y] = 1;
}
for (y=4;y<11;y++) {
g_tilemap[13][y] = 1;
}
for (x=4;x<12;x++) {
g_tilemap[x][4] = 1;
}

//Draw Power Dots Below
g_tilemap[1][1] = 3;
g_tilemap[14][13] = 3;
g_tilemap[1][13] = 3;
g_tilemap[14][1] = 3;

//PacMan starting position
g_tilemap[8][11] = 5;

//Draw Ghost starting position
g_tilemap[5][8] = 9;
g_tilemap[7][8] = 10;
g_tilemap[9][8] = 11;

}

//Draws the Tiles onto the screen
void DrawTilemap(int p_x, int p_y) {
int x,y;
int bx = p_x;
int by = p_y;

for (y = 0;y<MAPHEIGHT;y++) {
for (x = 0;x < MAPWIDTH; x++) {
currentTile = g_tilemap[x][y];
SDLBlit(g_tiles[currentTile],g_window,bx,by);
bx += TILESIZE;
}
bx = p_x;
by += TILESIZE;
}
}

void DrawLives(int p_x,int p_y) {
int x;
int bx = p_x;
int by = p_y;
for (x = 0;x<4;x++) {
SDLBlit(g_lives[x],g_window,bx,by);
bx+=TILESIZE;
}
}
void reDrawStage() {
dots = 0;
DrawMap();
DrawTilemap(0,0);
}

//void DrawFont() {
// static SDL_Surface* text;
// text = TTF_RenderText_Shaded( g_gui->GetFont(ARIAL), "Score", RED, WHITE );
// g_gui->Blit(text,513,10);
// SDL_FreeSurface( text );
//}

//Main Function
int main (int argc, char* argv[]) {


int x = 0;
int y = 0;
SDL_Event event;
if(SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0) {
printf("Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
TTF_Init();
SDL_WM_SetCaption(PROGRAM_NAME, 0);
SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
atexit(SDL_Quit);
g_window = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE|SDL_DOUBLEBUF/*SDL_FULLSCREEN*/);
if ( g_window == NULL ){
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}
g_gui->SetFont( "arial.ttf", ARIAL, 22, TTF_style_NORMAL );
// DrawFont();

for (x = 0;x<4;x++) {
g_lives[x] = SDL_LoadBMP("pRight.bmp");
}


g_tiles[0] = SDL_LoadBMP("blankTile.bmp");
g_tiles[1] = SDL_LoadBMP("wallTile.bmp");
g_tiles[2] = SDL_LoadBMP("dotTile.bmp");
g_tiles[3] = SDL_LoadBMP("powerTile.bmp");
g_tiles[4] = SDL_LoadBMP("pTop.bmp");
g_tiles[5] = SDL_LoadBMP("pLeft.bmp");
g_tiles[6] = SDL_LoadBMP("pRight.bmp");
g_tiles[7] = SDL_LoadBMP("pDown.bmp");
g_tiles[8] = SDL_LoadBMP("transparent.bmp");
g_tiles[9] = SDL_LoadBMP("redGhost.bmp");
g_tiles[10] = SDL_LoadBMP("blueGhost.bmp");
g_tiles[11] = SDL_LoadBMP("oGhost.bmp");
DrawMap();
DrawLives(513,440);


while (1) {

if (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT)
break;
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_ESCAPE) {
SDL_Event quit;
quit.type = SDL_QUIT;
SDL_PushEvent(&quit);
}
if (event.key.keysym.sym == SDLK_p) paused = !paused;
if (!paused && !gameover) {
if (event.key.keysym.sym == SDLK_LEFT) {
oldX = currentX;
temp = currentX;
temp--;
if (g_tilemap[temp][currentY] != 1 && temp > -1) {
if (dots != 93) {
currentX--;
if (g_tilemap[currentX][currentY] != 0) { dots++; score++;}
g_tilemap[currentX][currentY] = 5;
g_tilemap[oldX][currentY] = 0;
DrawTilemap(0,0);
} else {reDrawStage();currentX = 8;currentY = 11;}

}
}
if (event.key.keysym.sym == SDLK_RIGHT) {
oldX = currentX;
temp = currentX;
temp++;
if (g_tilemap[temp][currentY] != 1 && temp < 16) {

if (dots != 93) {
currentX++;
if (g_tilemap[currentX][currentY] != 0) {dots++;score++;}
g_tilemap[currentX][currentY] = 6;
g_tilemap[oldX][currentY] = 0;
DrawTilemap(0,0);
} else {reDrawStage();currentX = 8;currentY = 11;}
}

}
if (event.key.keysym.sym == SDLK_UP) {
oldY = currentY;
temp = currentY;
temp--;
if (g_tilemap[currentX][temp] != 1 && temp > -1) {
if (dots != 93) {
currentY--;
if (g_tilemap[currentX][currentY] != 0) {dots++; score++; }
g_tilemap[currentX][currentY] = 4;
g_tilemap[currentX][oldY] = 0;
DrawTilemap(0,0);
} else {reDrawStage();currentX = 8;currentY = 11;}
}
}
if (event.key.keysym.sym == SDLK_DOWN) {
oldY = currentY;
temp = currentY;
temp++;
if (g_tilemap[currentX][temp] != 1 && temp <16) {

if (dots != 93) {
currentY++;
if (g_tilemap[currentX][currentY] != 0) { dots++; score++; }
g_tilemap[currentX][currentY] = 7;
g_tilemap[currentX][oldY] = 0;
DrawTilemap(0,0);
} else {reDrawStage();currentX = 8;currentY = 11;}
}
}
}
}

}

DrawTilemap(0,0);
SDL_UpdateRect( g_window, 0, 0, 0, 0 );




}

// done
return 0;


}

I know its something very simple that i am missing but i just cant see it. If anyone knows what i am doing wrong any help would be very appreciated. SDL_ttf.h is included in the SDLGUI.h file. Sorry for the sloppy code i have been adding and removing parts of it for hours havent went back yet and adjusted the indenting. If it would help to see the actual project here is the link http://tracycoder.cjb.net/PacMan.zip

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!