当前位置: 首页>>代码示例>>C++>>正文


C++ TTF_RenderText_Shaded函数代码示例

本文整理汇总了C++中TTF_RenderText_Shaded函数的典型用法代码示例。如果您正苦于以下问题:C++ TTF_RenderText_Shaded函数的具体用法?C++ TTF_RenderText_Shaded怎么用?C++ TTF_RenderText_Shaded使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TTF_RenderText_Shaded函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: renderHUD

//display game stats
void renderHUD() {
    //display the score
    std::stringstream sScore;
    sScore<<iScore;
    sfScore=TTF_RenderText_Shaded(fnHUD,sScore.str().c_str(),clScore,clDefault);
    printb(7,0,sfScore,sfScreen);

    //display the wave number
    std::stringstream sWaves;
    sWaves<<iWave;
    surfWaves=TTF_RenderText_Shaded(fnHUD,sWaves.str().c_str(),clWaves,clDefault);
    printb(568,-1,surfWaves,sfScreen);
    printb(530,10,sfWavesIcon,sfScreen);

    //display the time remaining in the wave
    std::stringstream sTime;
    if(waveZero==true) sTime<<10000/100-tmTime.getTicks()/100;
    else sTime<<WAVE_LENGTH/100-tmTime.getTicks()/100;
    sfTime=TTF_RenderText_Shaded(fnHUD,sTime.str().c_str(),clTime,clDefault);
    printb(7,425,sfTime,sfScreen);

    //displaying bombs left
    std::stringstream sBombs;
    sBombs<<iBomb;
    sfBombs=TTF_RenderText_Shaded(fnHUD,sBombs.str().c_str(),clBomb,clDefault);
    printb(568,380,sfBombs,sfScreen);
    printb(530,391,sfBombsIcon,sfScreen);

    //displaying lives left
    std::stringstream sLives;
    sLives<<iLife-1;
    sfLives=TTF_RenderText_Shaded(fnHUD,sLives.str().c_str(),clLives,clDefault);
    printb(568,427,sfLives,sfScreen);
    printb(530,438,sfLivesIcon,sfScreen);
}
开发者ID:PocketEngi,项目名称:shutengu,代码行数:36,代码来源:shutengu.cpp

示例2: high_score_entry_draw

void high_score_entry_draw(high_score_entry* entry, SDL_Surface* screen) {

  // Draw a gold border
  _high_score_entry_draw_border(entry, screen);

  TTF_Font* font = TTF_OpenFont(FONT_PATH, 50);
  SDL_Color fg = {255, 255, 255};
  SDL_Color bg = {0, 0, 0};
  // Just use this render to get the width for centering
  SDL_Surface* textSurface = TTF_RenderText_Shaded(font, entry->name, fg, bg);

  int offset = (screen->w - textSurface->w)/2;
  int v_center = (screen->h - textSurface->h)/2;
  for (int i = 0; i <= 2; i++) {
    if (i == entry->index) {
      fg = (SDL_Color){0, 255, 0};
    } else {
      fg = (SDL_Color){255, 255, 255};
    }
    char str[] = {entry->name[i], 0};
    SDL_Surface* text = TTF_RenderText_Shaded(font, str, fg, bg);
    SDL_Rect textLocation = {offset, v_center, 0, 0};
    SDL_BlitSurface(text, NULL, screen, &textLocation);
    offset += text->w;
    SDL_FreeSurface(text);
  }

  SDL_FreeSurface(textSurface);
  TTF_CloseFont(font);
}
开发者ID:mpnolan,项目名称:snake,代码行数:30,代码来源:high-score-entry.c

示例3: init_ev

