Пример #1
0
//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);
}
Пример #2
0
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);
}
Пример #3
0
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;
}
Пример #4
0
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);
  }
  
  
}
Пример #5
0
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);
}
Пример #6
0
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;
}
Пример #7
0
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;
}
Пример #8
0
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);
        }

}
Пример #9
0
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);
}
Пример #10
0
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);
    }
}
Пример #11
0
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];
		}
	}
}
Пример #12
0
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;
}
Пример #13
0
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);
}
Пример #14
0
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);
}
Пример #15
0
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);
}
Пример #16
0
void draw_text(struct Player *p, SDL_Surface *screen, SDL_Surface *text, TTF_Font *font, SDL_Color color) {
	SDL_Rect rect = {0, 0, 0, 0};
	char item[8];
	switch(p->selected) {
	case DIRT:
		strcat(item," DIRT ");
		break;
	case GRASS:
		strcat(item," GRASS ");
		break;
	case SAND:
		strcat(item," SAND ");
		break;
	case ROCK:
		strcat(item," ROCK ");
		break;
	case WATER5:
		strcat(item," WATER ");
		break;
	case OIL:
		strcat(item," OIL ");
		break;
	}
	SDL_Color bgcolor = {0, 0, 0};
	text = TTF_RenderText_Shaded(font, item, color, bgcolor);
	SDL_BlitSurface(text, NULL, screen, &rect);
}
Пример #17
0
void Texture_Text::RenderText_Shaded( SDL_Renderer* renderer, const std::string &str )
{
	// Render with a text color
	SDL_Surface* surface = TTF_RenderText_Shaded( textFont, str.c_str(), textColor, backgroundColor );

	SetTexture( renderer, surface );
}
Пример #18
0
/*
 *  Execution of the clock window
 */
