Method: Rubygame::TTF#render_utf8

Defined in:
ext/rubygame/rubygame_ttf.c

#render_utf8(string, aa, fg, bg) ⇒ Surface

Renders a string to a Surface with the font’s style and the given color(s).

This method takes these arguments:

string

the text string to render

aa

Use anti-aliasing if true. Enabling this makes the text look much nicer (smooth curves), but is much slower.

fg

the color to render the text, in the form [r,g,b]

bg

the color to use as a background for the text. This option can be omitted to have a transparent background.

Returns:



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'ext/rubygame/rubygame_ttf.c', line 435

VALUE rbgm_ttf_render_utf8(int argc, VALUE *argv, VALUE self)
{
 	SDL_Surface *surf;
 	TTF_Font *font;
 	SDL_Color fore, back; /* foreground and background colors */
	VALUE vstring, vaa, vfg, vbg;
 
	rb_scan_args(argc, argv, "31", &vstring, &vaa, &vfg, &vbg);
 
 	Data_Get_Struct(self,TTF_Font,font);
 
	fore = make_sdl_color(vfg);

	if( RTEST(vbg) )
	{
		back = make_sdl_color(vbg);
	}

	if( RTEST(vaa) ) /* anti-aliasing enabled */
 	{
 		if( RTEST(vbg) ) /* background color provided */
 			surf = TTF_RenderUTF8_Shaded(font,StringValuePtr(vstring),fore,back);
 		else /* no background color */
 			surf = TTF_RenderUTF8_Blended(font,StringValuePtr(vstring),fore);
 	}
 	else /* anti-aliasing not enabled */
 	{
 		if( RTEST(vbg) ) /* background color provided */	
 		{
 			/* remove colorkey, set color index 0 to background color */
 			surf = TTF_RenderUTF8_Solid(font,StringValuePtr(vstring),fore);
 			SDL_SetColors(surf,&back,0,1);
 			SDL_SetColorKey(surf,0,0);
 		}
 		else /* no background color */
 		{
 			surf = TTF_RenderUTF8_Solid(font,StringValuePtr(vstring),fore);
 		}
 	}
 
 	if(surf==NULL)
 		rb_raise(eSDLError,"could not render font object: %s",TTF_GetError());
 	return Data_Wrap_Struct(cSurface,0,SDL_FreeSurface,surf);
}