Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

SDL_gfx, YUV overlay, etc

Name: Anonymous 2012-02-06 11:51

Hi, I have problems drawing to SDL surface after I blited into it with SDL_DisplayYUVOverlay.

The purpose of the program is to display video and draw some simple shapes on top of it.

I have SDL_Overlay overlay tied to main screen  and I display it normally.
I have other screen, gui that I use like this

SDL_Surface *gui, *screen;
screen = SDL_SetVideoMode(width, height, 0, 0);
...
gui = SDL_CreateRGBSurface(0, screen->w, screen->h, 0, 0);
...

//rect is entire screen, bmp comes from ffmpeg
SDL_DisplayYUVOverlay(bmp, &rect);

//from SDL_gfx -- draw filled box
boxColor(gui, width/4, 0, 0, height/4, 0xff0000ff);
SDL_BlitSurface(gui, NULL, screen, &rect);

//update entire screen
SDL_UpdateRect(screen, 0, 0, 0, 0);


Video display works without problems. But after I blit the gui surface to screen and SDL_UpdateRects the video frame is replaced by the rectangle on black background, resulting in ugly flicker.

First I thought that default alpha of surface created by SDL_CreateRGBSurface is 1, but after adding
SDL_FillRect(gui, NULL, SDL_MapRGBA(gui->format, 0, 0, 0, 0));
nothing changed.

So, how to draw on top of video with SDL?

Name: Anonymous 2012-02-06 12:28

It appears you need to explicitly turn on alpha blending for a surface.
http://www.libsdl.org/docs/html/sdlcreatergbsurface.html

SDL_CreateRGBSurface(SDL_SRCALPHA, s->w, s->h, depth, rmask, gmask, bmask, amask);

or

SDL_SetAlpha(gui, SDL_SRCALPHA, alphaValue);

Use the source, Luke.

Name: Anonymous 2012-02-06 13:24

>>2
Thanks,

I tried adding SDL_SRCALPHA to to gui surface (example in OP is wrong, sorry about that, the call looks like
  gui = SDL_CreateRGBSurface(SDL_SRCALPHA, screen->w, screen->h, 32,
                 rmask, gmask, bmask, amask);
)


Which produced no effect. I also tried adding color key to the surface, like so
Uint8 colorkey;
colorkey = SDL_MapRGB(gui->format, 0, 0, 0);
    SDL_SetColorKey(gui, SDL_SRCCOLORKEY | SDL_SRCALPHA, colorkey);


No effect :(

Name: Anonymous 2012-02-06 15:52

GOT IT!

First, I had to create a 24bit surface with no alpha channel (amask = 0) and tie the YUV overlay to this surface (let's call it video)
Then
  blit the video frame to this video surface
  do any SDL_gfx drawing still on video surface
  blit the video surface to screen surface (the one from SDL_SetVideoMode())
  Call SDL_UpdateRect on entire screen surface.

It's blitting the entire video frame twice, so it's probably more slow than it could be, but fuck that, it's still good enough.

Don't change these.
Name: Email:
Entire Thread Thread List