int clock_loop() {
	time_t now, prev = 0;
	struct tm* tm;
	char buff[100];
	int ret;
	int clockDeli = 1;

	Window *w = window[curr_window_idx];

	while (1) {

		if ((ret = handle_input()))
			return ret;

		now = time(0);

		if (now > prev) {

			tm = localtime(&now);
			prev = now;

			clockDeli = clockDeli == 1 ? 0 : 1;

			if (clockDeli) {
				sprintf(buff, "%02d:%02d", tm->tm_hour, tm->tm_min);
			} else {
				sprintf(buff, "%02d %02d", tm->tm_hour, tm->tm_min);
			}

			picframe_load_font("/usr/share/fonts/UbuntuMono-R.ttf", 115);
			Element_t *time_disp = window_get_element_byName(w, "time");
			time_disp->surface = TTF_RenderText_Shaded(_font, buff, fg, bg);

			strftime(buff, sizeof(buff), "%a, %d %b %Y %Z", tm);

			picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", 29);
			Element_t *info_disp = window_get_element_byName(w, "info");
			info_disp->surface = TTF_RenderText_Shaded(_font, buff, fg, bg);

			window_update(window[curr_window_idx]);

		}

		SDL_Delay(1);
	}
	return 0;
}
Пример #19
0
void BaseSpaceShip::Died()
{
	Gfx.srfText = TTF_RenderText_Shaded( Gfx.DefaultFont, " YOU DIED STOP PLAYING GOD DAMN YOU!!!!! ", Gfx.WhiteRGB, Gfx.BlackRGB );
	Gfx.apply_surface( 250, 500, Gfx.srfText, Gfx.BackBuffer );
	Gfx.FLIP();

	gamestate.GameState.push(GAME_PLAYER_DIED_STATE);
}
void ImpresionDeTexto::MostrarTexto( string texto, int fuente, SDL_Rect destination, SDL_Surface* pantallaDestino, SDL_Color foreground, SDL_Color background )
{
	// This renders our text to a temporary surface.
	SDL_Surface* temp = TTF_RenderText_Shaded( GetFont(fuente), texto.c_str(), foreground, background );
	// Blit the text surface to our window surface, the NULL specifies the whole surface.
	SDL_BlitSurface( temp, NULL, pantallaDestino, &destination );
	// Always free memory!
	SDL_FreeSurface( temp );
}
Пример #21
0
extern DECLSPEC SDL_Surface * SDLCALL
  TTF_RenderText_Shaded_p(
    TTF_Font *font,
    const char *text,
    SDL_Color *fg,
    SDL_Color *bg) {

  return TTF_RenderText_Shaded(font, text, *fg, *bg);
}
Пример #22
0
// Draw one row of the text area, passed as a string with a null on the end
static void drawLine(display *d, int r, char s[COLS + 1])
{
  int z;
  SDL_Surface *text = TTF_RenderText_Shaded(d->font, s, d->fg, d->bg);
  int pr = 525 + r * text->h;
  *d->box = (SDL_Rect) { 760, pr, text->h, text->w };
  z = SDL_BlitSurface(text, NULL, d->surface, d->box);
  if (z < 0) {
    SDL_Fail("Bad text display", d);
  }
  SDL_FreeSurface(text);
}
Пример #23
0
SDL_Surface* drawtext(TTF_Font *fonttodraw, char fgR, char fgG, char fgB, char fgA, 
		char bgR, char bgG, char bgB, char bgA, char text[], enum textquality quality)
{
	/*This takes lots of parameters and uses them to render in the desired manner a string in the desired font to the desired
	  surface in the desired color .*/
	SDL_Color tmpfontcolor = {fgR,fgG,fgB,fgA};
	SDL_Color tmpfontbgcolor = {bgR, bgG, bgB, bgA};
	if (quality == solid){return TTF_RenderText_Solid(fonttodraw, text, tmpfontcolor);}
	if (quality == shaded){return TTF_RenderText_Shaded(fonttodraw, text, tmpfontcolor, tmpfontbgcolor);}
	if (quality == blended){return TTF_RenderText_Blended(fonttodraw, text, tmpfontcolor);}
	return 0;
}
Пример #24
0
bool Text::loadText(std::string text, SDL_Color color, Quality q)
{
  bool success = true;
  if (mTextureSurface != nullptr) {
    SDL_FreeSurface(mTextureSurface);
    mTextureSurface = nullptr;
  }
  switch(q) {
    case LOW:
      mTextureSurface = TTF_RenderText_Solid( mFont, text.c_str(), color);
    break;
    case MED: {
      SDL_Color bg = {1, 1, 1, 1};
      mTextureSurface = TTF_RenderText_Shaded( mFont, text.c_str(), color, bg );
    }
    break;
    case HIGH:
      mTextureSurface = TTF_RenderText_Blended( mFont, text.c_str(), color);
    break;
  }
  if( mTextureSurface == nullptr ) {
      std::cout << "Unable to render text surface! SDL_ttf Error: " << TTF_GetError() << std::endl;
      success = false;
  }
  else {
    mWidth  = mTextureSurface->w;
    mHeight = mTextureSurface->h;
    
    if( mTexture != 0 ) {
      glDeleteTextures(1, &mTexture);
      mTexture=0;
    }
    glGenTextures( 1, &mTexture );
    glBindTexture(GL_TEXTURE_2D, mTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, mTextureSurface->pixels);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glBindTexture(GL_TEXTURE_2D, NULL);

    //Check for error
    GLenum error = glGetError();
    if( error != GL_NO_ERROR ) {
        std::cout << "Error loading texture" << gluErrorString( error ) << std::endl;
        success = false;
    }
    success = init();
  }

  return success;
}
Пример #25
0
//TTF_ERASETEXT -- Erase text over area
void TTF_EraseText(string str, SDL_Rect r)
{
    SDL_Color fc = {TTF_bR, TTF_bG, TTF_bB, TTF_bA}; //Font
    SDL_Color bg = {TTF_bR, TTF_bG, TTF_bB, TTF_bA}; //Background
    string erase_text;
    for(int i = 0; i < str.length(); i++) //Add spaces to equal it out
    {
        erase_text += " ";
    }
    SDL_Surface *text = TTF_RenderText_Shaded(font, erase_text.c_str(), fc, bg);
    Image_DrawImage(text, r); //Draw the image
    SDL_FreeSurface(text);
}
Пример #26
0
//TTF_DISPLAYTEXT -- Display text (Global_text)
void TTF_DisplayText(Global_text t, int total_space, SDL_Rect r)
{
    SDL_Color fc = {TTF_fR, TTF_fG, TTF_fB, TTF_fA}; //Font
    SDL_Color bg = {TTF_bR, TTF_bG, TTF_bB, TTF_bA}; //Background
    string str = TTF_arr[t];
    for(int i = 0; i < total_space - TTF_arr[t].length(); i++) //Add spaces to equal it out
    {
        str += " ";
    }
    SDL_Surface *text = TTF_RenderText_Shaded(font, str.c_str(), fc, bg);
    Image_DrawImage(text, r); //Draw the image
    SDL_FreeSurface(text);
}
Пример #27
0
void Screen::DrawDebugLayer(SDL_Surface *dst, float FPS)
{
	SDL_Rect __debug_rect;
	SDL_Surface *layer;
	SDL_Color fg = {0, 0, 0}, bg = {0xFF, 0xFF, 0xFF};
	char buf[255];

	sprintf(buf, "[Debug Layer]");
	layer = TTF_RenderText_Shaded((TTF_Font*)this->DebugFont, buf, fg, bg);
	__debug_rect.w = layer->w; __debug_rect.h = layer->h;
	__debug_rect.x = dst->w - layer->w; __debug_rect.y = 0;
	SDL_BlitSurface(layer, NULL, dst, &__debug_rect);

	sprintf(buf, "FPS: %f", FPS);
	layer = TTF_RenderText_Shaded((TTF_Font*)this->DebugFont, buf, fg, bg);
	__debug_rect.x = dst->w - layer->w; __debug_rect.y += __debug_rect.h;
	__debug_rect.w = layer->w; __debug_rect.h = layer->h;
	SDL_BlitSurface(layer, NULL, dst, &__debug_rect);

	SDL_FreeSurface(layer);
	return ;
}
Пример #28
0
SDL_Surface* TE_RenderText(const char text[], TextEdition te, int inverted)
{
    if (!text)
        return NULL;
    if (inverted)
        te.blitStyle = TE_BLITSTYLE_SHADED;

    switch(te.blitStyle)
    {
        case TE_BLITSTYLE_BLENDED:
            return TTF_RenderText_Blended(te.font, text, te.colorFG);
        case TE_BLITSTYLE_SHADED:
            if (inverted)
                return TTF_RenderText_Shaded(te.font, text, te.colorFGSelect, te.colorBGSelect);
            else return TTF_RenderText_Shaded(te.font, text, te.colorFG, te.colorBG);
        case TE_BLITSTYLE_SOLID:
            return TTF_RenderText_Solid(te.font, text, te.colorFG);
        default:
            break;
    }

    return NULL;
}
Пример #29
0
static int draw_text(SDL_Surface *sf, const struct rect *rect,
                     const char *buf, TTF_Font *font,
                     SDL_Color fg, SDL_Color bg)
{
    SDL_Surface *rendered;
    SDL_Rect dst, src, fill;

    if (buf == NULL) {
        src.w = 0;
        src.h = 0;

    } else if (buf[0] == '\0') { /* SDL_ttf fails for empty string */
        src.w = 0;
        src.h = 0;

    } else {
        rendered = TTF_RenderText_Shaded(font, buf, fg, bg);

        src.x = 0;
        src.y = 0;
        src.w = MIN(rect->w, rendered->w);
        src.h = MIN(rect->h, rendered->h);

        dst.x = rect->x;
        dst.y = rect->y;

        SDL_BlitSurface(rendered, &src, sf, &dst);
        SDL_FreeSurface(rendered);
    }

    /* Complete the remaining space with a blank rectangle */

    if (src.w < rect->w) {
        fill.x = rect->x + src.w;
        fill.y = rect->y;
        fill.w = rect->w - src.w;
        fill.h = rect->h;
        SDL_FillRect(sf, &fill, palette(sf, &bg));
    }

    if (src.h < rect->h) {
        fill.x = rect->x;
        fill.y = rect->y + src.h;
        fill.w = src.w; /* the x-fill rectangle does the corner */
        fill.h = rect->h - src.h;
        SDL_FillRect(sf, &fill, palette(sf, &bg));
    }

    return src.w;
}
Пример #30
0
SDL_Texture* Window::RenderText(std::string txt, TTF_Font *font,
						SDL_Color color, SDL_Color shaded_color, int quality)
{
	//font_quality { 0:blended, 1:shaded, 2:solid };
	SDL_Surface *surf = nullptr;
	if (quality == 2)
		surf = TTF_RenderText_Solid(font, txt.c_str(), color);
	else if (quality == 0)
		surf = TTF_RenderText_Blended(font, txt.c_str(), color);
	else if (quality == 1)
		surf = TTF_RenderText_Shaded(font, txt.c_str(), color, shaded_color);
	SDL_Texture *tex = SDL_CreateTextureFromSurface(mRenderer, surf);
	SDL_FreeSurface(surf);
	return tex;
}