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


C++ TTF_RenderText_Solid函数代码示例

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


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

示例1: TTF_RenderText_Solid

void Renderer::drawText(const TextRenderable& txt, bool clear)
{

	SDL_Surface* surfaceMessage = TTF_RenderText_Solid(sFont, (txt.text + txt.addText).c_str(), DEFAULT_TEXT_COLOR);
	SDL_Texture* message = SDL_CreateTextureFromSurface(sRenderer, surfaceMessage); 

	int w, h;
	TTF_SizeText(sFont, txt.text.c_str(), &w, &h);

	//Clear the area
	this->clear(txt.x, txt.y, w, h);
	SDL_Rect rectMessage {txt.x, txt.y, w, h}; 
	SDL_RenderCopy(sRenderer, message, nullptr, &rectMessage);

	SDL_DestroyTexture(message);
	SDL_FreeSurface(surfaceMessage);
}
开发者ID:Ffaithy,项目名称:Simple-Pattern-Matching-Game,代码行数:17,代码来源:Renderer.cpp

示例2: textoParaSuperficie

// Objetivo: Transformar um texto em uma superficie
// Parametros: O endereco da string que contem o texto e a fonte do texto
// Retorno: A superficie do texto ou NULL se ocorrer um erro
Superficie textoParaSuperficie(char *texto, Fonte fonteTexto){
	Superficie superficeTexto = NULL;
	
	// Transforma o texto em uma superficie
	superficeTexto = TTF_RenderText_Solid(fonteTexto, // A fonte do texto
	                                       texto, // O texto que sera tranformado
	                                       COR_FONTE_PRINCIPAL); // A cor do texto
	
	// Verifica se ocorreu um erro ao transformar o text em superficie
	if(superficeTexto == NULL) 
		salvarErro("Erro na funcao 'TTF_RenderText_Solid' de 'textoParaSuperficie'\n");
	
	// Limpa a memoria utilizada pela fonte
	TTF_CloseFont(fonteTexto);
	
	return superficeTexto;
}
开发者ID:ygorcf,项目名称:ProjetoFinalLab1,代码行数:20,代码来源:funcoesJanela.c

示例3: xyz_block_text

void xyz_block_text(int x, int y, const char *text) {
  SDL_Surface *rendered_text;
  SDL_Rect dest;
  SDL_Color color;
  Uint8 r, g, b;
  char *one_line = NULL;
  const char *index = text;
  const char *next_newline;

  SDL_GetRGB(current_color, surface->format, &r, &g, &b);
  color.r = r;
  color.g = g;
  color.b = b;

  while(index) {
    int length;

    next_newline = strchr(index, '\n');
    if(!next_newline) {
      one_line = strdup(index);
      index = NULL;
    } else {
      length = next_newline - index;
      one_line = malloc(length + 1);
      memcpy(one_line, index, length);
      one_line[length] = '\0';
      index = next_newline + 1;
    }

    rendered_text = TTF_RenderText_Solid(sanskrit_font_20, one_line, color);
    if(!rendered_text)
      xyz_fatal_error("Couldn't render text: %s!", TTF_GetError());

    dest.x = x;
    dest.y = y;
    y += 25;  /* For next line */
    dest.w = surface->w;
    dest.h = surface->h;

    SDL_BlitSurface(rendered_text, NULL, surface, &dest);
    SDL_FreeSurface(rendered_text);

    free(one_line);
  }
}
开发者ID:noahgibbs,项目名称:shannas_pizza,代码行数:45,代码来源:xyz.c

示例4: Tekst_opprett

Tekst * Tekst_opprett(void * spaceinvader, char * font_navn, int size) {

    Skjerm * skjerm = ((Spaceinvader*)spaceinvader)->skjerm;

    Tekst * tekst = (Tekst*)malloc(sizeof(Tekst));
                 
    tekst->spaceinvader = spaceinvader;

    tekst->font=TTF_OpenFont(font_navn, size);
    
    if(!tekst->font) {
        printf("TTF_OpenFont: %s\n", TTF_GetError());
        return NULL;
    }    

    strcpy(tekst->melding,"nop");
    
    tekst->x = 0;
    
    tekst->y = 0;
    
    SDL_Color farge = {0,255,0};
    SDL_Surface* surface = TTF_RenderText_Solid( tekst->font, tekst->melding, farge );
    
    if (surface == NULL) {
        printf("TTF_RenderText_Solid: %s\n", TTF_GetError());
        return NULL;        
    }
    
    tekst->bredde = surface->w;
    
    tekst->hoeyde = surface->h;
    
    tekst->texture = SDL_CreateTextureFromSurface( skjerm->ren, surface );
    
    if (tekst->texture == NULL) {
        printf("SDL_CreateTextureFromSurface: %s\n", SDL_GetError());
        return NULL;               
    }
            
    SDL_FreeSurface (surface );
                    
    return tekst;
    
}
开发者ID:halftanolger,项目名称:cprogrammering,代码行数:45,代码来源:tekst.c

