本文整理汇总了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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}