Question about using the main screen as a souce for blits to itself

I’m trying to write a simple tile based scroll engine. I had no trouble doing scrolling by drawing all the tiles each time, but that seem kind of inefficent. Since most of time I only need to draw a few new tiles along the edge of the screen in the direction I need to scroll, I thought I could shift the already drawn tiles by blitting the chunk from the screen where I already had drawn the tiles to the place where they need to be after the next scroll. Then all I’d have to do is draw in the newly visible tiles along the edge. The idea was suppose to be like the old vga trick where you get a pointer to video memory and shift the bits around, except I didn’t think that would be a practical idea for a cross platform app. Using a blit to do the shift seem like the next best thing. I can’t seem to get it to work though. When I do the blit, the screen will flash. Some times it’ll go black and some times white. Ussually the screen will go black a few times at first and the start going white. In the end, it seems to draw the chunk where I want it, but I can’t seem to get it to scroll right in spite of that. Oddly enough, the behavior changes depending on whether I’m in full screen mode or not. It seems to work more or less in windowed mode and breaks in full screen mode. I told SDL_SetVideoMode to give me a double buffered screen, which I assume is why the behavior changes (since you can’t do double buffering in windowed mode I think). But I don’t know exactly what the trouble is. I guess my question is: should this work at all? Can I blit from the screen to the screen like this and have it work? If anyone wants to see the code I’m happy to post it, but it’s kinda long so I won’t unless someone asks. Thanks yet again.

Jeremy Gregorio
@Jeremy_Gregorio

p.s. thanks to everyone that answered my first question. It’s been way too long since I wrote anything with SDL, but even so I guess I should have remembered what locked surfaces are :). Oh well, thanks again.


I guess my question is: should this work at all? Can I blit from the screen to the screen like this and have it work?

You could but it’s probably not a good idea. VRAM reads are very very
slow compared to system ram and you’d likely be better off re-blitting
all the tiles. It wouldn’t be an issue if you were keeping a buffer
in system memory already but that’s probably not a good idea either.
I think that’s been covered in other posts to this list.On Sat, Dec 01, 2001 at 02:22:06AM -0800, Jeremy Gregorio wrote:

Jeremy Gregorio
rsilvergun at home.net


Greg V. (hmaon)

PS: First post? (sorry :P)

I think the quickest way to scroll tiles is to make 2 ,or more, surfaces and blit a whole veiwable screen to the surface at a time. Then blit them to the screen as need, and be building the next surfarce at the same time. That way your only blitting four time to the screen max, and that will speed things up a lot. The only draw back is it eats ram faster too.> ----- Original Message -----

From: Jeremy Gregorio
To: libsdl
Sent: Saturday, December 01, 2001 2:22 AM
Subject: [SDL] question about using the main screen as a souce for blits to itself

I’m trying to write a simple tile based scroll engine. I had no trouble doing scrolling by drawing all the tiles each time, but that seem kind of inefficent. Since most of time I only need to draw a few new tiles along the edge of the screen in the direction I need to scroll, I thought I could shift the already drawn tiles by blitting the chunk from the screen where I already had drawn the tiles to the place where they need to be after the next scroll. Then all I’d have to do is draw in the newly visible tiles along the edge. The idea was suppose to be like the old vga trick where you get a pointer to video memory and shift the bits around, except I didn’t think that would be a practical idea for a cross platform app. Using a blit to do the shift seem like the next best thing. I can’t seem to get it to work though. When I do the blit, the screen will flash. Some times it’ll go black and some times white. Ussually the screen will go black a few times at first and the start going white. In the end, it seems to draw the chunk where I want it, but I can’t seem to get it to scroll right in spite of that. Oddly enough, the behavior changes depending on whether I’m in full screen mode or not. It seems to work more or less in windowed mode and breaks in full screen mode. I told SDL_SetVideoMode to give me a double buffered screen, which I assume is why the behavior changes (since you can’t do double buffering in windowed mode I think). But I don’t know exactly what the trouble is. I guess my question is: should this work at all? Can I blit from the screen to the screen like this and have it work? If anyone wants to see the code I’m happy to post it, but it’s kinda long so I won’t unless someone asks. Thanks yet again.

Jeremy Gregorio
rsilvergun at home.net

p.s. thanks to everyone that answered my first question. It’s been way too long since I wrote anything with SDL, but even so I guess I should have remembered what locked surfaces are :). Oh well, thanks again