示例5: TTF_OpenFont

Font::Font(std::string FontName, int FontSize, std::string Text, int x, int y)
{
	font = NULL;
	sText = Text;
	cX = x;
	cY = y;
	font = TTF_OpenFont(FontName.c_str(), FontSize);
	TextColor.r = 255;
	TextColor.b = 255;
	TextColor.g = 255;
	if(!font)
	{
		Log(std::string("Font failed to load, ") + TTF_GetError());
	}
	cText = sText;
	Color = TextColor;	
	Surface = TTF_RenderText_Solid(font, sText.c_str(), TextColor);
}
开发者ID:fouf,项目名称:Science-Fair-Project-2010,代码行数:18,代码来源:Font.cpp

示例6: TTF_RenderText_Solid

void TextLabel::loadTexture(SDL_Renderer *sdlRenderer,TTF_Font *font){
	this->freeTexture();
	SDL_Surface* surfaceMessage = TTF_RenderText_Solid(font, this->message.c_str(), this->textColor);
	if(surfaceMessage == NULL) {
		Log().Get(TAG,logERROR) << "No se pudo cargar la surface: "<<TTF_GetError();
		return;
	}

	this->width = surfaceMessage->w;
	this->height = surfaceMessage->h;

	this->texture = SDL_CreateTextureFromSurface(sdlRenderer, surfaceMessage);
	SDL_FreeSurface( surfaceMessage );
	if (this->texture == NULL){
		Log().Get(TAG,logERROR) << "No se pudo crear la texture: "<<SDL_GetError();
		return;
	}
}
开发者ID:kaoruheanna,项目名称:AgeOfFiuba,代码行数:18,代码来源:TextLabel.cpp

示例7: debug_hud_update_surfaces

void debug_hud_update_surfaces(DebugHud* self, SDL_Renderer* renderer) {
    for (u32 i = 0; i < self->count; ++i) {
        DebugHudWatch* watch = &self->watches[i];

        if (watch->texture) {
            SDL_DestroyTexture(watch->texture);
            watch->texture = NULL;
        }

        char watchOut[128];
        debug_hud_watch_build_string(watch, watchOut, 128);

        SDL_Color color = debug_hud_watch_internal_get_color(watch);
        SDL_Surface* surface = TTF_RenderText_Solid(self->debugFont, watchOut, color);
        watch->texture = SDL_CreateTextureFromSurface(renderer, surface);
        SDL_FreeSurface(surface);
    }
}
开发者ID:tedajax,项目名称:runner,代码行数:18,代码来源:debughud.c

示例8: TTF_RenderText_Solid

void *textureFromText(char *str, SDL_Color color, Text *text, TTF_Font *font,
                      SDL_Renderer *renderer) {
    SDL_Surface *surface = TTF_RenderText_Solid(font, str, color);
    if (surface == NULL) {
        printf("Unable to render text surface. Shit's fucked, because %s, dude"
               ".", TTF_GetError());
    } else {
        text->texture = SDL_CreateTextureFromSurface(renderer, surface);
        if (text->texture == NULL) {
            printf("Unable to create texture from rendered text. Shit's fucked"
                   " because %s, dude.", SDL_GetError());
        } else {
            text->width = surface->w;
            text->height = surface->h;
        }
        SDL_FreeSurface(surface);
    }
}
开发者ID:RylandAlmanza,项目名称:piggle,代码行数:18,代码来源:main.c

示例9: draw_timer

void draw_timer(signed int hours, signed int minutes, signed int seconds)
{
    SDL_Color color = { 255, 255, 255 };
    char buffer[20];
    int w, h;

    std::sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);

    if(TTF_SizeText(font_28, buffer, &w, &h))
    {
        log(ERROR, "TTF_SizeText failed. %s.", TTF_GetError());
        w = 180;
    }

    SDL_Surface * s = TTF_RenderText_Solid(font_28, buffer, color);

    apply_surface(s, (WIDTH / 2) - (w / 2), 20);
}
开发者ID:alexandrevicenzi,项目名称:gcw_mic,代码行数:18,代码来源:screen.cpp

