sdl - How to blit a text surface on SDL_Overlay? -


i'm newbie in sdl. question: create text surface use sdl_ttf.dll. ttf_font* myfont = ttf_openfont(szfontpath, text.m_ifontsize); sdl_surface *textsurface = ttf_renderunicode_blended(myfont, (const uint16*)text.m_wstrfilepath.c_str(), textcolor);

this works fine , textsurface ok if blit on screen,which used play video. sdl_blitsurface(textsurface , null, screen, offset); problem text on screen keep blinking in every 3 /4 seconds, set screen sdl_doublebuf , sdl_hwsurface, not help. went way.i decide blit text on screen before display. use function:

blitsurface2yuv(text, vp->bmp, &rectoffset); //vp->bmp sdl_overlay display it: sdl_displayyuvoverlay(vp->bmp, &rcrview); //rcview offset screen

"blitsurface2yuv" defined here:

   int blitsurface2yuv(sdl_surface *src, sdl_overlay *dst, sdl_rect *dstrect)    {   uint8 r, g, b;   int y1,u1,v1;   int y,x;   int height = src->h < dstrect->h ? src->h: dstrect->h;   int width =  src->w < dstrect->w ? src->w: dstrect->w;   int uv_off = 0;   uint32 pixel;    if(dst->format != sdl_yv12_overlay)     return 1;    for(y = 0; y < height; ++y)   {     for(x = 0; x < width; ++x)     {         switch(src->format->bitsperpixel)         {         case 8:             pixel = *((uint8*)src->pixels + y*src->pitch + x);             break;         case 16:             pixel = *((uint16*)src->pixels + y*src->pitch/2 + x);             break;         case 32:             pixel = *((uint32*)src->pixels + y*src->pitch/4 + x);             break;         default:             return -1;         }         sdl_getrgb(pixel, src->format, &r, &g, &b);         rgb2yuv(r, g, b, &y1, &u1, &v1);          memset(dst->pixels[0] + (dstrect->y + y) * dst->pitches[0] + (dstrect->x + x),              (uint8)y1, 1);          if((x%2 == 0 ) && (y%2 == 0 ))         {             memset(dst->pixels[1] + (uv_off + dstrect->y /2) * dst->pitches[1] + (dstrect->x/2 + x/2),                  (uint8)v1, 1);             memset(dst->pixels[2] + (uv_off + dstrect->y /2) * dst->pitches[2] + (dstrect->x/2 + x/2),                  (uint8)u1, 1);         }     }     if(y%2 == 0)++uv_off; } return 0; } 

this can solve blink problem. text on screen has black background, supposed empty.

so can tell me problem?

this not answer long comment.

i think you're trying solve wrong problem. initial problem text, generated using ttf_renderunicode_blended "blinks" @ interval when calling sdl_blitsurface on screen surface. supposed work, , has worked in of sdl projects.

this means there has wrong either rendering loop or text, if post more code helpful!


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -