本文整理汇总了C++中TTF_RenderText_Blended函数的典型用法代码示例。如果您正苦于以下问题:C++ TTF_RenderText_Blended函数的具体用法?C++ TTF_RenderText_Blended怎么用?C++ TTF_RenderText_Blended使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TTF_RenderText_Blended函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TTF_RenderText_Blended
//load the text, if it doesnt load throw an error
SDL_Surface* ImageCache::loadText(TTF_Font* font, const std::string text) const
{
SDL_Color textColor;
textColor.r = 192;
textColor.g = textColor.b = 0;
SDL_Surface* surface = TTF_RenderText_Blended(font, text.c_str(), textColor);
if(!surface)
{
throw(TTF_GetError());
}
else
{
return surface;
}
}
示例2: create_texture_str
SDL_Texture* create_texture_str(char *msg, SDL_Color color, int fontsize)
{
TTF_Font *font = TTF_OpenFont("studyres/a.ttf", fontsize);
if (!font) {
mtc_err("create font error %s", TTF_GetError());
return NULL;
}
SDL_Surface *sur = TTF_RenderText_Blended(font, msg, color);
SDL_Texture *tex = SDL_CreateTextureFromSurface(m_render2, sur);
SDL_FreeSurface(sur);
TTF_CloseFont(font);
return tex;
}
示例3: SDL_Init
Renderer::Renderer()
{
SDL_Init(SDL_INIT_EVERYTHING);
TTF_Init();
// freopen( "CON", "w", stdout );
//freopen( "CON", "w", stderr );
firstRender = true;
Font = TTF_OpenFont("Pokemon_GB.ttf", 18);
message = NULL;
SDL_Color textColor = { 255, 180, 255 };
sprite1 = SDL_LoadBMP("sprites_frame_1.bmp");
sprite2 = SDL_LoadBMP("sprites_frame_2.bmp");
message = TTF_RenderText_Blended( Font, "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG", textColor );
}
示例4: draw_text
void draw_text(t_visu *visu, char *text, int coor[2])
{
SDL_Surface *texte;
SDL_Color couleurNoire;
SDL_Rect position;
SDL_Surface *base;
texte = NULL;
memset(&couleurNoire, 0, sizeof(couleurNoire));
base = visu->info;
position.x = coor[0];
position.y = coor[1];
texte = TTF_RenderText_Blended(visu->police, text, couleurNoire);
SDL_BlitSurface(texte, NULL, base, &position);
SDL_FreeSurface(texte);
}
示例5: createRankSurfaces
std::vector<SDL_Surface*> createRankSurfaces(TTF_Font* font){
SDL_Color white = {255, 255, 255};
std::vector<SDL_Surface*> rankSurfaces;
for(int i=0; i<8; ++i){
SDL_Surface* newSurface = NULL;
rankSurfaces.push_back(newSurface);
}
rankSurfaces[0] = TTF_RenderText_Blended(font, "1er", white);
rankSurfaces[1] = TTF_RenderText_Blended(font, "2ème", white);
rankSurfaces[2] = TTF_RenderText_Blended(font, "3ème", white);
rankSurfaces[3] = TTF_RenderText_Blended(font, "4ème", white);
rankSurfaces[4] = TTF_RenderText_Blended(font, "5ème", white);
rankSurfaces[5] = TTF_RenderText_Blended(font, "6ème", white);
rankSurfaces[6] = TTF_RenderText_Blended(font, "7ème", white);
rankSurfaces[7] = TTF_RenderText_Blended(font, "8ème", white);
return rankSurfaces;
}
示例6: SDL_FillRect
void Menu::Draw( SGameEngine* game )
{
SDL_Rect bgrect = { 28, 28, SCREENWIDTH - 28 * 2, SCREENHEIGHT - 28 * 2 };
SDL_FillRect( game->screen, &bgrect, SDL_MapRGB( game->screen->format, bgColor.r, bgColor.g, bgColor.b ) );
//draw menu title
fontSurface = TTF_RenderText_Blended( theFont, title.c_str(), titleColor );
SDL_Rect where = { SCREENWIDTH / 2 - fontSurface->w / 2, 75 };
SDL_BlitSurface( fontSurface, NULL, game->screen, &where );
//draw top line
where.h = 3;
where.w = fontSurface->w + 8;
where.x -= 4;
where.y -= 2;
SDL_FillRect( game->screen, &where, SDL_MapRGB( game->screen->format, titleColor.r, titleColor.g, titleColor.b ) );
//draw left line
where.x -= 3;
where.h = 6 + fontSurface->h;
where.w = 3;
SDL_FillRect( game->screen, &where, SDL_MapRGB( game->screen->format, titleColor.r, titleColor.g, titleColor.b ) );
//draw right line
where.x += 10 + fontSurface->w;
SDL_FillRect( game->screen, &where, SDL_MapRGB( game->screen->format, titleColor.r, titleColor.g, titleColor.b ) );
//draw bottom line
where.x = SCREENWIDTH / 2 - fontSurface->w / 2 - 4;
where.y += 3 + fontSurface->h;
where.h = 3;
where.w = fontSurface->w + 8;
SDL_FillRect( game->screen, &where, SDL_MapRGB( game->screen->format, titleColor.r, titleColor.g, titleColor.b ) );
SDL_FreeSurface( fontSurface );
int offset = SCREENHEIGHT / 2 - 50 * numOptions / 2 + 10;
for( int i = 0; i < numOptions; i++ ) {
if( options[i]->isSelectable() )
drawSelectableOption( game, i, offset );
else
drawOption( game, i, offset );
offset += 50;
}
}
示例7: setprecision
/***********************************************************************
* draw: Simply draws the Counter to the screen
*
* returns: void.
***********************************************************************/
void Counter::draw(){
stringstream message;
message << fixed << setprecision(precision) << value;
// Create the surface to copy to the renderer
SDL_Surface *surf = TTF_RenderText_Blended(font, message.str().c_str(), color);
if (surf == NULL){
TTF_CloseFont(font);
return;
}
GLuint Texture = 0;
// Create the texture
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
// Enable texture parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Render the text to 2D by referencing its pixel data
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, GL_BGRA_EXT,
GL_UNSIGNED_BYTE, surf->pixels);
// Enable 2D Texture and alpha blend
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Draw the text
glBegin(GL_QUADS);
glTexCoord2d(0, 1); glVertex3d(xPosition, yPosition + surf->h, 0);
glTexCoord2d(1, 1); glVertex3d(xPosition + surf->w, yPosition + surf->h, 0);
glTexCoord2d(1, 0); glVertex3d(xPosition + surf->w, yPosition, 0);
glTexCoord2d(0, 0); glVertex3d(xPosition, yPosition, 0);
glEnd();
// Clean up
SDL_FreeSurface(surf);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glDeleteTextures(1, &Texture);
}
示例8: loop_name
void loop_name(SDL_Rect *position, t_sdl *cor, int i, t_champ *tmp)
{
SDL_Color color;
color.r = 255;
color.g = 255;
color.b = 255;
position->w = 15;
position->h = 30;
SDL_FillRect(cor->screen, position, tmp->color);
position->x += 50;
cor->name[i] = TTF_RenderText_Blended(cor->font,
tmp->graphic_name, color);
SDL_BlitSurface(cor->name[i], NULL, cor->screen, position);
position->x -= 50;
position->y += 35;
}
示例9: loadTextTexture
SDL_Texture* loadTextTexture(char* string, TTF_Font* Font, SDL_Color textColor, SDL_Renderer* renderer){
SDL_Surface* textSurface = TTF_RenderText_Blended(Font, string, textColor);
SDL_Texture* texture = NULL;
if (textSurface == NULL){
prError("Unable to create texture from rendered text");
return NULL;
}
else{
texture = SDL_CreateTextureFromSurface(renderer, textSurface);
if (texture == NULL){
prError("Unable to create texture from rendered text");
return NULL;
}
SDL_FreeSurface(textSurface);
}
return texture;
}
示例10: font_render
SDL_Rect font_render(char* message, int x, int y, int centered, TTF_Font *font, SDL_Color color) {
int w, h;
SDL_Surface *surf = TTF_RenderText_Blended(font, message, color);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surf);
SDL_FreeSurface(surf);
SDL_QueryTexture(texture, NULL, NULL, &w, &h);
SDL_Rect dest;
if (centered == 1) {
x = 640 / 2 - w / 2;
}
dest.x = x;
dest.y = y;
dest.h = h;
dest.w = w;
SDL_RenderCopy(renderer, texture, NULL, &dest);
return dest;
}
示例11: updater_
void TextPainter::Text::Update()
{
//content_.clear();
std::string new_content;
updater_(&new_content);
if (content_ == new_content)
return;
content_.clear();
content_ = new_content;
auto local = TTF_RenderText_Blended(master_->GetFont(font_name_, size_), content_.c_str(), color_);
delete content_image_;
content_image_ = nullptr;
if (local)
content_image_ = new ApproxGLImage(local);
}
示例12: TTF_OpenFont
SDL_Texture* Window::RenderText(const std::string &message, const std::string &fontFile, SDL_Color color, int fontSize)
{
//Open the font
TTF_Font *font = nullptr;
font = TTF_OpenFont(fontFile.c_str(), fontSize);
if (font == nullptr)
throw std::runtime_error("Failed to load font: " + fontFile + TTF_GetError());
//Render the message to an SDL_Surface, as that's what TTF_RenderText_X returns
SDL_Surface *surf = TTF_RenderText_Blended(font, message.c_str(), color);
SDL_Texture *texture = SDL_CreateTextureFromSurface(m_renderer, surf);
//Clean up unneeded stuff
SDL_FreeSurface(surf);
TTF_CloseFont(font);
return texture;
}
示例13: GCN_EXCEPTION
void SDLTrueTypeFont::drawString(gcn::Graphics* graphics, const std::string& text, const int x, const int y)
{
if (text == "")
{
return;
}
SDLGraphics *sdlGraphics = dynamic_cast<SDLGraphics *>(graphics);
if (sdlGraphics == NULL)
{
throw GCN_EXCEPTION("SDLTrueTypeFont::drawString. Graphics object not an SDL graphics object!");
return;
}
// This is needed for drawing the Glyph in the middle if we have spacing
int yoffset = getRowSpacing() / 2;
Color col = sdlGraphics->getColor();
SDL_Color sdlCol;
sdlCol.b = col.b;
sdlCol.r = col.r;
sdlCol.g = col.g;
SDL_Surface *textSurface;
if (mAntiAlias)
{
textSurface = TTF_RenderText_Blended(mFont, text.c_str(), sdlCol);
}
else
{
textSurface = TTF_RenderText_Solid(mFont, text.c_str(), sdlCol);
}
SDL_Rect dst, src;
dst.x = x;
dst.y = y + yoffset;
src.w = textSurface->w;
src.h = textSurface->h;
src.x = 0;
src.y = 0;
sdlGraphics->drawSDLSurface(textSurface, src, dst);
SDL_FreeSurface(textSurface);
}
示例14: textbox_set
void textbox_set(Tbox t, char *s)
{
SDL_Rect r;
SDL_Surface *txt;
SDL_Texture *text;
t->s = s;
r.x = t->x;
r.y = t->y;
txt = TTF_RenderText_Blended(t->font, s, font_fg);
text = SDL_CreateTextureFromSurface(t->screen, txt);
SDL_RenderCopy(t->screen, text, 0, &r);
if (TEXT_UTIL_DEBUG > 1)
fprintf(stderr, "%p Rendering textbox at %d/%d: `%s'\n",
t->screen, r.x, r.y, s);
}
示例15: drawTextNormal
static void drawTextNormal(int x, int y, int size, int align, SDL_Color c, char *text)
{
SDL_Surface *surface;
SDL_Texture *t;
int w, h;
long hash;
if (size >= MAX_FONTS)
{
printf("ERROR: %d exceeds max font size index of %d\n", size, MAX_FONTS);
exit(1);
}
if (!font[size])
{
loadFont(size);
}
hash = hashcode(text, size);
t = getCachedText(hash);
if (!t)
{
surface = TTF_RenderText_Blended(font[size], text, c);
t = SDL_CreateTextureFromSurface(app.renderer, surface);
SDL_FreeSurface(surface);
cacheText(hash, t);
}
SDL_QueryTexture(t, NULL, NULL, &w, &h);
if (align == TA_CENTER)
{
x -= (w / 2);
}
else if (align == TA_RIGHT)
{
x -= w;
}
SDL_SetTextureColorMod(t, c.r, c.g, c.b);
blit(t, x, y, 0);
}