本文整理汇总了C++中TTF_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ TTF_Init函数的具体用法?C++ TTF_Init怎么用?C++ TTF_Init使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TTF_Init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
forecol->g = (Uint8)g;
forecol->b = (Uint8)b;
} else
if ( strcmp(argv[i], "-bgcol") == 0 ) {
int r, g, b;
if ( sscanf (argv[++i], "%d,%d,%d", &r, &g, &b) != 3 ) {
fprintf(stderr, Usage, argv0);
return(1);
}
backcol->r = (Uint8)r;
backcol->g = (Uint8)g;
backcol->b = (Uint8)b;
} else {
fprintf(stderr, Usage, argv0);
return(1);
}
}
argv += i;
argc -= i;
/* Check usage */
if ( ! argv[0] ) {
fprintf(stderr, Usage, argv0);
return(1);
}
/* Initialize SDL */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
return(2);
}
/* Initialize the TTF library */
if ( TTF_Init() < 0 ) {
fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());
SDL_Quit();
return(2);
}
/* Open the font file with the requested point size */
ptsize = 0;
if ( argc > 1 ) {
ptsize = atoi(argv[1]);
}
if ( ptsize == 0 ) {
i = 2;
ptsize = DEFAULT_PTSIZE;
} else {
i = 3;
}
font = TTF_OpenFont(argv[0], ptsize);
if ( font == NULL ) {
fprintf(stderr, "Couldn't load %d pt font from %s: %s\n",
ptsize, argv[0], SDL_GetError());
cleanup(2);
}
TTF_SetFontStyle(font, renderstyle);
TTF_SetFontOutline(font, outline);
TTF_SetFontKerning(font, kerning);
TTF_SetFontHinting(font, hinting);
if( dump ) {
for( i = 48; i < 123; i++ ) {
SDL_Surface* glyph = NULL;
glyph = TTF_RenderGlyph_Shaded( font, i, *forecol, *backcol );
示例2: main
int
main (int argc, char ** argv)
{
int numloops = 0;
int fpstimer;
double a1, a2;
tolerance_file_t * tol = get_tolerance ("colors.tol");
memset (tol, '\0', sizeof (tolerance_file_t));
int do_blob = -1;
int do_text = -1;
Uint8 mouse_button;
SDL_Surface * image;
SDL_Surface * image_2;
SDL_Surface * screen;
SDL_Surface * back = IMG_Load ("back.png");
SDL_Color white = {255, 255, 255};
SDL_Event event;
char * jpeg_buff;
char * jpeg_buff_2;
int jpeg_buff_size;
int jpeg_buff_size_2;
int x, y;
FILE * log_fp;
blob * cam1_green;
blob * cam1_red;
blob * cam2_green;
blob * cam2_red;
blob * vision_targets = NULL;
CvCapture * capture;
CvCapture * capture_2;
IplImage * cam_img;
IplImage * cam_img_2;
FILE * color_fp;
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
SDL_Quit ();
printf ("SDL Initialization failed\n");
exit (1);
}
if ((screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN )) == NULL) {
SDL_Quit ();
printf ("Could not create output surface\n");
exit (1);
}
if (TTF_Init () == -1) {
SDL_Quit ();
printf ("TTF_Init: %s\n", TTF_GetError());
exit (1);
}
if (!(capture = cvCaptureFromCAM (0))) {
SDL_Quit ();
printf ("Failed to start capture\n");
exit (1);
}
if (!(capture_2 = cvCaptureFromCAM (1))) {
SDL_Quit ();
printf ("Failed to start capture\n");
exit (1);
}
int start = SDL_GetTicks ();
int lastfps;
TTF_Font * arial = TTF_OpenFont ("arial.ttf", 12);
while (1) {
fpstimer = SDL_GetTicks ();
numloops++;
if (fpstimer - start > 1000) {
start = SDL_GetTicks ();
lastfps = numloops;
numloops = 0;
}
while (SDL_PollEvent (&event)) {
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case 'q':
TTF_Quit ();
SDL_Quit ();
exit (0);
break;
case 'b':
do_blob = -do_blob;
break;
case 'v':
do_text = -do_text;
break;
case 'i':
tol->cam1_green.blob_minlength++;
break;
case 'k':
tol->cam1_green.blob_minlength--;
break;
case 'o':
tol->cam1_green.blob_tolerance++;
break;
case 'l':
tol->cam1_green.blob_tolerance--;
break;
case 'y':
tol->cam1_red.blob_minlength++;
break;
case 'h':
//.........这里部分代码省略.........
示例3: gui_init
int gui_init (void) {
#if 0
if (display == NULL) {
SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
display = SDL_SetVideoMode(640,480,16,VIDEO_FLAGS);
#if SDL_UI_DEBUG > 0
write_log ("SDLUI: SDL_Init display init\n");
#endif
} else {
#if SDL_UI_DEBUG > 0
write_log ("SDLUI: SDL_Init display ready\n");
#endif
}
#endif
SDL_JoystickEventState(SDL_ENABLE);
SDL_JoystickOpen(0);
SDL_ShowCursor(SDL_DISABLE);
TTF_Init();
amiga_font = TTF_OpenFont("guidep/fonts/amiga4ever_pro2.ttf", 16);
if (!amiga_font) {
printf("SDLUI: TTF_OpenFont failed: %s\n", TTF_GetError());
abort();
}
text_color.r = 50;
text_color.g = 50;
text_color.b = 50;
if(!pMainMenu_Surface) pMainMenu_Surface = SDL_LoadBMP("guidep/images/menu.bmp");
menu_load_surface(pMainMenu_Surface);
if (pMenu_Surface == NULL) {
write_log ("SDLUI: Failed to load menu image\n");
abort();
}
pMouse_Pointer = SDL_LoadBMP("guidep/images/mousep_33x33_wb20.bmp");
if (pMouse_Pointer == NULL) {
write_log ("SDLUI: Failed to load mouse pointer image\n");
abort();
}
SDL_SetColorKey(pMouse_Pointer, SDL_SRCCOLORKEY, SDL_MapRGB(pMouse_Pointer->format, 68, 94, 174));
icon_expansion = SDL_LoadBMP("guidep/images/icon-expansion.bmp");
if (icon_expansion == NULL) {
write_log ("SDLUI: Failed to load icon expansion\n");
abort();
}
icon_preferences = SDL_LoadBMP("guidep/images/icon-preferences.bmp");
if (icon_preferences == NULL) {
write_log ("SDLUI: Failed to load icon preferences\n");
abort();
}
icon_keymaps = SDL_LoadBMP("guidep/images/icon-keymaps.bmp");
if (icon_keymaps == NULL) {
write_log ("SDLUI: Failed to load icon keymaps\n");
abort();
}
icon_floppy = SDL_LoadBMP("guidep/images/icon-floppy.bmp");
if (icon_floppy == NULL) {
write_log ("SDLUI: Failed to load icon floppy\n");
abort();
}
icon_reset = SDL_LoadBMP("guidep/images/icon-reset.bmp");
if (icon_reset == NULL) {
write_log ("SDLUI: Failed to load icon reset\n");
abort();
}
icon_storage = SDL_LoadBMP("guidep/images/icon-storage.bmp");
if (icon_storage == NULL) {
write_log ("SDLUI: Failed to load icon storage\n");
abort();
}
icon_run = SDL_LoadBMP("guidep/images/icon-run.bmp");
if (icon_run == NULL) {
write_log ("SDLUI: Failed to load icon run\n");
abort();
}
icon_exit = SDL_LoadBMP("guidep/images/icon-exit.bmp");
if (icon_exit == NULL) {
write_log ("SDLUI: Failed to load icon exit\n");
abort();
}
// icon_tweaks = SDL_LoadBMP("guidep/images/icon-tweaks.bmp");
return 1;
}
示例4: main
int main(int argc, char **argv)
{
int res = 0;
#else
/* gee */
extern "C" DECLSPEC void SDLCALL SDL_SetModuleHandle(void *hInst);
// translated to utf8_main
int main(int argc, char *argv[])
{
int res = 0;
#if !(SDLMAME_SDL2)
/* Load SDL dynamic link library */
if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) {
fprintf(stderr, "WinMain() error: %s", SDL_GetError());
return(FALSE);
}
SDL_SetModuleHandle(GetModuleHandle(NULL));
#endif
#endif
// disable I/O buffering
setvbuf(stdout, (char *) NULL, _IONBF, 0);
setvbuf(stderr, (char *) NULL, _IONBF, 0);
#ifdef SDLMAME_UNIX
#if (!defined(SDLMAME_MACOSX)) && (!defined(SDLMAME_HAIKU))
if (TTF_Init() == -1)
{
printf("SDL_ttf failed: %s\n", TTF_GetError());
}
FcInit();
#endif
#endif
#ifdef SDLMAME_OS2
MorphToPM();
#endif
#if defined(SDLMAME_X11) && (SDL_MAJOR_VERSION == 1) && (SDL_MINOR_VERSION == 2)
if (SDL_Linked_Version()->patch < 10)
/* workaround for SDL choosing a 32-bit ARGB visual */
{
Display *display;
if ((display = XOpenDisplay(NULL)) && (DefaultDepth(display, DefaultScreen(display)) >= 24))
{
XVisualInfo vi;
char buf[130];
if (XMatchVisualInfo(display, DefaultScreen(display), 24, TrueColor, &vi)) {
snprintf(buf, sizeof(buf), "0x%lx", vi.visualid);
osd_setenv(SDLENV_VISUALID, buf, 0);
}
}
if (display)
XCloseDisplay(display);
}
#endif
{
sdl_osd_interface osd;
sdl_options options;
cli_frontend frontend(options, osd);
res = frontend.execute(argc, argv);
}
#ifdef MALLOC_DEBUG
{
void check_unfreed_mem(void);
check_unfreed_mem();
}
#endif
// already called...
//SDL_Quit();
#ifdef SDLMAME_UNIX
#if (!defined(SDLMAME_MACOSX)) && (!defined(SDLMAME_HAIKU))
TTF_Quit();
FcFini();
#endif
#endif
exit(res);
return res;
}
示例5: main
int main( int argc, char* args[] )
{
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
TTF_Init();
//Set window caption
SDL_WM_SetCaption("Yet Another Dave!", NULL);
SDL_Surface *buffer = NULL;
SDL_Surface *message = NULL;
bool fullscreen = false;
if( fullscreen == true )
buffer = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE | SDL_FULLSCREEN);
else
buffer = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
SDL_Event event ;
Game *G1 = new Game();
player *P1 = new player();
int times=0;
while(event.type != SDL_QUIT)
{
SDL_PollEvent( &event );
//If a key was pressed
if( event.type == SDL_KEYDOWN )
{
//Set the proper message surface
switch( event.key.keysym.sym )
{
case SDLK_UP: if(times==0&&G1->jump==0) times=10;//P1->movePlayer(G1, 2);
G1->jump=1;
break;
case SDLK_DOWN: P1->movePlayer(G1, 3);
break;
case SDLK_LEFT: P1->movePlayer(G1, 0);
break;
case SDLK_RIGHT: P1->movePlayer(G1, 1);
break;
}
}
if(times>0)
{
times--;
P1->movePlayer(G1, 2);
}
else
{
G1->jump=1;
P1->movePlayer(G1, 3);
}
G1->blitBackground( buffer );
G1->blitExtra( buffer );
P1->blitPlayer( buffer );
G1->blitMessage( buffer );
SDL_Flip( buffer );
SDL_Delay(100);
if(G1->end(P1))
break;
}
G1->blitBackground( buffer );
G1->blitExtra( buffer );
SDL_Flip( buffer );
static const SDL_Color WHITE = {255,255,255} ;
TTF_Font *font;
SDL_Color textColor;
font = TTF_OpenFont( "comic.ttf", 24 );
textColor = WHITE;
SDL_Rect *r1=new SDL_Rect();
r1->x=296; r1->y=228;
message = TTF_RenderText_Solid( font, "GAME OVER", textColor );
SDL_BlitSurface(message, NULL, buffer, r1);
SDL_Flip( buffer );
r1->x=250; r1->y=260;
message = TTF_RenderText_Solid( font, "Final Score: ", textColor );
SDL_BlitSurface(message, NULL, buffer, r1);
SDL_Flip( buffer );
char buff[10];
_itoa_s(G1->score,buff,10);
r1->x=400; r1->y=260;
message = TTF_RenderText_Solid( font, buff, textColor );
SDL_BlitSurface(message, NULL, buffer, r1);
SDL_Flip( buffer );
r1->x=50; r1->y=0;
message = TTF_RenderText_Solid( font, "Thank You for Playing", textColor );
SDL_BlitSurface(message, NULL, buffer, r1);
SDL_Flip( buffer );
r1->x=0; r1->y=28;
message = TTF_RenderText_Solid( font, "Game Developed by Chinmay Pednekar", textColor );
SDL_BlitSurface(message, NULL, buffer, r1);
//.........这里部分代码省略.........
示例6: main
int main(int argc, char **argv){
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
logSDLError(std::cout, "SDL_Init");
return 1;
}
if (TTF_Init() != 0){
logSDLError(std::cout, "TTF_Init");
return 1;
}
SDL_Window *window = SDL_CreateWindow("Hello World!", 100, 100, SCREEN_WIDTH, GRID_HEIGHT + HUD_HEIGHT,
SDL_WINDOW_SHOWN);
if (window == nullptr){
logSDLError(std::cout, "CreateWindow");
SDL_Quit();
return 2;
}
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (renderer == nullptr){
logSDLError(std::cout, "CreateRenderer");
SDL_DestroyWindow(window);
SDL_Quit();
return 3;
}
//The textures we'll be using
SDL_Texture *background = loadTexture("res/game_bg.jpg", renderer);
SDL_Texture *image = loadTexture("res/Blue.png", renderer);
SDL_Texture *blueGem = loadTexture("res/Blue.png", renderer);
SDL_Texture *greenGem = loadTexture("res/Green.png", renderer);
SDL_Texture *purpleGem = loadTexture("res/Purple.png", renderer);
SDL_Texture *redGem = loadTexture("res/Red.png", renderer);
SDL_Texture *yellowGem = loadTexture("res/Yellow.png", renderer);
SDL_Texture *gems[] = {blueGem, greenGem, purpleGem, redGem, yellowGem};
SDL_Texture *cursorYellowImg = loadTexture("res/cursor_yellow.png", renderer);
SDL_Texture *cursorGreenImg = loadTexture("res/cursor_green.png", renderer);
//Make sure they both loaded ok
if (background == nullptr || image == nullptr){
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 4;
}
//We'll render the string "TTF fonts are cool!" in white
//Color is in RGB format
SDL_Color color = { 255, 255, 255 };
SDL_Texture *textImage;
TTF_Font* font = loadFont("res/sample.ttf", 32);
//Our event structure
SDL_Event e;
//For tracking if we want to quit
bool quit = false;
int gameState = GAMESTATE_TITLE_SCREEN;
int** pGridArray;
gem* pGemsArray = new gem[NUM_ROWS * NUM_COLUMNS];
int score;
int mouseX = 0;
int mouseY = 0;
int numGemsSelected = 0;
int selectedGems[2][2] = {{-1, -1}, {-1, -1}};
bool gemSelected = false;
int cursorRow = 0;
int cursorColumn = 0;
bool foundMatch = false;
int thisRow, thisColumn;
bool gemsDropping;
bool cancelSwap = false;
bool mouseDown = false;
int dragStartX;
int dragStartY;
bool dragStarted = false;
time_t timer;
time_t startTime;
std::ostringstream os;
while (!quit)
{
switch (gameState)
{
case GAMESTATE_TITLE_SCREEN:
break;
case GAMESTATE_INIT:
for (int i = 0; i < NUM_ROWS*NUM_COLUMNS; i++)
{
pGemsArray[i].state = GEMSTATE_IDLE;
}
pGridArray = initGrid(pGemsArray);
score = 0;
startTime = time(0);
gameState = GAMESTATE_INITIAL_CHECK_MATCH;
break;
case GAMESTATE_INITIAL_CHECK_MATCH:
//.........这里部分代码省略.........
示例7: main
int main(int argc, char *argv[]) {
int width = 640;
int height = 480;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
return 1;
}
if (TTF_Init() == -1) {
printf("Unable to initialize SDL_ttf: %s \n", TTF_GetError());
return 2;
}
atexit(SDL_Quit);
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
if (videoInfo) {
width = videoInfo->current_w;
height = videoInfo->current_h;
}
SDL_Surface* screen = SDL_SetVideoMode(width, height, 0,
SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF);
reflexgame::Renderer renderer(screen);
reflexgame::GameState gameState(width, height);
if (screen == NULL)
return 2;
SDL_ShowCursor(0);
SDL_WM_GrabInput(SDL_GRAB_ON);
Uint32 nextTime = 0;
time_left(nextTime);
gameState.start();
while(true) {
gameState.handleTick();
if (gameState.gameEnded()) {
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch(event.type){
case SDL_KEYDOWN:
switch(event.key.keysym.sym){
case SDLK_ESCAPE:
return 0;
break;
default:
break;
}
case SDL_QUIT:
return 0;
default:
break;
}
}
renderer.drawEndGame(gameState);
} else {
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch(event.type){
case SDL_MOUSEBUTTONDOWN:
{
if (event.button.button == SDL_BUTTON_LEFT) {
int x = event.button.x;
int y = event.button.y;
printf("Click at (%d, %d)\n", x, y);
gameState.attackAt(x, y);
}
break;
}
case SDL_KEYDOWN:
switch(event.key.keysym.sym){
case SDLK_ESCAPE:
return 0;
break;
default:
break;
}
case SDL_QUIT:
return 0;
default:
break;
}
}
renderer.draw(gameState);
}
SDL_Flip(screen);
SDL_Delay(time_left(nextTime));
}
return 0;
}
示例8: main
int main(int argc, char *argv[])
{
Game *g = (Game*) malloc(sizeof(Game));
SDL_Event event;
Uint8 *keystates;
Uint8 quit = false;
long lastplayerupdate = ms_time();
long lastenemyupdate = ms_time();
long lastshotupdate = ms_time();
long lastufoupdate = ms_time();
srand((unsigned int) time(NULL));
// SDL initialisieren
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
printf("Kann Video nicht initialisieren: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
g->screen = SDL_SetVideoMode(WIDTH, HEIGHT, 16, SDL_HWSURFACE);
if (g->screen == NULL) {
printf("Kann Video-Modus nicht festlegen: %s\n", SDL_GetError());
exit(1);
}
TTF_Init();
// Game initialisieren
initGame(g);
startNewLevel(g);
updateScore(g);
updateLives(g);
showHighscore(g);
updateBlocks(g);
// Nächster Grafikzustand
SDL_Flip(g->screen);
// Loop
while (!quit) {
// SDL Events abfragen
SDL_PollEvent(&event);
// Tastenstatus laden
keystates = SDL_GetKeyState(NULL);
// Escape gedrückt -> beenden
// TODO: Menü aufrufen statt beenden
if (keystates[SDLK_ESCAPE]) {
saveHighscore(g->score);
quit = true;
}
// Nur wenn entweder Links oder Rechts, nicht beide zur selben Zeit
if (keystates[SDLK_LEFT] != keystates[SDLK_RIGHT] && lastplayerupdate >= 100) {
lastplayerupdate = ms_time();
// Links
if (keystates[SDLK_LEFT]) {
movePlayer(g, Left);
}
// Rechts
if (keystates[SDLK_RIGHT]) {
movePlayer(g, Right);
}
}
if (keystates[SDLK_SPACE]) {
shoot(g);
}
// UFO
if (ms_time() - lastufoupdate >= UFO_UPDATE) {
lastufoupdate = ms_time();
ufo(g);
}
// Alienposition aktualisieren?
// Exponentialfunktion, die Level und Alienanzahl berücksichtigt
if (ms_time() - lastenemyupdate >= ENEMY_UPDATE_BASE * pow(0.95, g->level * 3 + (ENEMY_COUNT - g->enemyContainer.aliveCount) / 4)) {
lastenemyupdate = ms_time();
updateBlocks(g);
moveEnemys(g);
alienShot(g);
}
// Schüsse aktualisieren
if (ms_time() - lastshotupdate >= SHOT_UPDATE) {
lastshotupdate = ms_time();
updateShots(g);
checkCollision(g);
movePlayer(g, None);
}
usleep(20000); // begrenzt CPU Last
// Nächster Grafikzustand
//.........这里部分代码省略.........
示例9: initialize
//main loop functions
int initialize()
{
/* Setando coisas */
quit = false;
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
cout << "Problemas ao inicializar sistemas e subsistemas do SDL" << endl;
return -1;
}
//Initialize SDL_ttf
if( TTF_Init() == -1 )
return false;
//The attributes of the screen
const int SCREEN_WIDTH = 1980;
const int SCREEN_HEIGHT = 1024 ;
const int SCREEN_BPP = 32;
//Set up the screen
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//If there was an error in setting up the screen
if( screen == NULL )
{
cout << "Problemas inicializando o video" << endl;
return -2;
}
//Set the window caption
SDL_WM_SetCaption( "The World Last War", NULL );
//objetos principais
ImageHandlerSDLObj = new ImageHandlerSDL();
drawObj = new Draw();
randomObj = new Random();
timer = new Timer();
audioHandler = new AudioHandler();
fontHandler = new FontHandler();
//Load the images
logoEmpresa = (*ImageHandlerSDLObj).load_image("images/gamaSoft.jpg",0);
logoJogo = (*ImageHandlerSDLObj).load_image("images/logo.png",0);
logoRecursos = (*ImageHandlerSDLObj).load_image("images/recursosTecnologicos.png",0);
civilizationUnits = (*ImageHandlerSDLObj).load_image("images/unidades2.png",0);
classificacaoIndicativa = (*ImageHandlerSDLObj).load_image("images/classificacaoIndicativa.png",0);
menu = (*ImageHandlerSDLObj).load_image("images/menu.png",0);
mapa = (*ImageHandlerSDLObj).load_image("images/gamasoft_mapaTeste.png",0);
escolhaNacao = (*ImageHandlerSDLObj).load_image("images/telaNacao.png", 0);
nivel = (*ImageHandlerSDLObj).load_image("images/telaNivel.png", 0);
telaInstrucoes = (*ImageHandlerSDLObj).load_image("images/telaInstrucoes.png", 0);
telaOpcoes = (*ImageHandlerSDLObj).load_image("images/telaOpcoes.png", 0);
telaCreditos = (*ImageHandlerSDLObj).load_image("images/telaCreditos.png", 0);
telaLoading = (*ImageHandlerSDLObj).load_image("images/telaLoading.png", 0);
loading = (*ImageHandlerSDLObj).load_image("images/loadingPiece.png", 0);
(*audioHandler).initialize();
(*fontHandler).initialize();
//depois colocar no quadro 1 (0) da fase 1 apos a abertura no switch
initializeCenario1();
(*timer).start();
return 1; //sucess
}
示例10: main
int main( int argc, char* args[] ) {
if (SDL_Init(SDL_INIT_VIDEO) !=0)
{
std::cerr << "SDL_Init failed\n";
exit(EXIT_FAILURE);
}
if (TTF_Init() != 0) {
std::cerr << "TTF_Init failed\n";
exit(EXIT_FAILURE);
}
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
int systemX = videoInfo->current_w;
int systemY = videoInfo->current_h;
Uint8 bpp = videoInfo->vfmt->BitsPerPixel;
screen = SDL_SetVideoMode(systemX, systemY, bpp, SDL_SWSURFACE); // SDL_HWSURFACE | SDL_DOUBLEBUF
if (!screen)
{
std::cerr << "SDL_SetVideoMode failed\n";
exit(EXIT_FAILURE);
}
SDL_Rect r1_1 = {0,0,100,100};
SDL_FillRect(screen, &r1_1, SDL_MapRGB(screen->format, 255,0,0));
SDL_Rect r1_2 = {100,0,100,100};
SDL_FillRect(screen, &r1_2, SDL_MapRGB(screen->format, 0,255,0));
SDL_Rect r1_3 = {200,0,100,100};
SDL_FillRect(screen, &r1_3, SDL_MapRGB(screen->format, 0,0,255));
SDL_Rect r2_1 = {0,100,100,100};
SDL_FillRect(screen, &r2_1, SDL_MapRGB(screen->format, 0,255,0));
SDL_Rect r2_2 = {100,100,100,100};
SDL_FillRect(screen, &r2_2, SDL_MapRGB(screen->format, 0,0,255));
SDL_Rect r2_3 = {200,100,100,100};
SDL_FillRect(screen, &r2_3, SDL_MapRGB(screen->format, 255,0,0));
SDL_Rect r3_1 = {0,200,100,100};
SDL_FillRect(screen, &r3_1, SDL_MapRGB(screen->format, 0,0,255));
SDL_Rect r3_2 = {100,200,100,100};
SDL_FillRect(screen, &r3_2, SDL_MapRGB(screen->format, 255,0,0));
SDL_Rect r3_3 = {200,200,100,100};
SDL_FillRect(screen, &r3_3, SDL_MapRGB(screen->format, 0,255,0));
font = TTF_OpenFont("fonts/verdana.ttf",72);
if(!font){
std::cerr << "TTF_OpenFont failed\n";
exit(EXIT_FAILURE);
}
message = TTF_RenderUTF8_Blended(font,"Hello!",textColor);
if(!message){
std::cerr << "TTF_Render failed\n";
exit(EXIT_FAILURE);
}
messageRect.x = (systemX / 2) - (message->w / 2);
messageRect.y = (systemY / 2) - (message->h / 2);
SDL_BlitSurface(message, NULL, screen, &messageRect);
SDL_Surface* loaded = IMG_Load("logo.png");
if(!loaded){
std::cerr << "IMG_Load failed\n";
exit(EXIT_FAILURE);
}
image = SDL_DisplayFormatAlpha(loaded);
SDL_FreeSurface(loaded);
SDL_BlitSurface(image, NULL, screen, NULL);
SDL_Flip(screen);
SDL_Event event;
bool quit = false;
while(!quit) {
SDL_WaitEvent(&event);
switch (event.type) {
case SDL_QUIT : quit = true; break;
case SDL_KEYDOWN: {
printf("The %s key was pressed!\n", SDL_GetKeyName(event.key.keysym.sym));
switch( event.key.keysym.sym ) {
case SDLK_ESCAPE : quit = true; break;
default : break;
}
}
default : break;
}
}
//SDL_Delay(10000);
TTF_CloseFont(font);
TTF_Quit();
SDL_FreeSurface(message);
SDL_FreeSurface(image);
SDL_FreeSurface(screen);
SDL_Quit();
return EXIT_SUCCESS;
}
示例11: gestionTextBox
/**
* \fn int gestionTextBox(int value, SDL_Surface *ecran, SDL_Rect zone, int limite)
* \brief gère les interaction avec lutilisateur pour la modifiation et laffichage d'un nombre
*
* \param value La valeur initiale
* \param ecran La surface sur laquelle on veut l'afficher
* \param zone L'endroit où on veut afficher le nombre
* \param limite Valeur maximum que peut prendre le nombre
* \return la nouvelle valeur
*/
int gestionTextBox(int value, SDL_Surface *ecran, SDL_Rect zone, int limite){
/**Déclaration des variables*/
SDL_Color white = {255,255,255};
SDL_Color black = {0,0,0};
SDL_Surface *texte, *popup;
char valide = 0;
char affichageNb[3] = "";
TTF_Init(); //Démarrage de SDL_ttf
TTF_Font *police = TTF_OpenFont("Fonts/OCRAStd.otf", 16); //Charger la police
SDL_Event event;
do{
/**Affichage de la valeur modifié*/
sprintf(affichageNb, "%d",value); //convertion int -> string
texte = TTF_RenderText_Blended(police, affichageNb, black);
popup = SDL_CreateRGBSurface(SDL_HWSURFACE, texte->w, texte->h, 32, 0,0,0,0); //maj taille popup
SDL_FillRect(popup, NULL, SDL_MapRGB(popup->format, 255, 255, 255)); //couleur de fond de la fenetre
apply_surface(0, 0, texte, popup, NULL);
apply_surface(zone.x, zone.y,popup, ecran, NULL);
SDL_Flip(ecran); // Mise à jour de l'écran
/**Modification de la valeur*/
SDL_WaitEvent(&event);
if(event.type == SDL_KEYDOWN){
switch (event.key.keysym.sym){
case SDLK_KP0:
value = value*10 + 0;
break;
case SDLK_KP1:
value = value*10 + 1;
break;
case SDLK_KP2:
value = value*10 + 2;
break;
case SDLK_KP3:
value = value*10 + 3;
break;
case SDLK_KP4:
value = value*10 + 4;
break;
case SDLK_KP5:
value = value*10 + 5;
break;
case SDLK_KP6:
value = value*10 + 6;
break;
case SDLK_KP7:
value = value*10 + 7;
break;
case SDLK_KP8:
value = value*10 + 8;
break;
case SDLK_KP9:
value = value*10 + 9;
break;
case SDLK_BACKSPACE:
value = (value - value%10) / 10;
break;
case SDLK_KP_ENTER: //validation
valide = 1;
break;
case SDLK_RETURN: //validation
valide = 1;
break;
default:
break;
}
if (value>limite){
value = limite;
}else if(value/1000>0){//limite laffichage a 3 chiffre
value = (value - value%10) / 10;
}
}
/**Masquage de l'ancienne valeur*/
SDL_FillRect(popup, NULL, SDL_MapRGB(popup->format, 0, 0, 0)); //couleur de fond de la fenetre
apply_surface(zone.x, zone.y,popup, ecran, NULL);
}while(valide == 0);
sprintf(affichageNb, "%d",value); //ajout du char score
texte = TTF_RenderText_Blended(police, affichageNb, white);
apply_surface(0, 0, texte, popup, NULL);
apply_surface(zone.x, zone.y,popup, ecran, NULL);
SDL_Flip(ecran); // Mise à jour de l'écran
TTF_CloseFont(police); //Fermer la police
SDL_FreeSurface(texte); // On libère la surface
SDL_FreeSurface(popup); // On libère la surface
//.........这里部分代码省略.........
示例12: afficherMenuOption
/**
* \fn SDL_Rect* afficherMenuOption(SDL_Surface *ecran, Option *opt, int joueurSelect)
* \brief affiche un menu avec les options rejouer, quitter et option
*
* \param optAffichage Les options d'affichage
* \param opt Les options de jeu
* \param joueurSelect Le numero du joueur selectionné pour la modification de sont apparence
* \return un tableau de SDL_Rect, chaque case contient les position et taille d'un des boutons
*/
SDL_Rect* afficherMenuOption(SDL_Surface *ecran, Option *opt, int joueurSelect){//add: choix nb case libre, mode de jeu
/**Déclaration des variables*/
SDL_Surface *texte;
int popWidth = ecran->w, popHeight = ecran->h, marge = 32/4;
SDL_Color white = {255,255,255};
/**Zone menu*/
SDL_Surface *popup = SDL_CreateRGBSurface(SDL_HWSURFACE, popWidth, popHeight, 32, 0, 0, 0, 0);
rectangle(0,0,popup->w, popup->h, white, popup); //contour de la surface
apply_surface(0, 0,popup, ecran, NULL);
TTF_Init(); //Démarrage de SDL_ttf
TTF_Font *police;
/**Titre*/
police = TTF_OpenFont("Fonts/OCRAStd.otf", 20); //Charger la police
texte = TTF_RenderText_Blended(police, "Option", white);
apply_surface(16, 16, texte, ecran, NULL);
police = TTF_OpenFont("Fonts/OCRAStd.otf", 16); //Charger la police
/**Zone nombre de joueurs*/
int firstMarge = 16 + texte->w + marge;
int positionX = firstMarge;
int positionY = 16+texte->h +4* marge;
char affichageNb[21+3+1] = "Nombre de joueurs: ";
texte = TTF_RenderText_Blended(police, affichageNb, white);
apply_surface(positionX, positionY, texte, ecran, NULL);
positionX +=texte->w+marge;
sprintf(affichageNb, "%d",opt->nbJoueur);
texte = TTF_RenderText_Blended(police, affichageNb, white);
apply_surface(positionX, positionY, texte, ecran, NULL);
//position du bouton
boutons[6].x = positionX;
boutons[6].y = positionY;
boutons[6].w = texte->w;
boutons[6].h = texte->h;
/**Zone apparence du joueur*/
positionX = firstMarge;
positionY += texte->h + 2*marge;
texte = TTF_RenderText_Blended(police, "Apparence du joueur: ", white);
apply_surface(positionX, positionY, texte, ecran, NULL);
//btn player
if (opt->nbJoueur>1){
int i=0;
boutons = realloc(boutons, (7 + opt->nbJoueur) * sizeof(SDL_Rect));//reallocation
for (i=0; i<opt->nbJoueur; i++){
positionX +=texte->w+marge;
sprintf(affichageNb, "J%d",i+1); //ajout du char score
texte = TTF_RenderText_Blended(police, affichageNb, white);
apply_surface(positionX, positionY, texte, ecran, NULL);
//position du bouton
boutons[i+7].x = positionX;
boutons[i+7].y = positionY;
boutons[i+7].w = texte->w;
boutons[i+7].h = texte->h;
//affichage du joueur selectionné
if (joueurSelect == i){
rectangle(boutons[i+7].x,boutons[i+7].y,boutons[i+7].w, boutons[i+7].h, white, ecran); //contour de la case
}
}
}
//image charset
positionX = firstMarge;
positionY += texte->h + 2*marge;
SDL_Surface *charset = IMG_Load(araignee.pathName); //load le charset
apply_surface(positionX, positionY, charset, ecran, &araignee.clip);
//position du bouton
boutons[0].x = positionX;
boutons[0].y = positionY;
boutons[0].w = charset->w/16;
boutons[0].h = charset->h/16;
//image charset
positionX += araignee.clip.w+marge;
charset = IMG_Load(squelette.pathName); //load le charset
apply_surface(positionX, positionY, charset, ecran, &squelette.clip);
//position du bouton
boutons[1].x = positionX;
boutons[1].y = positionY;
boutons[1].w = charset->w/16;
boutons[1].h = charset->h/16;
//image charset
positionX += squelette.clip.w+marge;
charset = IMG_Load(farmer.pathName); //load le charset
apply_surface(positionX, positionY, charset, ecran, &farmer.clip);
//position du bouton
boutons[2].x = positionX;
boutons[2].y = positionY;
boutons[2].w = charset->w/farmer.nbImageAnim;
boutons[2].h = charset->h/4;
//.........这里部分代码省略.........
示例13: GWDBG_OUTPUT
void GW_PlatformSDL::initialize()
{
if (!initialized_)
{
GWDBG_OUTPUT("SDL: Initialize");
// initialize SDL video
if ( SDL_Init( sdlinit(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) ) < 0 )
throw GW_Exception(string("Unable to init SDL: "+string(SDL_GetError())));
#ifndef GW_NO_SDL_MIXER
if ( Mix_OpenAudio(22050, AUDIO_S16SYS, 1, audiobufsize_get()) < 0)
throw GW_Exception(string("Unable to init SDL_mixer: "+string(Mix_GetError())));
#endif
#ifndef GW_NO_SDL_TTF
if ( TTF_Init() < 0 )
throw GW_Exception(string("Unable to init SDL_ttf: "+string(TTF_GetError())));
#endif
#ifndef GW_NO_SDL_MIXER
Mix_AllocateChannels(6);
sound_volume(75);
#endif
custom_initialize();
// make sure SDL cleans up before exit
atexit(SDL_Quit);
// set application icon
plat_init();
// create a new window
window_ = SDL_CreateWindow("Game & Watch simulator - by Hitnrun / ZsoltK & Madrigal",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
width_, height_,
fullscreen_ ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_SHOWN);
if ( !window_ )
throw GW_Exception(string("Unable to allocate game window: " + string(SDL_GetError())));
renderer_ = SDL_CreateRenderer(window_, -1, SDL_RENDERER_ACCELERATED);
if ( !renderer_ )
throw GW_Exception(string("Unable to allocate renderer: " + string(SDL_GetError())));
// Let SDL & GPU do the scaling
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
SDL_RenderSetLogicalSize(renderer_, width_, height_);
SDL_ShowCursor(SDL_DISABLE);
#ifndef GW_NO_SDL_TTF
// load font
//font_=TTF_OpenFont( bf::path( bf::path(platformdata_get() ) / "andalemo.ttf" ).string().c_str(), fontsize_get() );
string pfont(platformdata_get() + "/" + "andalemo.ttf" );
font_=TTF_OpenFont( pfont.c_str(), fontsize_get() );
if (!font_)
throw GW_Exception(string("Unable to load font: "+string(TTF_GetError())));
#endif
initialized_=true;
}
}
示例14: Inventaire
void Inventaire(sJoueur *Perso,sMESS_ITEMS *items_data)
{
TTF_Init();
SDL_Rect postexte;
SDL_Surface *texte =NULL;
TTF_Font *police= NULL;
police = TTF_OpenFont("carolingia.ttf" ,50);
SDL_Color noire = {135,65,14};
int tabEquipement[10]={0,0,0,0,0,0,0,0,0,0};
SDL_Rect position,positionFenetreListe,positionFenetreSelect,positionOnglets,positionImagesOnglets,posrefreshEquipement;
//Affichage ecran
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface* ecran = NULL;
ecran=SDL_SetVideoMode(1680,1050,32,SDL_HWSURFACE/*|SDL_FULLSCREEN*/);
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
//Affichage interface
SDL_Surface* interface =NULL;
interface= SDL_LoadBMP("Sprites/II/Interface II.bmp");
SDL_SetColorKey(interface, SDL_SRCCOLORKEY, SDL_MapRGB(interface->format, 0, 0, 255));
position.x=0;
position.y=0;
//Affichage Fenetres Liste
SDL_Surface* fenetreListe = NULL;
fenetreListe = SDL_LoadBMP("Sprites/II/Liste II.bmp");
positionFenetreListe.x=113;
positionFenetreListe.y=189;
//Affichage Fenetres Select
SDL_Surface* fenetreSelect = NULL;
fenetreSelect = SDL_LoadBMP("Sprites/II/Fenetre Select II.bmp");
SDL_SetColorKey(fenetreSelect, SDL_SRCCOLORKEY, SDL_MapRGB(fenetreSelect->format, 0, 0, 255));
positionFenetreSelect.x=113;
positionFenetreSelect.y=0;
//Affichage Onglets
SDL_Surface* Onglets = NULL;
Onglets = SDL_LoadBMP("Sprites/II/Onglets II.bmp");
SDL_SetColorKey(Onglets, SDL_SRCCOLORKEY, SDL_MapRGB(Onglets->format, 0, 0, 255));
positionOnglets.x=722;
//Affichage Onglets
SDL_Surface* ImagesOnglets = NULL;
ImagesOnglets = SDL_LoadBMP("Sprites/II/Images Onglets II.bmp");
SDL_SetColorKey(ImagesOnglets, SDL_SRCCOLORKEY, SDL_MapRGB(ImagesOnglets->format, 0, 0, 255));
positionImagesOnglets.x=724;
positionImagesOnglets.y=162;
//Affichage Refresh Equipement
SDL_Surface* refreshEquipement = NULL;
refreshEquipement = SDL_LoadBMP("Sprites/II/Refersh Equipement II.bmp");
SDL_SetColorKey(refreshEquipement, SDL_SRCCOLORKEY, SDL_MapRGB(refreshEquipement->format, 0, 0, 255));
posrefreshEquipement.x=724;
posrefreshEquipement.y=162;
int tabObjet[10];
int deplaList=0;
int listType=1;
SDL_BlitSurface(interface,NULL,ecran,&position);
positionOnglets.y=156;
SDL_BlitSurface(Onglets,NULL,ecran,&positionOnglets);
positionOnglets.y=287;
SDL_BlitSurface(Onglets,NULL,ecran,&positionOnglets);
positionOnglets.y=419;
SDL_BlitSurface(Onglets,NULL,ecran,&positionOnglets);
positionOnglets.y=550;
SDL_BlitSurface(Onglets,NULL,ecran,&positionOnglets);
positionOnglets.y=682;
SDL_BlitSurface(Onglets,NULL,ecran,&positionOnglets);
SDL_BlitSurface(ImagesOnglets,NULL,ecran,&positionImagesOnglets);
affListeInventaire(tabObjet, deplaList ,listType,fenetreListe, ecran, texte, positionFenetreListe, postexte, items_data, police, noire);
SDL_Flip(ecran);
int Select=0;
//EVENT
int continuer = 1;
SDL_Event event;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
//.........这里部分代码省略.........
示例15: printf
// initialize application display variables
bool SDLApp::init()
{
bool success = true;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
success = false;
}
//Create window
window = SDL_CreateWindow( "GemsArr", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Create renderer for window
renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED );
if( renderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Initialize renderer color
SDL_SetRenderDrawColor( renderer, 0xFF, 0xFF, 0xFF, 0xFF );
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ) )
{
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
success = false;
}
//Initialize SDL_mixer
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
//Initialize SDL_ttf
if( TTF_Init() == -1 )
{
printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
}
game = new Game();
// fetches media from respective folders
game->fetchMedia();
// loads all the media required
game->loadMedia( renderer );
// prints board
cout << game->stringGrid();
// prints available moves
cout << game->stringMoveList( game->moveList() );
return true;
}
}
return success;
}