本文整理汇总了C++中TTF_GetError函数的典型用法代码示例。如果您正苦于以下问题:C++ TTF_GetError函数的具体用法?C++ TTF_GetError怎么用?C++ TTF_GetError使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TTF_GetError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Font_initialize
static VALUE
Font_initialize(VALUE self, VALUE rbRealFilePath, VALUE rbSize,
VALUE rbBold, VALUE rbItalic, VALUE rbTtcIndex)
{
const char* path = StringValueCStr(rbRealFilePath);
const int size = NUM2INT(rbSize);
const bool bold = RTEST(rbBold);
const bool italic = RTEST(rbItalic);
const int ttcIndex = NUM2INT(rbTtcIndex);
Font* font;
Data_Get_Struct(self, Font, font);
font->size = size;
font->sdlFont = TTF_OpenFontIndex(path, size, ttcIndex);
if (!font->sdlFont) {
rb_raise(strb_GetStarRubyErrorClass(), "%s (%s)", TTF_GetError(), path);
}
const int style = TTF_STYLE_NORMAL |
(bold ? TTF_STYLE_BOLD : 0) | (italic ? TTF_STYLE_ITALIC : 0);
TTF_SetFontStyle(font->sdlFont, style);
return Qnil;
}
示例2: SDL_FreeSurface
void TextView::setText(string s){
if(s.empty()){
if(textSurface != NULL)
SDL_FreeSurface( textSurface );
textSurface = NULL;
return;
}
text = s;
SDL_Surface * newTextSurface;
newTextSurface = TTF_RenderText_Blended(font, text.c_str(), textColor);
if(newTextSurface == NULL)
{
cerr << "TTF_RenderText_Blended() Failed: " << TTF_GetError() << endl;
TTF_Quit();
return;
}
if(textSurface != NULL)
SDL_FreeSurface( textSurface );
textSurface = newTextSurface;
resize(textSurface->w,textSurface->h);
}
示例3: init
bool init() {
bool success=true;
if(SDL_Init(SDL_INIT_VIDEO)<0) {
std::cout<<"SDL could not initialize! SDL Error: "<<SDL_GetError()<<std::endl;
success=false;
}
else {
if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) {
std::cout<<"Warning: Linear texture filtering not enabled!";
}
gWindow=SDL_CreateWindow("Snake II", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if(gWindow==NULL) {
std::cout<<"Window could not be created! SDL Error: "<<SDL_GetError()<<std::endl;
success=false;
}
else {
gRenderer=SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
if(gRenderer==NULL) {
std::cout<<"Renderer could not be created! SDL Error: "<<SDL_GetError()<<std::endl;
success=false;
}
else {
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
int imgFlags = IMG_INIT_PNG;
if(!(IMG_Init(imgFlags) & imgFlags)) {
std::cout<<"SDL_image could not initialize! SDL_image Error: "<<IMG_GetError()<<std::endl;
success=false;
}
if(TTF_Init()==-1) {
std::cout<<"SDL_ttf could not initialize! SDL_ttf Error: "<<TTF_GetError()<<std::endl;
success=false;
}
}
}
}
return success;
}
示例4: Resource
/** Constructor
* Creates a texture instance for rendering text.
*
* @param p_id The string identifier of the resource
* @param p_renderer The window renderer used to create the text texture
* @param p_font Pointer to a TTF_Font object used to render the text
* @param p_textureText The string to render
* @param p_textColor The color to render the text as
*/
n8::Texture::Texture(std::string p_id, SDL_Renderer* p_renderer, TTF_Font* p_font, std::string p_textureText, SDL_Color p_textColor ) : Resource(p_id)
{
SDL_Surface* textSurface = TTF_RenderText_Solid( p_font, p_textureText.c_str(), p_textColor );
if( textSurface == nullptr )
{
std::string msg( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
n8::Log::Error(TAG, msg);
if(p_font == nullptr)
n8::Log::Error( TAG, " font was null");
else
n8::Log::Error( TAG, " font wasn't null");
string textMessage( " texture text was: %s", p_textureText.c_str());
n8::Log::Error(TAG, textMessage);
}
else
{
//Create texture from surface pixels
m_texture = SDL_CreateTextureFromSurface( p_renderer, textSurface );
if( m_texture == nullptr )
{
string textureCreationFailedMsg("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
n8::Log::Error(TAG, textureCreationFailedMsg);
}
else
{
//Get image dimensions
m_width = textSurface->w;
m_height = textSurface->h;
}
//Get rid of old surface
SDL_FreeSurface( textSurface );
}
}
示例5: free
bool Drawable::loadFromRenderedText( std::string textureText, SDL_Color textColor )
{
//Get rid of preexisting texture
free();
TTF_Font * gFont = TTF_OpenFont(GlobalDefs::getResource(RESOURCE_FONT, "zorque.ttf").c_str(),40);
//Render text surface
SDL_Surface* textSurface = TTF_RenderText_Solid( gFont, textureText.c_str(), textColor );
TTF_CloseFont(gFont);
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( renderer, textSurface );
if( mTexture == NULL )
{
printf( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
}
else
{
//Get image dimensions
image_size = {textSurface->w, textSurface->h};
render_size = image_size;
}
//Get rid of old surface
SDL_FreeSurface( textSurface );
}
//Return success
return mTexture != NULL;
}
示例6: TTF_RenderText_Blended
bool Text::LoadText(std::string _textureText, SDL_Color _textColor, TTF_Font* _textureFont)
{
// Make sure to delete any previous surfaces (unlikely but just in case)
this->FreeText();
// Create the new surface by using the SDL_TTF plugin, blended so we have the lovely alpha values of the text
SDL_Surface* textSurface = TTF_RenderText_Blended(_textureFont, _textureText.c_str(), _textColor);
if (textSurface == NULL)
{
// If we can't make it then error
printf("Unable to render text surface. SDL_ttf Error: %s\n", TTF_GetError());
}
else
{
// Otherwise create and store our values for later use
this->m_textString = _textureText;
this->m_textColor = _textColor;
this->m_textFont = _textureFont;
// Create the texture we're going to draw from the surface we just created
this->m_text = SDL_CreateTextureFromSurface(this->m_render, textSurface);
if (m_text == NULL)
{
printf("Unable to create texture from rendered text. SDL Error: %s\n", SDL_GetError());
}
else
{
// Assign the sizes from the surface and store them for drawing
m_width = textSurface->w;
m_height = textSurface->h;
SDL_Rect rect = { 0, 0, m_width, m_height };
m_rect = rect;
}
SDL_FreeSurface(textSurface);
}
return this->m_text != NULL;
}
示例7: TTF_OpenFontRW
TTF_Font* FontManager::getTTF_Font(std::string filename, int pointsize)
{
TTFId id;
id.filename = filename;
id.pointsize = pointsize;
std::map<TTFId, TTF_Font*>::iterator iter;
iter = ttf_fonts.find(id);
if (iter != ttf_fonts.end())
return iter->second;
IDataSource* fontids;
fontids = FileSystem::get_instance()->ReadFile("@data/" + filename);
if (!fontids) {
perr << "Failed to open TTF: @data/" << filename << std::endl;
return 0;
}
// open font using SDL_RWops.
// Note: The RWops and IDataSource will be deleted by the TTF_Font
TTF_Font* font = TTF_OpenFontRW(fontids->getRWops(), 1, pointsize);
if (!font) {
perr << "Failed to open TTF: @data/" << filename
<< ": " << TTF_GetError() << std::endl;
return 0;
}
ttf_fonts[id] = font;
#ifdef DEBUG
pout << "Opened TTF: @data/" << filename << "." << std::endl;
#endif
return font;
}
示例8: TTF_RenderUTF8_Solid
bool NXFont::InitChars(TTF_Font *font, uint32_t color)
{
SDL_Color fgcolor;
SDL_Surface *letter;
fgcolor.r = (uint8_t)(color >> 16);
fgcolor.g = (uint8_t)(color >> 8);
fgcolor.b = (uint8_t)(color);
#ifdef _L10N_CP1251
char utf8_str[2];
#endif
char str[2];
str[1] = 0;
for(int i=1;i<NUM_LETTERS_RENDERED;i++)
{
str[0] = i;
#ifndef _L10N_CP1251
letter = TTF_RenderUTF8_Solid(font, str, fgcolor);
#else
win1251_to_utf8(str, utf8_str);
letter = TTF_RenderUTF8_Solid(font, utf8_str, fgcolor);
#endif
if (!letter)
{
staterr("InitChars: failed to render character %d: %s", i, TTF_GetError());
return 1;
}
letters[i] = SDL_DisplayFormat(letter);
SDL_FreeSurface(letter);
}
return 0;
}
示例9: SDL_DestroyTexture
bool TextureManager::load_text(const std::string & text,
const std::string & id,
const SDL_Color & color,
SDL_Renderer * renderer)
{
if (textures[id] != NULL)
SDL_DestroyTexture(textures[id]);
std::string rendered_text = " ";
TTF_Font * f = Game::get_instance() -> get_font();
//SDL_Color color = {152, 255, 255, 0};
if (text.length() > 0)
{
rendered_text = text;
}
SDL_Surface * tmp = TTF_RenderText_Solid(f, rendered_text.c_str(), color);
if (!tmp)
{
std::cerr << "Failure loading text: "
<< TTF_GetError() << std::endl;
return false;
}
SDL_Texture * new_texture = SDL_CreateTextureFromSurface(renderer, tmp);
SDL_FreeSurface(tmp);
if (!new_texture)
{
std::cerr << "Failure loading texture: "
<< SDL_GetError() << std::endl;
return false;
}
textures[id] = new_texture;
return true;
}
示例10: texture_load_font_string
bool
texture_load_font_string(texture* img, char* text, SDL_Color text_color) {
// rm preexisting texture
texture_free(img);
// https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_43.html
s_surface* text_surface = TTF_RenderText_Solid(g_font, text, text_color);
if ( !text_surface )
{
printf("texture_load_font_string: unable to render text, ttf err: %s\n", TTF_GetError());
}
else
{
// create texture
img->ref = SDL_CreateTextureFromSurface(g_render, text_surface);
if ( !img->ref )
{
printf("texture_load_font_string: unable to create text texture, err: %s\n", SDL_GetError());
}
else
{
// get image dimensions
img->w = text_surface->w;
img->h = text_surface->h;
}
// flush surface
SDL_FreeSurface(text_surface);
}
return img->ref != 0;
}
示例11: Display
CDebugger::CDebugger(CDisplay& Display, CSettingsManager& Settings): Display(Display)
{
/* Load the main font to be used throughout
* the debugger information.
*/
std::string font_name(Settings.GetValueAt("DebugFont"));
if(font_name == "")
/* Erroneous font name, hopefully we can
* load a safe alternative.
*/
font_name == "C:\\Windows\\Fonts\\Arial.ttf";
std::string size(Settings.GetValueAt("DebugFontSize"));
if(size == "")
/* No font size given! Most likely the font name
* check failed as well, so a 12pt Arial font
* would be just fine for debug info.
*/
size = "12";
this->debug_font = TTF_OpenFont(font_name.c_str(), atoi(size.c_str()));
if(!this->debug_font)
handleError(TTF_GetError());
/* For debug builds of the program,
* debugging is automatically on by default.
*/
#ifdef _DEBUG
this->ToggleDebugMode(true);
#else
this->ToggleDebugMode(false);
#endif // _DEBUG
}
示例12: spFontReload
PREFIX int spFontReload(spFontPointer font,const char* fontname,Uint32 size)
{
spLetterDelete( font->root );
font->root = NULL;
spLetterDelete( font->buttonRoot );
font->buttonRoot = NULL;
if ( font->cache.cache )
free( font->cache.cache );
TTF_CloseFont( font->font );
font->font = TTF_OpenFont( fontname, size );
if ( !(font->font) )
{
printf( "Failed to load Font \"%s\", dude...\n", fontname );
printf( " Error was: \"%s\"\n", TTF_GetError() );
free(font);
return 1;
}
font->size = size;
font->maxheight = 0;
font->cacheOffset = 0;
font->cache.cache = NULL;
spFontChangeCacheSize( font, SP_FONT_DEFAULT_CACHE );
return 0;
}
示例13: loadTextureFromFont
GLuint loadTextureFromFont(const std::string& fontFilename, int pointSize, const std::string& text)
{
GLuint textureID = 0;
TTF_Font * font = TTF_OpenFont(fontFilename.c_str(), pointSize);
if (!font)
{
std::cout << "Unable to load font " << fontFilename << " " << TTF_GetError();
return textureID;
}
SDL_Surface *textSurface = TTF_RenderText_Blended(font, text.c_str(), { 255, 255, 255 });
textureID = convertSDLSurfaceToGLTexture(textSurface);
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_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
TTF_CloseFont(font);
return textureID;
}
示例14: Spaceinvader_opprett
Spaceinvader * Spaceinvader_opprett() {
/* Opprett Spaceinvader-objekt. */
Spaceinvader *s = (Spaceinvader*)malloc(sizeof(Spaceinvader));
/* Initier SDL */
if (SDL_Init(SDL_INIT_VIDEO) != 0){
printf ("SDL_Init Error: %s", SDL_GetError());
return NULL;
}
/* Initier TTF */
if (TTF_Init() != 0) {
printf ("TTF_Init Error: %s", TTF_GetError());
return NULL;
}
/* Opprett skjerm-objekt. */
s->skjerm = Skjerm_opprett(s);
if (s->skjerm == NULL) {
printf ("Skjerm_opprett Error: Systemfeil.");
return NULL;
}
s->modell = Modell_opprett(s);
s->kontrollsentral = Kontrollsentral_opprett(s);
return s;
}
示例15: free
bool STexture::loadFromRenderedText(std::string textureText, SDL_Color textColor)
{
//Get rid of preexisting texture
free();
TTF_Font *gFont = NULL;
//Render text surface
SDL_Surface* textSurface = TTF_RenderText_Solid(gFont, textureText.c_str(), textColor);
if (textSurface != NULL)
{
//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);
}
else
{
printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());
}
//Return success
return mTexture != NULL;
}