bool Main_menu::draw_menu()
{
	init_ev();
	//render_sdl();
	SDL_RenderCopy(render, texture, NULL, NULL);
	SDL_RenderCopy(render, m_font_newgame, NULL, &new_game_rect);
	SDL_RenderCopy(render, m_font_quit, NULL, &quit_rect);
	SDL_RenderPresent(render);
	while (!next)
	{
		while (SDL_PollEvent(&event))
		{
			if (event.type == SDL_MOUSEMOTION)
			{
				SDL_GetMouseState(&px, &py);
				pressed = false;
				//std::cout << px << " " << py << std::endl;
			}
			if (event.type == SDL_MOUSEBUTTONDOWN)
				pressed = true;
		}
		if (px >= new_game_rect.x && px <= new_game_rect.x + new_game_rect.w && py >= new_game_rect.y && py <= new_game_rect.y + new_game_rect.h)
		{
			myfont = TTF_RenderText_Shaded(font, "New Game", backcolor, textcolor);
			m_font_newgame = SDL_CreateTextureFromSurface(render, myfont);
			if (pressed)
				next = true;
		}
		else
		{
			myfont = TTF_RenderText_Solid(font, "New Game", textcolor);
			m_font_newgame = SDL_CreateTextureFromSurface(render, myfont);
		}

		if (px >= quit_rect.x && px <= quit_rect.x + quit_rect.w && py >= quit_rect.y && py <= quit_rect.y + quit_rect.h)
		{
			quitfont = TTF_RenderText_Shaded(font, "Quit", textcolor, backcolor);
			m_font_quit = SDL_CreateTextureFromSurface(render, quitfont);
			if (pressed)
			{
				return false;
			}
		}
		else
		{
			quitfont = TTF_RenderText_Solid(font, "Quit", textcolor);
			m_font_quit = SDL_CreateTextureFromSurface(render, quitfont);
		}
	}
	return true;
}
开发者ID:k0ntre201,项目名称:Tank-Mission-Game,代码行数:51,代码来源:main_menu.cpp

示例4: SDL_SetRenderDrawColor

void Menu::draw(SDL_Renderer &renderer){
  SDL_SetRenderDrawColor(&renderer, _bgColor.r, _bgColor.g, _bgColor.b, _bgColor.a);
  SDL_RenderClear(&renderer);
 
  SDL_Surface* text_surface;

  SDL_Rect menuPos;
  
  int itemAmount = _currentItems.size();
  for(int i = 0; i < itemAmount; ++i){
    if(i == 0){
      if(!(text_surface = TTF_RenderText_Shaded(_titleFont, _currentItems.at(i), _titleColor1, _bgColor))){
	std::cerr<<TTF_GetError()<<std::endl;
      }
    }
    else if(i == _currentSelection){
      if(!(text_surface = TTF_RenderText_Shaded(_highlightFont, _currentItems.at(i), _highlightColor, _bgColor))){
	std::cerr<<TTF_GetError()<<std::endl;
      }
    }
    else{
      if(!(text_surface = TTF_RenderText_Shaded(_breadFont, _currentItems.at(i), _breadColor, _bgColor))){
	std::cerr<<TTF_GetError()<<std::endl;
      }
    }
    SDL_Texture* text_texture = NULL;
    text_texture = SDL_CreateTextureFromSurface(&renderer, text_surface);
    if(text_texture == NULL){
      std::cerr<<SDL_GetError()<<std::endl;
    }
    int w, h;
    if(SDL_QueryTexture(text_texture, NULL, NULL, &w, &h) != 0){
      std::cerr<<"Query: "<<SDL_GetError()<<std::endl;
    }
    menuPos.x = 640/2 - w/2;
    menuPos.y = 480/4 + i * 64;
    menuPos.w = w;
    menuPos.h = h;
    SDL_Rect src;
    src.x = 0;
    src.y = 0;
    src.w = w;
    src.h = h;
    if(SDL_RenderCopy(&renderer, text_texture, &src, &menuPos) != 0 ){
      std::cerr<<SDL_GetError()<<std::endl;
    }
    SDL_FreeSurface(text_surface);
  }
  
  
}
开发者ID:forsnererik,项目名称:gunsbloodammo,代码行数:51,代码来源:Menu.cpp

示例5: set_color_with_pc

static int	set_color_with_pc(t_gui *gui,
				  t_corewar *core,
				  int i)
{
  SDL_Color	fg_color;
  char		str[3];

  fg_color.r = 0;
  fg_color.g = 0;
  fg_color.b = 0;
  fg_color.unused = 0;
  if (is_pc(core, gui, i) != 0)
    gui->byte_arena = TTF_RenderText_Shaded(gui->font,
					    hex_to_str(core->arena[i],
						       &str[0]),
					    fg_color,
					    gui->my_color);
  else
    gui->byte_arena = TTF_RenderText_Solid(gui->font,
  					   hex_to_str(core->arena[i],
						      &str[0]),
  					   gui->my_color);
  if (gui->byte_arena == NULL)
    return (my_putstr("error: TTF_RenderText\n", 2));
  return (0);
}
开发者ID:Nephos,项目名称:corewar2014,代码行数:26,代码来源:get_color.c

示例6: free