示例10: SDL_BlitSurface

       void game::relatifdetails(const char* c)
{

        SDL_BlitSurface(mario_head,NULL,screen,&rect_mario_head);
    rect_mario_head.x=10;
    rect_mario_head.y=40;
    rect_mario_head.w=30;
    rect_mario_head.h=27;
     mario_head=SDL_DisplayFormat(SDL_LoadBMP("mario_head.bmp"));
     SDL_SetColorKey(mario_head,SDL_SRCCOLORKEY,SDL_MapRGB(screen->format,0x00,0xFF,0xFF));
    SDL_Color color={255,255,255};
    SDL_Surface* text=TTF_RenderText_Solid(font,c,color);
    SDL_Rect tmprect={50,40};
    SDL_BlitSurface(text,NULL,screen,&tmprect);
     SDL_BlitSurface(mario_head,NULL,screen,&rect_mario_head);
     // afficher sky qui move

}
开发者ID:rachednemr,项目名称:Mario_bross,代码行数:18,代码来源:game.cpp

示例11: free

bool TRTexture::loadFromRenderedText(std::string renderedText, SDL_Color textColor){
    free();
    SDL_Surface *loadedSurface = TTF_RenderText_Solid(mFont, renderedText.c_str(), textColor);
    if(loadedSurface == NULL){
        //EXCEPTION
        printf( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
    }else{
        mTexture = SDL_CreateTextureFromSurface(mRenderer, loadedSurface);
        if(mTexture == NULL){
            //EXCEPTION
            printf( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
        }else{
            mWidth = loadedSurface->w;
            mHeight = loadedSurface->h;
        }
    }
    return mTexture != NULL;
}
开发者ID:baconLIN001,项目名称:TombRaider,代码行数:18,代码来源:TRTexture.cpp

示例12: fps_draw_msg

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

	SDL_Surface *surf= TTF_RenderText_Solid(font, msg, fg);

        SDL_TextureID text = SDL_CreateTextureFromSurface(0, surf);

        //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_RenderCopy(text, NULL, &rect);

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

示例13: va_start

void Font::WriteSolid(int x, int y, const char* text, ...) {
    SDL_Rect pos;
    pos.x = x;
    pos.y = y;

    char* buffer = new char[strlen(text)+1];

    va_list args;
	va_start(args, text);
	vsprintf(buffer, text, args);
	va_end(args);

    SDL_Surface* aux = TTF_RenderText_Solid(font, buffer, fg);
    SDL_BlitSurface(aux, NULL, surface, &pos);

    delete buffer;
    SDL_FreeSurface(aux);
}
开发者ID:SanchezSobrino,项目名称:Campo-Estelar-2010,代码行数:18,代码来源:Font.cpp

示例14: TTF_RenderText_Solid

    void Painter::drawString(iXY pos, const std::string & text, const std::string & font)
    {
        currentTransform.apply(pos);
        Palette p;
        SDL_Color c = p[brushColor];
        SDL_Color c2;
        c2.r = c.red;
        c2.g = c.green;
        c2.b = c.blue;
                
        SDL_Surface * surface = TTF_RenderText_Solid(fontManager->getFont(font),text.c_str(), c2);

        SDL_Rect r;
        r.x = pos.x;
        r.y = pos.y;

        SDL_BlitSurface(surface, NULL, drawingSurface, &r);
    }
开发者ID:BackupTheBerlios,项目名称:netpanzer-svn,代码行数:18,代码来源:Painter.cpp

示例15: SDL_DestroyTexture

void Label::draw(SDL_Renderer *renderer) {
    if (dirty) {
        if (renderedText) {
            SDL_DestroyTexture(renderedText);
        }
        SDL_Surface* renderedSurface = TTF_RenderText_Solid(UIManager::getInstance().getFont(), text.c_str(), textColor);
        renderedText = SDL_CreateTextureFromSurface(renderer, renderedSurface);
        SDL_FreeSurface(renderedSurface);
    }
    SDL_Rect rect;
    int w, h;
    SDL_QueryTexture(renderedText, nullptr, nullptr, &w, &h);
    rect.x = getX();
    rect.y = getY();
    rect.w = w;
    rect.h = h;
    SDL_RenderCopy(renderer, renderedText, nullptr, &rect);
}
开发者ID:trid,项目名称:exp,代码行数:18,代码来源:label.cpp


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