本文整理汇总了C++中TTF_OpenFont函数的典型用法代码示例。如果您正苦于以下问题:C++ TTF_OpenFont函数的具体用法?C++ TTF_OpenFont怎么用?C++ TTF_OpenFont使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TTF_OpenFont函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: game_menu
void game_menu(t_window *w, t_music *m, t_list *l, t_text *t, t_font *f, t_image *img)
{
int next;
int height, width;
SDL_Event event;
SDL_Rect posBox;
SDL_Surface *menu_box;
SDL_Color white_color = {255,255,255,255};
SDL_Surface *texte = NULL;
TTF_Font *font;
next = 1;
posBox.x = (atoi(w->sizeX) - atoi(w->sizeX) / 2.5) / 2;
posBox.y = (atoi(w->sizeY) - (((atoi(w->sizeY) / 10) * 5) + ((atoi(w->sizeY) / 7) * 3))) / 2;
if ((font = TTF_OpenFont(f->font_used, f->size_font + 10)) == NULL)
show_error(4);
f->posText.y = (atoi(w->sizeY) + atoi(w->sizeY) / 16 - (((atoi(w->sizeY) / 10) * 5) + ((atoi(w->sizeY) / 7) * 3))) / 2;
menu_box = SDL_CreateRGBSurface(SDL_HWSURFACE, atoi(w->sizeX) / 2.5, atoi(w->sizeY) / 10, 32, 0, 0, 0, 0);
SDL_FillRect(menu_box, NULL, SDL_MapRGB(w->screen->format, 0, 0, 0));
SDL_BlitSurface(w->background, NULL, w->screen, &w->posBack);
f->posText.y += atoi(w->sizeY) / 7;
posBox.y += atoi(w->sizeY) / 7;
SDL_BlitSurface(menu_box, NULL, w->screen, &posBox);
TTF_SizeText(font, "SAVE", &width, &height);
f->posText.x = ((atoi(w->sizeX) + (atoi(w->sizeX) / 2.5)) - (width + (atoi(w->sizeX) / 2.5))) / 2;
/* posText = ((TailleFenetre + TailleBox) - (TaillePolice + TailleBox)) / 2 */
texte = TTF_RenderText_Blended(font, "SAVE", white_color);
SDL_BlitSurface(texte, NULL, w->screen, &f->posText);
posBox.y += atoi(w->sizeY) / 7;
SDL_BlitSurface(menu_box, NULL, w->screen, &posBox);
TTF_SizeText(font, "LOAD GAME", &width, &height);
f->posText.x = ((atoi(w->sizeX) + (atoi(w->sizeX) / 2.5)) - (width + (atoi(w->sizeX) / 2.5))) / 2;
f->posText.y += atoi(w->sizeY) / 7;
texte = TTF_RenderText_Blended(font, "LOAD GAME", white_color);
SDL_BlitSurface(texte, NULL, w->screen, &f->posText);
posBox.y += atoi(w->sizeY) / 7;
SDL_BlitSurface(menu_box, NULL, w->screen, &posBox);
TTF_SizeText(font, "SOUND", &width, &height);
f->posText.x = ((atoi(w->sizeX) + (atoi(w->sizeX) / 2.5)) - (width + (atoi(w->sizeX) / 2.5))) / 2;
f->posText.y += atoi(w->sizeY) / 7;
texte = TTF_RenderText_Blended(font, "SOUND", white_color);
SDL_BlitSurface(texte, NULL, w->screen, &f->posText);
posBox.y += atoi(w->sizeY) / 7;
SDL_BlitSurface(menu_box, NULL, w->screen, &posBox);
TTF_SizeText(font, "GRAPHICS", &width, &height);
f->posText.x = ((atoi(w->sizeX) + (atoi(w->sizeX) / 2.5)) - (width + (atoi(w->sizeX) / 2.5))) / 2;
f->posText.y += atoi(w->sizeY) / 7;
texte = TTF_RenderText_Blended(font, "GRAPHICS", white_color);
SDL_BlitSurface(texte, NULL, w->screen, &f->posText);
posBox.y += atoi(w->sizeY) / 7;
SDL_BlitSurface(menu_box, NULL, w->screen, &posBox);
TTF_SizeText(font, "QUIT GAME", &width, &height);
f->posText.x = ((atoi(w->sizeX) + (atoi(w->sizeX) / 2.5)) - (width + (atoi(w->sizeX) / 2.5))) / 2;
f->posText.y += atoi(w->sizeY) / 7;
texte = TTF_RenderText_Blended(font, "QUIT GAME", white_color);
SDL_BlitSurface(texte, NULL, w->screen, &f->posText);
SDL_SetAlpha(f->text_support, SDL_SRCALPHA, 100);
SDL_Flip(w->screen);
while (next)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
clean_exit(w, m, l, t);
break;
case SDL_MOUSEBUTTONUP:
if (event.button.button == SDL_BUTTON_LEFT)
events2(w, m, l, t, f, img);
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_RETURN:
break;
case SDLK_SPACE:
break;
case SDLK_DOWN:
break;
case SDLK_UP:
break;
case SDLK_ESCAPE:
events2(w, m, l, t, f, img);
break;
default:
break;
}
break;
default:
break;
}
}
//.........这里部分代码省略.........
示例2: load_files
//carrega recursos do jogo
void load_files()
{
tileB = IMG_Load("tileB.png");
tileP = IMG_Load("tileP.png");
font = TTF_OpenFont( "arial.ttf", 28 );
}
示例3: TTF_OpenFont
TextPrinter &TextPrinter::font(const char* font_name,int size) {
if(mFont != 0) TTF_CloseFont(mFont);
mFont = TTF_OpenFont( font_name, size );
if(mFont == NULL) Logger::logError("Font is currently NULL!!!!!!!") << std::endl;
return *this;
}
示例4: main
//.........这里部分代码省略.........
sfx_c4->amp_start = 0.3;
sfx_c4->amp_end = 0.1;
sfx_c4->freq_start = 261.626;
sfx_c4->freq_end = 261.626;
sfx_f4 = sound_synth_get(7);
sfx_f4->waveform = SYNTH_SQUARE;
sfx_f4->length = 180;
sfx_f4->delay = 0;
sfx_f4->amp_start = 0.3;
sfx_f4->amp_end = 0.1;
sfx_f4->freq_start = 349.228;
sfx_f4->freq_end = 349.228;
level = 0;
gravity = 0.8;
framefn = &_introfn;
memset(&controls, 0, sizeof(Controls));
memset(&player, 0, sizeof(Player));
player.hearts = 10;
player.rect.w = 48;
player.rect.h = 64;
// level_place_player();
player.spriterect.x = 192;
player.spriterect.y = 0;
player.spriterect.w = 48;
player.spriterect.h = 64;
font = TTF_OpenFont("Vera.ttf", 16);
screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
load_sprites();
mygoats = (Goat**) malloc(sizeof(Goat*) * 16);
memset(mygoats, 0, sizeof(Goat*) * 16);
// mygoats[0] = goat_create(100, 10);
// mygoats[1] = goat_create(300, 10);
// mygoats[2] = goat_create(500, 10);
myslimes = (Slime**) malloc(sizeof(Slime*) * 16);
memset(myslimes, 0, sizeof(Slime*) * 16);
// myslimes[0] = slime_create(400, 10, 1);
// myslimes[0]->controls.left = 1;
// fpsreport = SDL_GetTicks() + 1000;
while (!quit)
{
frameDelta = SDL_GetTicks() - frameStart;
frameStart = SDL_GetTicks();
framefn(frameDelta);
while (SDL_PollEvent(&ev))
{
switch (ev.type)
{
case SDL_KEYDOWN:
switch (ev.key.keysym.sym)
示例5: DungeonMasterUi_create
DungeonMasterUi* DungeonMasterUi_create(struct Player* player) {
DungeonMasterUi* this = malloc(sizeof(DungeonMasterUi));
this->cards = List_create();
SDL_Renderer* renderer = player->scene->engine->renderer;
TextureCache* tc = player->scene->engine->textureCache;
this->player = player;
this->background.x = player->scene->camera->translation.x;
this->background.y = player->scene->camera->translation.y;
this->background.w = player->scene->background->bounds.w;
this->background.h = player->scene->background->bounds.h;
this->cardFont = TTF_OpenFont("fonts/Black-Chancery.ttf", 16);
SDL_Point p = {.x = player->scene->camera->translation.x, .y=250};
List_pushBack(this->cards, Card_create(p, renderer, tc, "images/uiWhiteKnight.png", CARD_SUMMON_WHITKNIGHT, 10, this->cardFont, "Summon Skeleton Knight"));
p.x += ((Card*)this->cards->first->data)->background->bounds.w + 5;
List_pushBack(this->cards, Card_create(p, renderer, tc, "images/blue/cursor.png", CARD_CONTROL_STRONGEST, 5, this->cardFont, "Control strongest enemy"));
p.x += ((Card*)this->cards->first->data)->background->bounds.w + 5;
//List_pushBack(this->cards, Card_create(renderer, tc, "images/uiWhiteKnight.png", CARD_SUMMON_WHITKNIGHT, 15, this->cardFont, "Summon Skeleton Knight"));
SDL_Color white = {.r=255, .g=255, .b=255, .a=255};
p.x = player->scene->camera->translation.x;
char hintActionHotkey[256];
char* hotkeyName = Input_keycodeToPrintable(Input_getHotkeyForAction(player->input, action));
sprintf(hintActionHotkey, "Use: %s", hotkeyName);
free(hotkeyName);
this->hintSummonHotkey = Sprite_create(SDL_CreateTextureFromSurface(
renderer,
TTF_RenderUTF8_Blended(this->cardFont, hintActionHotkey, white)
)
);
this->hintSummonHotkey->bounds.x = p.x;
this->hintSummonHotkey->bounds.y = p.y += ((Card*)this->cards->first->data)->background->bounds.h + 5;
char hintNextHotkey[256];
hotkeyName = Input_keycodeToPrintable(Input_getHotkeyForAction(player->input, attackSword));
sprintf(hintNextHotkey, "N. %s", hotkeyName);
free(hotkeyName);
this->hintNextHotkey = Sprite_create(SDL_CreateTextureFromSurface(
renderer,
TTF_RenderUTF8_Blended(this->cardFont, hintNextHotkey, white)
)
);
this->hintNextHotkey->bounds.x = p.x;
this->hintNextHotkey->bounds.y = this->hintSummonHotkey->bounds.y + this->hintSummonHotkey->bounds.h;
char hintPreviousHotkey[256];
hotkeyName = Input_keycodeToPrintable(Input_getHotkeyForAction(player->input, attackBow));
sprintf(hintPreviousHotkey, "P. %s", hotkeyName);
free(hotkeyName);
this->hintPreviousHotkey = Sprite_create(SDL_CreateTextureFromSurface(
renderer,
TTF_RenderUTF8_Blended(this->cardFont, hintPreviousHotkey, white)
)
);
this->hintPreviousHotkey->bounds.x = p.x;
this->hintPreviousHotkey->bounds.y = this->hintNextHotkey->bounds.y + this->hintNextHotkey->bounds.h;
char indicatorpath[128];
sprintf(indicatorpath, "images/%s/indicator.png", player->scene->colorPrefix);
this->indicator = Sprite_create(TextureCache_getForUnconstantPath(tc, indicatorpath));
this->indicator->bounds.y = ((Card*)this->cards->first->data)->background->bounds.y - this->indicator->bounds.h -2;
this->selected = this->cards->first;
return this;
}
void DungeonMasterUi_destroy(DungeonMasterUi* this) {
FREE_LIST_WITH_ELMENTS(this->cards, Card_destroy);
TTF_CloseFont(this->cardFont);
}
void DungeonMasterUi_summonSelectedCard(DungeonMasterUi* this, struct Scene* scene, SDL_Point tilePosition) {
Card* card = this->selected->data;
if (card && this->player->money >= card->cost) {
Player_earnMoney(this->player, -card->cost);
if (card->type == CARD_SUMMON_WHITKNIGHT) {
if (Scene_getTile(scene, tilePosition) == NULL) {
Enemy* enemy = Enemy_createWhiteKnight(scene, tilePosition);
Scene_addEntity(scene, enemy->entity);
}
} else if (card->type == CARD_CONTROL_STRONGEST) {
Entity* strongest = NULL;
for (int i=0; i < scene->entities->usedElements; ++i) {
Entity* e = scene->entities->elements[i];
if (e && (e->physics.belongsToGroups & COLLISION_GROUP_ENEMY)) {
if (!strongest || e->attack1 > strongest->attack1) {
strongest = e;
}
}
}
if (strongest) {
ControlledEntity_set(&this->player->controlledEntity, strongest);
}
}
}
}
//.........这里部分代码省略.........
示例6: FTinit
int FTinit(font_data *font, const char * fontname, int ptsize)
{
int i;
SDL_Color white = { 0xFF, 0xFF, 0xFF, 0x00 };
SDL_Color black = { 0x00, 0x00, 0x00, 0 };
SDL_Color *forecol;
SDL_Color *backcol;
GLenum gl_error;
texcoord_t texcoords;
int minx = 0,miny = 0,maxx = 0,maxy = 0;
/* We might support changing theese later */
/* Look for special rendering types */
renderstyle = TTF_STYLE_NORMAL;
rendertype = RENDER_LATIN1;
/* Default is black and white */
forecol = &white;
backcol = &black;
/* Initialize the TTF library */
/*if ( TTF_Init() < 0 ) {
fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());
return(2);
}*/
font->ttffont = TTF_OpenFont(fontname, ptsize);
if ( font->ttffont == NULL ) {
fprintf(stderr, "Couldn't load %d pt font from %s: %s\n", ptsize, fontname, SDL_GetError());
return(2);
}
TTF_SetFontStyle(font->ttffont, renderstyle);
font->list_base=glGenLists(next_p2(NUMCHARS));
/* Get the recommended spacing between lines of text for this font */
font->linespacing = TTF_FontLineSkip(font->ttffont);
font->h = ptsize;
for( i = 0; i < NUMCHARS; i++ ) {
SDL_Surface *glyph = NULL;
GLuint height = 0; /* kps - added default value */
forecol = &white;
glyph = TTF_RenderGlyph_Blended( font->ttffont, i, *forecol );
if(glyph) {
glGetError();
font->textures[i] = SDL_GL_LoadTexture(glyph, &texcoords);
if ( (gl_error = glGetError()) != GL_NO_ERROR )
printf("Warning: Couldn't create texture: 0x%x\n", gl_error);
font->W[i] = glyph->w;
height = glyph->h;
TTF_GlyphMetrics( font->ttffont, i, &minx,&maxx,&miny,&maxy,NULL);
}
SDL_FreeSurface(glyph);
glNewList(font->list_base+i,GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, font->textures[i]);
glTranslatef(1,0,0);
glPushMatrix();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(texcoords.MinX, texcoords.MaxY);
glVertex2i(0 , miny);
glTexCoord2f(texcoords.MaxX, texcoords.MaxY);
glVertex2i(font->W[i] , miny);
glTexCoord2f(texcoords.MinX, texcoords.MinY);
glVertex2i(0 ,miny+height );
glTexCoord2f(texcoords.MaxX, texcoords.MinY);
glVertex2i(font->W[i] , miny+height);
glEnd();
glPopMatrix();
glTranslatef((font->W[i]>3)?font->W[i]:(font->W[i] = 3) + 1,0,0);
/*one would think this should be += 2... I guess they overlap or the edge
* isn't painted
*/
font->W[i] += 1;
glEndList();
}
/*TTF_CloseFont(font->ttffont);*/
/*TTF_Quit();*/
return 0;
}
示例7: main
//Main function
int main(int argc, char* argv[])
{
/*
-----
// INITIALIZATION
-----
*/
//Seed RNG
srand(time(NULL));
//Initialize all SDL subsystems
if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}
//Initialize SDL_TTF
TTF_Init();
TTF_Font * planetFont = TTF_OpenFont("corbel.ttf", 20);
//Set up the screen
SDL_Surface* screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE);
//Make sure screen set up
if (screen == NULL)
{
return false;
}
//Set the window caption
SDL_WM_SetCaption("GAEM", NULL);
//Create an event manager
SDL_Event event;
//Store keystates
Uint8* keystates;
//Set up camera
SDL_Rect camera = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
float camerax = 0;
float cameray = 0;
/*
-----
GAME SETUP
-----
*/
//Set up ship stats
std::vector<ShipStats> shipstats(10);
for (int i = 0; i < 10; i++)
{
shipstats[i].attack = i+1;
shipstats[i].defense = i+1;
shipstats[i].speed = DEFAULT_FLEET_SPEED;
shipstats[i].interceptRange = 200;
shipstats[i].interceptDamage = 0.1;
shipstats[i].interceptCD = 250;
}
//Set up ship type 1: Heavy ship
shipstats[1].attack = 3;
shipstats[1].defense = 2;
shipstats[1].speed = DEFAULT_FLEET_SPEED/2;
//Set up ship type 2: Fiery attack ship
shipstats[2].attack = 2;
shipstats[2].defense = 1;
shipstats[2].speed = DEFAULT_FLEET_SPEED*1.25;
//Set up buildings and building rules
std::list<Building> buildings;
std::vector<std::list<Building*> > buildRules;
buildRules.resize(2);
SDL_Surface* b01 = loadImage("b01.png");
SDL_Surface* bc01 = loadImage("bc01.png");
SDL_Surface* b02 = loadImage("b02.png");
SDL_Surface* bc02 = loadImage("bc02.png");
buildings.push_back(Building(b01, bc01, "build 0 2")); //0
buildings.push_back(Building(b02, bc02, "fire damage 2 1")); //1
buildings.push_back(Building(b01, bc01, "build 1 4")); //2
buildings.push_back(Building(b01, bc01, "build 2 2")); //3
buildings.push_back(Building(b02, bc02, "aura damage 1 total")); //4
//0
std::list<Building>::iterator bi = buildings.begin();
buildRules[0].push_back(&(*bi));
bi->setBuildTime(15000);
bi++;
//1
buildRules[0].push_back(&(*bi));
bi->setBuildTime(10000);
bi->setRange(250);
bi++;
//2
//.........这里部分代码省略.........
示例8: SDL_Init
char ModeloFactory::nuevoElegirMisiones(std::list<ParserYaml::stEscenario>& listaEscenarios){
bool quit = false;
bool clicBotonMouseIzquierdo = false;
int posicionMouseX, posicionMouseY;
char misionElegida;
SDL_Event event;
TTF_Font *fuente = NULL;
SDL_Color textColor = { 255, 255, 255 }; //color blanco
SDL_Surface* pantalla = NULL;
SDL_Init( SDL_INIT_EVERYTHING );
pantalla = SDL_SetVideoMode( PANTALLA_ANCHO, PANTALLA_ALTO, SCREEN_BPP, SDL_SWSURFACE );
TTF_Init();
SDL_WM_SetCaption( "Misiones", NULL );
SDL_Surface *imagenDeFondo = NULL;
imagenDeFondo = ImageLoader::getInstance().load_image( "./img/background4.png" );
fuente = TTF_OpenFont( "./fonts/Verdana.ttf", 28 );
SDL_Surface* textoMisionCarnicero = TTF_RenderText_Solid( fuente, "Mision Carnicero", textColor );
SDL_Surface* textoMisionBanderas = TTF_RenderText_Solid( fuente, "Mision Banderas", textColor );
SDL_BlitSurface( imagenDeFondo, NULL, pantalla, NULL );
SDL_Rect offset;
offset.x = 50;
offset.y = 190;
SDL_BlitSurface( textoMisionCarnicero, NULL, pantalla, &offset );
rectangleRGBA( pantalla, 48, 190, 295, 225, 0, 255, 0, 255);
offset.x = 350;
offset.y = 190;
SDL_BlitSurface( textoMisionBanderas, NULL, pantalla, &offset );
rectangleRGBA( pantalla, 348, 190, 595, 225, 0, 255, 0, 255);
SDL_Flip( pantalla );
while( quit == false ) {
while( SDL_PollEvent( &event ) ) {
switch (event.type) {
case SDL_QUIT:
quit = true;
break;
case SDL_MOUSEMOTION:
posicionMouseX = event.motion.x;
posicionMouseY = event.motion.y;
break;
case SDL_MOUSEBUTTONDOWN:
switch (event.button.button) {
case SDL_BUTTON_LEFT:
clicBotonMouseIzquierdo = true;
break;
}
break;
case SDL_MOUSEBUTTONUP:
switch (event.button.button) {
case SDL_BUTTON_LEFT:
clicBotonMouseIzquierdo = false;
break;
}
break;
}
}
if (clicBotonMouseIzquierdo && posicionMouseX >48 && posicionMouseX <295 && posicionMouseY >190 && posicionMouseY <225){
misionElegida = 1;
std::cout << "Mision Elegida Carnicero" << std::endl;
Log::getInstance().log(1,__FILE__,__LINE__,"Mision Elegida Carnicero");
std::list<ParserYaml::stEscenario>::iterator it=listaEscenarios.begin();
advance(it, 0);
std::cout << "Se usara el escenario: "<< (*it).nombre << std::endl;
this->juegoElegido.nombreEscenario = (*it).nombre;
this->juegoElegido.escenario = (*it);
SDL_FreeSurface( imagenDeFondo );
SDL_FreeSurface( textoMisionCarnicero );
SDL_FreeSurface( textoMisionBanderas );
SDL_FreeSurface( pantalla );
TTF_CloseFont( fuente );
TTF_Quit();
SDL_Quit();
return misionElegida;
}
else if (clicBotonMouseIzquierdo && posicionMouseX >348 && posicionMouseX <595 && posicionMouseY >190 && posicionMouseY <225){
misionElegida = 2;
std::cout << "Mision Elegida Banderas" << std::endl;
Log::getInstance().log(1,__FILE__,__LINE__,"Mision Elegida Banderas");
std::list<ParserYaml::stEscenario>::iterator it=listaEscenarios.begin();
advance(it, 1);
std::cout << "Se usara el escenario: "<< (*it).nombre << std::endl;
this->juegoElegido.nombreEscenario = (*it).nombre;
this->juegoElegido.escenario = (*it);
SDL_FreeSurface( imagenDeFondo );
SDL_FreeSurface( textoMisionCarnicero );
SDL_FreeSurface( textoMisionBanderas );
SDL_FreeSurface( pantalla );
TTF_CloseFont( fuente );
TTF_Quit();
SDL_Quit();
return misionElegida;
}
}
SDL_FreeSurface( imagenDeFondo );
SDL_FreeSurface( textoMisionCarnicero );
SDL_FreeSurface( textoMisionBanderas );
SDL_FreeSurface( pantalla );
TTF_CloseFont( fuente );
TTF_Quit();
SDL_Quit();
return 3;
//.........这里部分代码省略.........
示例9: InitGFX
/* Setup SDL */
void InitGFX(){
static int flags=0;
/* Define the program icon */
#ifdef _WIN32
program_icon = SDL_LoadBMP("irixbasic-icon-32px.bmp");
#else
program_icon = SDL_LoadBMP("irixbasic-icon-128px.bmp");
#endif
char *msg;
/* Initialize SDL */
if (SDL_Init (SDL_INIT_VIDEO) < 0)
{
sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());
/*MessageBox (0, msg, "Error", program_icon);*/
free (msg);
exit (1);
}
atexit (SDL_Quit);
/* Set video mode */
screen = SDL_SetVideoMode (screen_width, screen_height, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL)
{
sprintf (msg, "Couldn't set %dx%dx16 video mode: %s\n", screen_width, screen_height, SDL_GetError ());
printf("%s",msg);
free (msg);
exit (2);
}
flags = screen->flags;
/* Check if the enable fullscreen argument is turned on */
if(enable_fullscreen){
screen = SDL_SetVideoMode(0, 0, 0, screen->flags ^ SDL_FULLSCREEN);
screen_width = screen->w;
screen_height = screen->h;
if(screen == NULL)
{
screen = SDL_SetVideoMode(0, 0, 0, flags); /* If toggle FullScreen failed, then switch back */
}
if(screen == NULL)
{
exit(1); /* If you can't switch back for some reason, then fail */
}
}
SDL_WM_SetIcon(program_icon, NULL);
SDL_WM_SetCaption ("IRIXBASIC", "IRIXBASIC");
/* Create background screen colors*/
screen_color = SDL_MapRGB(screen->format, 66, 66, 231);
frame_color = SDL_MapRGB(screen->format, 165, 165, 255);
debug_color = SDL_MapRGB(screen->format, 126, 126, 126);
/* light blue */
foreground_color.r = 165;
foreground_color.g = 165;
foreground_color.b = 255;
/* dark blue */
background_color.r = 66;
background_color.g = 66;
background_color.b = 231;
/* Setup a rect for the full screen */
screen_rect.h = screen->h;
screen_rect.w = screen->w;
/* frame border width 36px / height 45px */
display_area_rect.x = 36;
display_area_rect.y = 45;
display_area_rect.w = screen->w-(36*2);
display_area_rect.h = screen->h-(45*2);
/* Set up the SDL_TTF */
TTF_Init();
atexit(TTF_Quit);
/* TTF_Init() is like SDL_Init(), but with no parameters. Basically, it initializes
SDL_TTF. There's really not much to it. Remember, when the program ends, we
have to call TTF_Quit(). atexit(TTF_Quit) ensures that when we call exit(), the
program calls TTF_Quit() for us. */
fntc64 = TTF_OpenFont( "./C64_User_Mono_v1.0-STYLE.ttf", fontsize );
/* Get the size of a character in pixels */
if(TTF_SizeText(fntc64,"B",&character_with,&character_height)) {
printf("SDL_TTF error: %s", TTF_GetError());
} else {
total_text_rows = (display_area_rect.h/character_height)-1;
//.........这里部分代码省略.........
示例10: main
//.........这里部分代码省略.........
show_dshow_device();
//Show Device Options
show_dshow_device_option();
//Show VFW Options
show_vfw_device();
#if USE_DSHOW
AVInputFormat *ifmt=av_find_input_format("dshow");
AVDictionary* options = NULL;
av_dict_set(&options,"video_size","320x240",0); //设置更改分辨率
//av_set_options_string();
//Set own video device's name
if(avformat_open_input(&pFormatCtx,"video=QuickCam Orbit/Sphere AF",ifmt,&options)!=0){
printf("Couldn't open input stream.(无法打开输入流)\n");
return -1;
}
#else
AVInputFormat *ifmt=av_find_input_format("vfwcap");
if(avformat_open_input(&pFormatCtx,"0",ifmt,NULL)!=0){
printf("Couldn't open input stream.(无法打开输入流)\n");
return -1;
}
#endif
#endif
//Linux
#ifdef linux
AVInputFormat *ifmt=av_find_input_format("video4linux2");
if(avformat_open_input(&pFormatCtx,"/dev/video0",ifmt,NULL)!=0){
printf("Couldn't open input stream.(无法打开输入流)\n");
return -1;
}
#endif
if(avformat_find_stream_info(pFormatCtx,NULL)<0)
{
printf("Couldn't find stream information.(无法获取流信息)\n");
return -1;
}
videoindex=-1;
for(i=0; i<pFormatCtx->nb_streams; i++)
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
videoindex=i;
break;
}
if(videoindex==-1)
{
printf("Couldn't find a video stream.(没有找到视频流)\n");
return -1;
}
pCodecCtx=pFormatCtx->streams[videoindex]->codec;
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL)
{
printf("Codec not found.(没有找到解码器)\n");
return -1;
}
if(avcodec_open2(pCodecCtx, pCodec,NULL)<0)
{
printf("Could not open codec.(无法打开解码器)\n");
return -1;
}
AVFrame *pFrame,*pFrameYUV;
pFrame=avcodec_alloc_frame();
pFrameYUV=avcodec_alloc_frame();
uint8_t *out_buffer=(uint8_t *)av_malloc(avpicture_get_size(PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height));
avpicture_fill((AVPicture *)pFrameYUV, out_buffer, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
//SDL----------------------------
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
printf( "Could not initialize SDL - %s\n", SDL_GetError());
return -1;
}
int screen_w=0;
int screen_h=0;
SDL_Surface *screen;
//////////////////////////////////////////////////////////////////////////
//王全洲 2015年5月29日19:46:56 增加在YUV上显示时间的功能
SDL_Surface *pText;
TTF_Font *font;
char szTime[32]={"hello world"};
//初始化字体库
if (TTF_Init()==-1)
{
cout<<"初始化字库失败!"<<endl;
return 0;
}
/* 打开simfang.ttf 字库,设字体为20号 */
font=TTF_OpenFont("C:\\Windows\\Fonts\\Arial.ttf",20);
if (font==NULL)
{
cout<<"error load C:\\Windows\Fonts\\Arial.ttf,please make sure it is existed"<<endl;
return 0;
}
示例11: main
int main(int argc, char* argv[]) {
SDL_Window *window; // Declare a pointer
if(init_SDL_all() != 0) {
return 1;
}
// Create an application window with the following settings:
window = SDL_CreateWindow(
WINDOW_NAME, // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
SCREEN_WIDTH, // width, in pixels
SCREEN_HEIGHT, // height, in pixels
SDL_WINDOW_OPENGL // flags - see below
);
if (window == NULL) {
return logSDLError("Could not create window");
}
SDL_Renderer* ren;
ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (ren == NULL) {
return logSDLError("Could not create renderer");
}
dropData = getDrops();
srand(time(NULL));
//Open the font
font = TTF_OpenFont(fontFile, fontSize);
if (font == NULL){
return logSDLError("TTF_OpenFont");
}
background = loadTexture("images/bkg.png", ren);
SDL_Texture *image = loadTexture("images/image.bmp", ren);
if (background == NULL || image == NULL) {
return 4;
}
SDL_Texture *sheet = loadTexture("images/sheet.png", ren);
blocks = loadTexture("images/blocks.png", ren);
//iW and iH are the clip width and height
//We'll be drawing only clips so get a center position for the w/h of a clip
int iW = 100, iH = 100;
int x = SCREEN_WIDTH / 2 - iW / 2;
int y = SCREEN_HEIGHT / 2 - iH / 2;
//Setup the clips for our image
SDL_Rect clips[4];
int i;
for (i = 0; i < 4; ++i){
clips[i].x = i / 2 * iW;
clips[i].y = i % 2 * iH;
clips[i].w = iW;
clips[i].h = iH;
}
//Specify a default clip to start with
for(i=0; i < NUMBER_OF_BLOCKS; i++) {
blockClips[i].x = i * BLOCK_SIZE;
blockClips[i].y = 0;
blockClips[i].w = BLOCK_SIZE;
blockClips[i].h = BLOCK_SIZE;
}
nextPiece = pickNewPiece();
useClip = pickNewPiece();
//SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example
//Our event structure
SDL_Event e;
bool quit = false;
while (!quit){
SDL_Delay(FRAME_TIME_DELAY);
// Event loop for each possible game mode
if(mode == MODE_GAMEOVER) {
printf("\nGAME OVER\nScore: %lu\n\n", score);
quit = true;
break;
} else if(mode == MODE_PAUSE) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_KEYDOWN) {
switch (e.key.keysym.sym){
case SDLK_p:
mode = MODE_RUNNING;
break;
case SDLK_q:
case SDLK_ESCAPE:
quit = true;
break;
//.........这里部分代码省略.........
示例12: main
int main(int argc , char ** argv)
{
char a;
struct key key;
int loop;
int menu;
int selectedMenu;
/* Initialisation simple */
if (argc == 1)
a = argv[0][0];
if (SDL_Init(SDL_INIT_VIDEO) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError());
return -1;
}
//writeScore("Flo 2", 92);
TTF_Init();
/* Création de la fenêtre */
SDL_Window* pWindow = NULL;
SDL_Renderer* pRenderer = NULL;
SDL_Surface* pSurface = NULL;
TTF_Font* font = TTF_OpenFont("/Library/Fonts/Microsoft/Arial.ttf", 72);
pWindow = SDL_CreateWindow("Space Invaders",SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
SDL_WINDOW_SHOWN);
pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_PRESENTVSYNC);
/* Initialisation du texte */
if ( pWindow )
{
loop = 1;
menu = 1;
selectedMenu = 1;
while (loop == 1) {
key = getKey(key);
if (key.exit == 1)
loop = 0;
if (menu == 1) {
if (key.down == 1 && selectedMenu < 4)
selectedMenu++;
else if (key.up == 1 && selectedMenu > 1)
selectedMenu--;
else if (key.enter == 1) {
if (selectedMenu == 1)
menu = 0;
else if (selectedMenu == 2)
menu = 1; //doing nothing yet
else if (selectedMenu == 3)
menu = 2;
else if (selectedMenu == 4)
loop = 0;
}
pRenderer = drawMenu(pRenderer, selectedMenu, font, pSurface);
}
else if (menu == 2) {
if (key.enter == 1)
menu = 1;
else
pRenderer = drawHighScores(pRenderer, font, pSurface);
}
else
pRenderer = drawGame(pRenderer);
SDL_Delay(100);
}
}
TTF_CloseFont(font);
SDL_DestroyWindow(pWindow);
TTF_Quit();
SDL_Quit();
return 0;
}
示例13: main
int main(int argc, char *argv[])
{
/* initialize SDL and its subsystems */
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) die();
if (TTF_Init() == -1) die();
/* set the height and width of the main window, as well as the number
of bits per pixel; this needs to be done prior to initializing the
main window (*screen, below) */
initWindowAttributes();
/* the frame buffer */
SDL_Surface *screen = SDL_SetVideoMode(W_WIDTH, W_HEIGHT,
W_COLOR_DEPTH, SDL_HWSURFACE|SDL_FULLSCREEN);
if (!screen) die();
/* hide the mouse cursor */
SDL_ShowCursor(SDL_DISABLE);
/* the background color of the screen */
const Uint32 clearColor = CLEAR_COLOR(screen->format);
clearScreen(screen, clearColor);
/* clearColor as an SDL_Color, for use with TTF */
Uint8 r, g, b;
SDL_GetRGB(clearColor, screen->format, &r, &g, &b);
SDL_Color bgColor = { r: r, g: g, b: b };
/* the score font */
TTF_Font *font = TTF_OpenFont("resources/VeraMono.ttf", FONT_SIZE);
if (!font) die();
SDL_Color fontColor = FONT_COLOR;
/* the score text; we'll allow three digits plus the terminating '\0' */
char *lScoreStr = malloc(sizeof(char) * 4);
char *rScoreStr = malloc(sizeof(char) * 4);
if (!lScoreStr || !rScoreStr) die();
SDL_Surface *lScore = NULL, *rScore = NULL;
SDL_Rect lScorePos = { x: C_X+FONT_SIZE, y: C_HEIGHT/5,
w: F_WIDTH, h: F_HEIGHT };
SDL_Rect rScorePos = { x: (C_X+C_WIDTH)-3*FONT_SIZE, y: C_HEIGHT/5,
w: F_WIDTH, h: F_HEIGHT };
/* set up the playing court */
Court *court = makeCourt(screen);
if (!court) die();
/* set up the players and their paddles */
Player *lPlayer = makePlayer(screen);
Player *rPlayer = makePlayer(screen);
if (!lPlayer || !rPlayer) die();
rPlayer->paddle.rect.x = C_X + C_WIDTH - P_WIDTH;
/* add the ball */
Ball *ball = makeBall(screen);
if (!ball) die();
/* because SDL_KEY(UP|DOWN) occurs only once, not continuously while
the key is pressed, we need to keep track of whether a key is
(still) pressed */
bool lPlayerShouldMoveUp = false, lPlayerShouldMoveDown = false,
rPlayerShouldMoveUp = false, rPlayerShouldMoveDown = false;
Uint32 startTime; /* denotes the beginning of each iteration
of the main event loop */
bool running = true; /* true till the application should exit */
while (running) {
startTime = SDL_GetTicks();
/* clear the previous frame's paddles and ball */
SDL_FillRect(screen, &lPlayer->paddle.rect, clearColor);
SDL_FillRect(screen, &rPlayer->paddle.rect, clearColor);
SDL_FillRect(screen, &ball->rect, clearColor);
/* clear the previous frame's score */
SDL_FillRect(screen, &lScorePos, clearColor);
SDL_FillRect(screen, &rScorePos, clearColor);
/* redraw the walls in case they were clipped by the ball
in a previous frame */
SDL_FillRect(screen, &court->upperWall, court->color);
SDL_FillRect(screen, &court->lowerWall, court->color);
/* get the current state of the players' controls */
readPlayerInput(&running,
&lPlayerShouldMoveUp, &lPlayerShouldMoveDown,
&rPlayerShouldMoveUp, &rPlayerShouldMoveDown);
/* save the current position of the paddles */
lPlayer->paddle.prevY = lPlayer->paddle.rect.y;
rPlayer->paddle.prevY = rPlayer->paddle.rect.y;
/* move the paddles if appropriate */
if (lPlayerShouldMoveUp)
movePaddle(court, &lPlayer->paddle, UP);
else if (lPlayerShouldMoveDown)
movePaddle(court, &lPlayer->paddle, DOWN);
if (rPlayerShouldMoveUp)
movePaddle(court, &rPlayer->paddle, UP);
else if (rPlayerShouldMoveDown)
//.........这里部分代码省略.........
示例14: printf
bool Card::loadingText(SDL_Renderer* r, std::string svHeader, std::string svText, std::string enHeader, std::string enText, std::vector<std::string> svCat, std::vector<std::string> enCat){
// /Library/Fonts Arial.ttf
bool success = true;
// Loading font
if( TTF_Init() == -1 )
{
printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
TTF_Font *gFont = NULL;
gFont = TTF_OpenFont( "/Library/Fonts/Arial.ttf", 100 ); // Apple: "/Library/Fonts/Arial.ttf"
if( gFont == NULL )
{
printf( "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
SDL_Color textColor = { 0, 0, 0};
// Loading text
SDL_Surface* textSurface = NULL;
// Svenska header
textSurface = TTF_RenderText_Blended( gFont, svHeader.c_str(), textColor);
if( textSurface == NULL )
{
printf( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
else
{
//Create texture from surface pixels
headersSv.push_back( SDL_CreateTextureFromSurface( r, textSurface ));
if( headersSv[infoIndex] == NULL )
{
printf( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
success = false;
}
//Get rid of old surface
SDL_FreeSurface( textSurface );
}
// Svenska text
textSurface = NULL;
textSurface = TTF_RenderText_Blended_Wrapped( gFont, svText.c_str(), textColor, 3000);
if( textSurface == NULL )
{
printf( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
else
{
//Create texture from surface pixels
infoTextSv.push_back( SDL_CreateTextureFromSurface( r, textSurface ));
if( infoTextSv[infoIndex] == NULL )
{
printf( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
success = false;
}
//Get rid of old surface
SDL_FreeSurface( textSurface );
}
// Svenska kategorier
textSurface = NULL;
std::string catString = "Kategorier som kortet tillhˆr kommer synas h‰r";
for (int i = 0; i < svCat.size(); i++) {
if (i > 0) {
catString += " - ";
catString += svCat[i].c_str() ;
}
else {
catString = svCat[i].c_str() ;
}
}
textSurface = TTF_RenderText_Blended( gFont, catString.c_str(), textColor);
if( textSurface == NULL )
{
printf( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
else
{
//Create texture from surface pixels
catTextSv.push_back( SDL_CreateTextureFromSurface( r, textSurface ));
if( catTextSv[infoIndex] == NULL )
{
printf( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
success = false;
}
//Get rid of old surface
SDL_FreeSurface( textSurface );
}
// English header
textSurface = NULL;
textSurface = TTF_RenderText_Blended( gFont, enHeader.c_str(), textColor);
if( textSurface == NULL )
{
printf( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
//.........这里部分代码省略.........
示例15: main
int main(int argc, char *argv[])
{
SDL_Surface *screen = NULL,
*image = NULL,
*scaledImage = NULL,
*name = NULL;
SDL_Rect picturePortion;
TTF_Font *font = NULL;
double scale = 1.0;
int currentImageNumber = 1,
showFileName = TRUE,
runSlideShow = FALSE,
isRunning = TRUE;
SDL_TimerID slideShowTimer = 0;
// Process command line
if (argc < 2) {
fprintf(stderr, "\n"
" imgv v%s. Syntax: imgv <image files>\n\n"
" Hotkeys:\n"
" 'f' fit to screen\n"
" 'z' zoom at pixel level\n"
" 'i' zoom in 'o' zoom out\n"
" 'l' rotate left 'r' rotate right\n"
" 'n' next image 'p' previous image\n"
" 'd' show / hide file name\n"
" 's' start / stop slide show\n"
" 'arrows' pan 'ESC' quit\n\n", VERSION);
exit(0);
}
screen = initScreen();
font = TTF_OpenFont("font.ttf", 11);
if (font == (TTF_Font *) (NULL)) {
font = TTF_OpenFont("/usr/share/imgv/font.ttf", 11);
}
if (font == (TTF_Font *) (NULL)) {
font = TTF_OpenFont("/usr/share/fonts/ttf-dejavu/DejaVuSans.ttf", 11);
}
picturePortion.w = SCREENWIDTH;
picturePortion.h = SCREENHEIGHT;
image = loadImage(argv[1]);
if (image->w < SCREENWIDTH && image->h < SCREENHEIGHT) {
scaledImage = zoom100(image, &picturePortion, &scale);
} else {
scaledImage = zoomFit(image, &picturePortion, &scale);
}
name = drawFileName(argv[currentImageNumber], font, runSlideShow);
drawImage(scaledImage, &picturePortion, screen, name);
do {
SDL_Event event;
if (SDL_WaitEvent(&event) && event.type == SDL_KEYDOWN) {
switch (event.key.keysym.sym) {
case SDLK_LEFT: // PAN LEFT
pan(scaledImage, &picturePortion, -PANSTEP, 0);
break;
case SDLK_RIGHT: // PAN RIGHT
pan(scaledImage, &picturePortion, PANSTEP, 0);
break;
case SDLK_UP: // PAN UP
pan(scaledImage, &picturePortion, 0, -PANSTEP);
break;
case SDLK_DOWN: // PAN DOWN
pan(scaledImage, &picturePortion, 0, PANSTEP);
break;
case SDLK_i: // ZOOM IN
SDL_FreeSurface(scaledImage);
scaledImage = zoomIn(image, &picturePortion, &scale);
break;
case SDLK_o: // ZOOM OUT
SDL_FreeSurface(scaledImage);
scaledImage = zoomOut(image, &picturePortion, &scale);
break;
case SDLK_f: // ZOOM TO FIT SCREEN
SDL_FreeSurface(scaledImage);
scaledImage = zoomFit(image, &picturePortion, &scale);
break;
case SDLK_z: // ZOOM TO ORIGINAL SIZE
SDL_FreeSurface(scaledImage);
scaledImage = zoom100(image, &picturePortion, &scale);
break;
case SDLK_l: // ROTATE LEFT
{
SDL_FreeSurface(scaledImage);
SDL_Surface *tmp = rotateSurface90Degrees(image, 3);
SDL_FreeSurface(image);
image = tmp;
scaledImage = zoomSurface(image, scale, scale, SMOOTHING_ON);
int x = picturePortion.x;
picturePortion.x = picturePortion.y + SCREENHEIGHT/2 - SCREENWIDTH/2;
picturePortion.y = scaledImage->h - x - SCREENHEIGHT/2 - SCREENWIDTH/2;
pan(scaledImage, &picturePortion, 0, 0);
}
break;
case SDLK_r: // ROTATE RIGHT
{
//.........这里部分代码省略.........