bool LTexture::loadFromRenderedText(std::string textureText, SDL_Color textColor, SDL_Color bgColor, TTF_Font* gFont, SDL_Renderer* gRenderer)
{
	//Get rid of preexisting texture
	free();

	//Render text surface
	SDL_Surface* textSurface = TTF_RenderText_Shaded(gFont, textureText.c_str(), textColor, bgColor);
	if (textSurface == NULL)
	{
		printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());
	}
	else
	{
		//Create texture from surface pixels
		mTexture = SDL_CreateTextureFromSurface(gRenderer, textSurface);
		if (mTexture == NULL)
		{
			printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError());
		}
		else
		{
			//Get image dimensions
			mWidth = textSurface->w;
			mHeight = textSurface->h;
		}

		//Get rid of old surface
		SDL_FreeSurface(textSurface);
	}

	//Return success
	return mTexture != NULL;
}
开发者ID:trebla01,项目名称:18.5-color-game,代码行数:33,代码来源:LTexture.cpp

示例7: afficher_message_interface_SDL

int afficher_message_interface_SDL (SDL_Surface *screen, SDL_Surface *message, char phrase2_affiche[], TTF_Font *font, SDL_Rect position,	SDL_Color textColor, SDL_Color fondColor)
{
	// affiche texte
	SDL_FreeSurface(message); /* On supprime la surface précédente */
	//Mise en place du texte sur la surface message 
	message = TTF_RenderText_Shaded( font, phrase2_affiche, textColor, fondColor ); 

	//S'il y a une erreur dans la mise en place du texte 
			if( message == NULL ) {
				printf("\n erreur message \n"); 
				return 1; 
			} 
        		
        		SDL_BlitSurface(message, NULL, screen, &position); /* Blit du texte */
        		SDL_Flip(screen);

			//apply_surface( 0, 0, background, screen 

			//Mise à jour de l'écran 
			if( SDL_Flip( screen ) == -1 ) { 
				printf("\n erreur mise à jour écran \n"); 
				return 1; 
			}
	return 1;
}
开发者ID:AlexTAB,项目名称:OthelloL2SPIGr5,代码行数:25,代码来源:grille.c

示例8: subtitle_clean_msg

int subtitle_clean_msg(SDL_Surface *screen, int x, int y, const char *msg)
{
        SDL_Color black = { 0x00, 0x00, 0x00, 0x00 };

	//SDL_Color fg={255, 165,0,0}; // orange color
	SDL_Color fg={0, 0, 0,0};
	SDL_Color bg={0, 0, 0, 0};

        SDL_Surface *black_text_surface = TTF_RenderText_Shaded(font, msg, fg, bg);

        if (black_text_surface) 
        {

           SDL_TextureID black_text = SDL_CreateTextureFromSurface(0, black_text_surface);
           if (black_text) {
               SDL_Rect black_rect = {x, y, black_text_surface->w, black_text_surface->h };
               SDL_RenderCopy(black_text, NULL, &black_rect);

               SDL_DestroyTexture(black_text);


               { 
                 char log_msg[256];
                 // sprintf(log_msg, "CleanedMsg:%s", msg);
                 __android_log_print(ANDROID_LOG_INFO, "BroovPlayer", "CleanedMsg:%s", msg);
               }
           }

           SDL_FreeSurface(black_text_surface);
        }

}
开发者ID:ashiontang,项目名称:dolphin-player,代码行数:32,代码来源:broov_font.c

示例9: overlay_subtitle_draw_msg_type2

int overlay_subtitle_draw_msg_type2(SDL_Surface *screen, int x, int y, const char *msg)
{
        int blender = 254;
	SDL_Color bg={0,0,0,0};
	SDL_Color fg={255,255,255,255};

	SDL_Surface *surf= TTF_RenderText_Shaded(font,msg,fg, bg);

        //Central alignment for subtitle
        x=(int) ((320.0*fs_screen_width/640.0) -(surf->w/2.0));

        SDL_Rect rect = {x, y, surf->w, surf->h };

        SDL_Surface *alpha_surf = SDL_DisplayFormat(surf);
        overlay_transparent(alpha_surf, 0,0,0);
        //SDL_Surface *alpha_surf = SDL_DisplayFormatAlpha(surf);
        SDL_SetAlpha(alpha_surf, SDL_SRCALPHA, blender); //255-opaque,0-invisible
        SDL_TextureID text = SDL_CreateTextureFromSurface(0, alpha_surf);

        SDL_RenderCopy(text, NULL, &rect);

        SDL_FreeSurface(surf);
        SDL_FreeSurface(alpha_surf);
        SDL_DestroyTexture(text);
}
开发者ID:ashiontang,项目名称:dolphin-player,代码行数:25,代码来源:broov_font.c

