RenderedGlyphContainer::RenderedGlyph RenderedGlyphContainer::renderGlyph(glyph_char glyph, void*fontptr, void*renderer, unsigned int size, int fontstyle, bool antialiasing)
	{
		TTF_Font* font = (TTF_Font*)fontptr;
		SDL_Color color = {255,255,255,255}; //white
		SDL_Surface* surface = nullptr;
		if(antialiasing)
		{
			surface = TTF_RenderGlyph_Blended(font, CharForceConvert<glyph_char, GameLibrary::Uint16>(glyph), color);
		}
		else
		{
			surface = TTF_RenderGlyph_Solid(font, CharForceConvert<glyph_char, GameLibrary::Uint16>(glyph), color);
		}
		if(surface == nullptr)
		{
			throw RenderGlyphException(TTF_GetError());
		}
		SDL_Texture*texture = SDL_CreateTextureFromSurface((SDL_Renderer*)renderer, surface);
		SDL_FreeSurface(surface);
		if(texture == nullptr)
		{
			throw RenderGlyphException(SDL_GetError());
		}

		RenderedGlyph renderedGlyph;
		renderedGlyph.texture = texture;
		renderedGlyph.size = size;
		renderedGlyph.fontstyle = fontstyle;
		renderedGlyph.antialias = antialiasing;

		return renderedGlyph;
	}
