Using A Second Surface As Accum Buffer...


PokeParadox

Founder of Pirate Games - Penjin Coder
Staff member
Joined
Dec 8, 2005
Messages
6,603
Age
40
Location
UK
Website
pokeparadox.itch.io
WEBSITE
https://github.com/pokeparadox
YOUTUBE
pokeparadox
OK... basically I want to use an SDL_Surface* as a backbuffer, where I can copy the screen contents and then manipulate pixels and render them back. I can do things like motion blur with this, but I'm not entirely sure how to actually get the screen contents onto this backbuffer surface...

So please if someone has already done this, please share the secrets? ;) :lol:
 
Yeah, what should be different from getting stuff on the buffer than getting the buffer on the screen? o_O

Btw, got a little blur engine too, but did you actually test yours on the 2X? Mine`s pretty lame as its going through the screen pixel by pixel... dont think theres a faster way to do stuff like that?
 
Funny... I tried that and that's not working for me...
In my class:
CODE

void GFX::setBackBuffer(SDL_Surface* screen)
{
// Set up blitting area
SDL_Rect src;
src.x = screen->clip_rect.x;
src.y = screen->clip_rect.y;
src.w = screen->w;
src.h = screen->h;
backBuffer = SDL_CreateRGBSurface(0, src.x, src.h, 16,
0, 0, 0, 0);

SDL_BlitSurface(screen, &src, backBuffer, &src);
}



and when I render it back
CODE

void GFX::renderBackBuffer(SDL_Surface* screen)
{
SDL_Rect src;
src.x = screen->clip_rect.x;
src.y = screen->clip_rect.y;
src.w = screen->w;
src.h = screen->h;
SDL_BlitSurface(backBuffer, &src, screen, &src);
}



Unfortunately I'm not get anything from the stored buffer :S
 
This is how I'm using those functions:
CODE

if(firstPass)
{
// Use backbuffer to store current screen
gfx.setBackBuffer(screen);
//gfx.setBackBufferFormat(screen);
//gfx.setBackBufferAlpha(128);
//gfx.lockBackBuffer();
//gfx.changeBackBufferBrightness(-20);
//gfx.unlockBackBuffer();
firstPass = false;
}
// Clear screen
SDL_FillRect(screen, NULL, 0);
gfx.renderBackBuffer(screen);



I'm trying to grab the gameplay screen and use it (I'll fade it on the name entry screen)
So I try to grab this screen from the first render of the name entry (since the video is still in the buffer)
If I don't clear the screen then I can see the gameplay screen but obviously the screen blurs since the surface is not being cleared.

EDIT: And I haven't tested it on the 2X yet because I can't get it to work at all yet... ha ha
I don't think fullscreen motion blur will be too tricky... maybe if you want to motion blur individual things... don't know yet...
 
PokeParadox said:
Funny... I tried that and that's not working for me...
Unfortunately I'm not get anything from the stored buffer :S
hmm all I do is;

CODE

/** DBC
* pre:
* invariant:
* post: x != NULL
*/
SDL_Surface *BackupScreen(void)
{
SDL_Surface *x = SDL_CreateRGBSurface(SDL_SWSURFACE, scx->w, scx->h, scx->format->BitsPerPixel, 0, 0, 0, 0);
if(x != NULL)
SDL_BlitSurface(scx, NULL, x, NULL);

return x;
}



scx being the double buffer.

I do my own double buffering since its needed for tv-out. so I just backup the second buffer.

works fine.
 
Last edited by a moderator:
Wait, so..

You're drawing to a surface, and blitting it to the screen?

Why not just keep that surface around, rather than fetchign back from the screen; ie: You just put on the screen last cycle, just hold onto your old surface.

ie:

USe surface1 and surface2; you alternate. The one you're drawing on is current, the _other_ one is your backbuffer thjen by definition, from last cycle?

jeff
 
Yes but I need to keep a copy so that I can redraw it.
I can keep the clean screen for only the first screen draw, then after that is is sullied by my Name Entry text etc...

In any case I also have other uses for my "accumulation buffer" so Even if there are easy ways of doing what I'm doing, I still need this for other things.
 
Back
Top