示例10: switch

void TextTexture::drawText()
{
    SDL_Color fg = {TextColor.r*255,TextColor.g*255,TextColor.b*255,TextColor.a*255}, bg = {255-TextColor.r*255,255-TextColor.g*255,255-TextColor.b*255,255-TextColor.a*255};
    if(TextImage!=NULL){SDL_FreeSurface(TextImage); TextImage=NULL;}
    switch(RenderStyle)
    {
        case TTF_RENDER_BLENDED:
            TextImage = TTF_RenderText_Blended(font->getFont(),text.c_str(),fg);
            break;
        case TTF_RENDER_SHADED:
            TextImage = TTF_RenderText_Shaded(font->getFont(),text.c_str(),fg,bg);
            break;
        case TTF_RENDER_SOLID:
            TextImage = TTF_RenderText_Solid(font->getFont(),text.c_str(),fg);
            break;
    }
    if(TextImage == NULL)
    {
        std::cout<<"ERROR: COULD NOT LOAD TEXT FOR "<<getName()<<std::endl;
        return;
    }
    else
    {
        if(RenderStyle == TTF_RENDER_SHADED)
        {
            SDL_SetColorKey(TextImage,SDL_TRUE,SDL_MapRGB(TextImage->format,bg.r,bg.g,bg.b)); //Kinda silly, that we render the background and then cancel it out
        }
        SDL_SetSurfaceAlphaMod(TextImage,TextColor.a*255);
    }
}
开发者ID:0NDR,项目名称:AGE,代码行数:30,代码来源:TextTexture.cpp

示例11: TTF_GlyphMetrics

void Font::loadChar(int c) {
	GLfloat texcoord[4];
	char letter[2] = { 0, 0 };

	if ((minGlyph <= c) && (c <= maxGlyph) && (NULL == glyphs[c].pic)) {
		SDL_Surface *g0 = NULL;
		SDL_Surface *g1 = NULL;
		letter[0] = c;
		TTF_GlyphMetrics(ttfFont, (Uint16) c, &glyphs[c].minx, &glyphs[c].maxx,
				&glyphs[c].miny, &glyphs[c].maxy, &glyphs[c].advance);
		g0 = TTF_RenderText_Shaded(ttfFont, letter, foreground, background);
		if (g0) {
			g1 = SDL_ConvertSurface(g0,g0->format,0);
			SDL_FreeSurface(g0);
		}
		if (g1) {
			glyphs[c].pic = g1;
			glyphs[c].tex = 0; // loadTextureColorKey(g1, texcoord, 0, 0, 0);
			glyphs[c].texMinX = texcoord[0];
			glyphs[c].texMinY = texcoord[1];
			glyphs[c].texMaxX = texcoord[2];
			glyphs[c].texMaxY = texcoord[3];
		}
	}
}
开发者ID:codespear,项目名称:GameEx,代码行数:25,代码来源:font.cpp

示例12: renderText

static int renderText(const char *text, SDL_Surface *rendered_text, SDL_Rect *text_size, TTF_Font *font, const unsigned int foreground, const unsigned int background)
{
	const unsigned int display_w = 1024;
	const unsigned int display_h = 768;
	
	SDL_Color fg, bg;
	fg.r = foreground;
	fg.g = foreground;
	fg.b = foreground;
	bg.r = background;
	bg.g = background;
	bg.b = background;
	
	rendered_text = TTF_RenderText_Shaded(font, text, fg, bg);
	
	if (!rendered_text || 
		TTF_SizeText(font, text, (int *)&text_size->w, (int *)&text_size->h) ||
		(text_size->w + text_size->x > display_w) ||
		(text_size->h + text_size->y > display_h) ) {
		fprintf(stderr, "SDL_TTF: Error rendering text.\n       : Error: %s\n", TTF_GetError() );
		return 1;
	}
	
	return 0;
}
开发者ID:keot,项目名称:maptiler,代码行数:25,代码来源:text.c

示例13: I_TTFRendSurface