Example #2
0
static void cache_glyphs()
{
    int top=999, bottom=-999;

    start_color();
    
    for(int ch=0; ch<128; ch++)
    {
        for(int color=0; color<16; color++)
        {
            SDL_Surface * glyph = glyph_cache[ch][color] = TTF_RenderGlyph_Solid(font, ch, windowsPalette[color]);
            int minx, maxx, miny, maxy, advance;
            if(glyph!=NULL && color==0 && 0==TTF_GlyphMetrics(font, ch, &minx, &maxx, &miny, &maxy, &advance) )
            {
               int t = TTF_FontAscent(font)-maxy;
               int b = t + glyph->h;
               if(t<top) top = t;
               if(b>bottom) bottom = b;
            }
        }
    }
    
    int height = bottom - top;
    int delta = (fontheight-height)/2;

    ttf_height_hack =  delta - top;
}
Example #3
0
extern DECLSPEC SDL_Surface * SDLCALL
  TTF_RenderGlyph_Solid_p(
    TTF_Font *font,
    uint16_t glyph,
    SDL_Color *fg) {

  return TTF_RenderGlyph_Solid(font, glyph, *fg);
}
Example #4
0
SDL_Surface* SimKit::TTFVFont::render_font(const Uint32 ch, const SDL_Color textcol, const SimKit::IVFont::TransparencyType bg) {
    switch (bg) {
        case SimKit::IVFont::COLORKEY:
            return TTF_RenderGlyph_Solid(this->rfont, ch, textcol);
        case SimKit::IVFont::ALPHA:
            return TTF_RenderGlyph_Blended(this->rfont, ch, textcol);
    }
};
Example #5
0
void cache_glyphs()
{
    int i;
    char title[800];
    SDL_Color fg={0,0,0,255};
#if RENDER_MODE==1
    SDL_Color bg={255,255,255,255};
#endif

    free_glyphs();
    if(!font)
        return;
    if(style!=TTF_GetFontStyle(font))
        TTF_SetFontStyle(font,style);
    if(kerning != !!TTF_GetFontKerning(font))
        TTF_SetFontKerning(font,kerning);
    if(hinting != TTF_GetFontHinting(font))
        TTF_SetFontHinting(font,hinting);
    if(outline != TTF_GetFontOutline(font))
        TTF_SetFontOutline(font,outline);
    for(i=0; i<128; i++)
    {
        /* cache rendered surface */
#if RENDER_MODE==0
        text[i]=TTF_RenderGlyph_Solid(font,i+start_glyph,fg);
#elif RENDER_MODE==1
        text[i]=TTF_RenderGlyph_Shaded(font,i+start_glyph,fg,bg);
#elif RENDER_MODE==2
        text[i]=TTF_RenderGlyph_Blended(font,i+start_glyph,fg);
#endif
        if(!text[i])
        {
            printf("TTF_RenderGlyph_Shaded: %s\n", TTF_GetError());
            exit(4);
        }
        /* cache metrics */
        TTF_GlyphMetrics(font, i+start_glyph,
            &gm[i].minx, &gm[i].maxx,
            &gm[i].miny, &gm[i].maxy,
            &gm[i].advance);
    }

    sprintf(title,"%s-%s:%d+0x%04x",TTF_FontFaceFamilyName(font),
        TTF_FontFaceStyleName(font),font_size,start_glyph);
    SDL_WM_SetCaption(title,"latin1");
}
Example #6
0
static mrb_value
mrb_sdl2_ttf_font_render_glyph(mrb_state *mrb, mrb_value self)
{
  mrb_value text; 
  mrb_int r, g, b, a;
  SDL_Surface * c;
  SDL_Color color;
  mrb_get_args(mrb, "Siiii", &text, &r, &g, &b, &a);
  color.r = r;
  color.g = g;
  color.b = b;
  color.a = a;
  c = TTF_RenderGlyph_Solid(mrb_sdl2_font_get_ptr(mrb, self), RSTRING_PTR(text)[0], color);
  if (c == NULL) {
    mruby_sdl2_raise_error(mrb);
    return mrb_false_value();
  }
  return mrb_sdl2_video_surface(mrb, c, 0);
}
Example #7
0
void GM_Debug::renderScene()
{
	if(background)
		background->Blit(0,0,0,0,background->getBasicWidth(),background->getBasicHeight(),glictGlobals.w, glictGlobals.h);
	if(spr)
		spr->Blit(50,50);
 	if(thing)
		thing->Blit(100,50);

	if(background)
		background->Blit(150,50,125,51,85,136,32,48);

/*
    int xs = px - mapw/2;
    int ys = py - maph/2;
    int xe = px + mapw/2;
    int ye = py + maph/2;

    if (map[0]) map[0]->Blit(0,0, xs%256, ys%256, 256-(xs%256), 256-(ys%256));
    if (map[1]) map[1]->Blit(256-(xs%256),0, 0, ys%256, mapw-(256-(xs%256)), 256-(ys%256));
    if (map[2]) map[2]->Blit(0,256-(ys%256), xs%256, 0, 256-(xs%256), maph-(256-(ys%256)));
    if (map[3]) map[3]->Blit(256-(xs%256),256-(ys%256), 0, 0, mapw-(256-(xs%256)), maph-(256-(ys%256)));
*/
	GM_Debug *gd = (GM_Debug*)g_game;
    a.renderSelf(700,0,256,256,Position(gd->px, gd->py, gd->pz));

/*
    std::stringstream testchar;
    testchar << (char)('u'+32);

    for(int i = 0; i < 255; i++) {
        g_engine->drawText(testchar.str().c_str(), "system", 0+(i%8)*12,300+(i/8)*12, i);
    }
*/


	//desktop.RememberTransformations();
	desktop.Paint();

#ifdef SDLTTF_EXPERIMENT
    if (font) 
	{

        SDL_Surface* glyph = NULL;
        SDL_Color forecol, backcol;

        forecol.r = 255;
        forecol.g = 255;
        forecol.b = 255;

        backcol.r = 0;
        backcol.g = 0;
        backcol.b = 0;


        SDL_SetClipRect(g_engine->m_screen, NULL);

        int YOffset = TTF_FontAscent(font);  // Actually a baseline


        for (int i = 32; i < 256; i++)
        {

            int minx, maxx, miny, maxy, advance;


            glyph = TTF_RenderGlyph_Solid( font, i, forecol);//backcol ); // solid or shaded; shaded uses backcol, solid doesnt


            TTF_GlyphMetrics(font, i, &minx, &maxx, &miny, &maxy, &advance);


            SDL_Rect src = {0, 0, glyph->w, glyph->h};
            SDL_Rect dest = {((i - 32) % 32)*8 + minx,
                             ((i - 32) / 32)*16 + YOffset-maxy,
                             glyph->w,
                             glyph->h};





            SDL_BlitSurface(glyph, &src, g_engine->m_screen, &dest);


            SDL_FreeSurface(glyph);
        }
    }
#endif

}