static void I_TTFRendSurface(const char *textmsg, TTF_Font *font, TextQuality quality, SDL_Color fontfgcolor, SDL_Color fontbgcolor)
{
	// Print text in the buffer.
	// SDL_ttf has three modes to draw text.
	// Solid rendering is quick, but dirty. Use it if you need speed more than quality.
	switch (quality)
	{
		case solid:
			TTFRendSurface = TTF_RenderText_Solid(font, textmsg, fontfgcolor);
			break;
		// Shaded rendering adds a background to the rendered text. Because of this, I_TTFDrawText
		// takes an extra color more than the other styles to be a background color.
		// Shaded is supposedly as fast as solid rendering and about as good quality as blended.
		case shaded:
			TTFRendSurface = TTF_RenderText_Shaded(font, textmsg, fontfgcolor, fontbgcolor);
			break;
		// Blended rendering is the opposite of solid. Good quality, but slow.
		case blended:
			TTFRendSurface = TTF_RenderText_Blended(font, textmsg, fontfgcolor);
			break;
	}

	// Get SDL to update the main surface.
	SDL_BlitSurface(TTFRendSurface, NULL, TTFSurface, &TTFRect);
	SDL_Flip(TTFSurface);
}
开发者ID:PrisimaTheFox,项目名称:SRB2,代码行数:26,代码来源:i_ttf.c

示例14: surf_string_tr

void TFont_ttf::surf_string(SDL_Surface *surf,int x, int y, const char *s, int color, int bgcolor, int w) {
    if (!s[0]) return;
  if (!ttf)
    return TFont::surf_string(surf,x,y,s,color,bgcolor,w);
  if (!bgcolor) // 0 is totally transparent in sdl_gfx -> no bg
    return surf_string_tr(surf,x,y,s,color,w);
  SDL_Rect dest;
  SDL_Color sc,bg;
  sc.b = (color >> 8) & 0xff;
  sc.g = (color >> 16) & 0xff;
  sc.r = (color >> 24) & 0xff;
  bg.b = (bgcolor >> 8) & 0xff;
  bg.g = (bgcolor >> 16) & 0xff;
  bg.r = (bgcolor >> 24) & 0xff;
  SDL_Surface *sf;
  if (is_utf)
      sf = TTF_RenderUTF8_Shaded(ttf,s,sc,bg);
  else
      sf = TTF_RenderText_Shaded(ttf,s,sc,bg);
  // SDL_SetColorKey(sf,SDL_SRCCOLORKEY | SDL_RLEACCEL,0);
  dest.x = x; dest.y = y;
  if (w && w < sf->w) {
      SDL_Rect src;
      src.w = w;
      src.h = sf->h;
      src.x = src.y = 0;
      SDL_BlitSurface(sf,&src,surf,&dest);
  } else
      SDL_BlitSurface(sf,NULL,surf,&dest);
  SDL_FreeSurface(sf);
}
开发者ID:albinoz,项目名称:raine,代码行数:31,代码来源:tfont.cpp

示例15: overlay_subtitle_draw_msg_type1

int overlay_subtitle_draw_msg_type1(SDL_Surface *screen, int x, int y, const char *msg)
{
        int blender = 45;
	SDL_Color bg={0,0,0,0};
	SDL_Color fg={255,255,255,255};

        SDL_Surface *mBackground = SDL_CreateRGBSurface
               (SDL_SWSURFACE, sw, sh, 32, screen->format->Rmask,
                screen->format->Gmask,
                screen->format->Bmask,
                screen->format->Amask);
        Uint32 color = SDL_MapRGB(mBackground->format, 255, 255, 255);
        SDL_FillRect(mBackground, 0, color);
        
	SDL_Surface *surf= TTF_RenderText_Shaded(font,msg,fg, bg);

        //Central alignment for subtitle
        x=(int) ((320.0*fs_screen_width/640.0) -(surf->w/2.0));

        SDL_Rect rect = {x, y, surf->w, surf->h };

        SDL_Surface *alpha_surf = SDL_DisplayFormat(mBackground);
        overlay_transparent(alpha_surf, 0,0,0);
        SDL_SetAlpha(alpha_surf, SDL_SRCALPHA, blender); //255-opaque,0-invisible
        SDL_TextureID text = SDL_CreateTextureFromSurface(0, alpha_surf);

        SDL_RenderCopy(text, NULL, &rect);

        SDL_FreeSurface(surf);
        SDL_FreeSurface(alpha_surf);
        SDL_DestroyTexture(text);
}
开发者ID:ashiontang,项目名称:dolphin-player,代码行数:32,代码来源:broov_font.c


注:本文中的TTF_RenderText_Shaded函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。