Accessing Back Buffer In Video Memory

I am creating a double buffered surface in video memory like this:

gScreen=SDL_SetVideoMode(1024, 768, 0,
SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF);

this should create two surfaces in video memory (a primary and a
backbuffer).

I then lock like this:

if(SDL_MUSTLOCK(gScreen))
{
if(SDL_LockSurface(gScreen) < 0)
{
return FALSE;
}
}

then I use the gScreen->pixels memory pointer to draw with.

My problem is that gScreen->pixels seems to be the primary (viewing)
surface; I don’t have to call
SDL_Flip(gScreen) to view the drawn pixels. How can I access the back
(offscreen) buffer in
video memory? I would like to draw to the offscreen video buffer, then
call SDL_Flip(gScreen).
If I draw the pixels then call SDL_Flip(gScreen), I get a blank screen.

Am I missing something here :wink:

Kelly

I should also add that this behavior for this particular question is under
Windows98/DX. I am in the process of converting several demos/small test
programs from DX to SDL (this has been a very easy conversion for sure)! I
will compile them under Linux when I can get them working properly in
Win9x. I also was assuming that in the code below the memory pointer
returned would/should be the back buffer (obviously is not). Am I missing
an equivalent SDL call like DX’s GetAttachedSurface(), which would give me
access to the flip buffer which was created at the same time the main
(primary) buffer is created?

Thanks,
Kelly

kashe wrote:> I am creating a double buffered surface in video memory like this:

gScreen=SDL_SetVideoMode(1024, 768, 0,
SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF);

this should create two surfaces in video memory (a primary and a
backbuffer).

I then lock like this:

if(SDL_MUSTLOCK(gScreen))
{
if(SDL_LockSurface(gScreen) < 0)
{
return FALSE;
}
}

then I use the gScreen->pixels memory pointer to draw with.

My problem is that gScreen->pixels seems to be the primary (viewing)
surface; I don’t have to call
SDL_Flip(gScreen) to view the drawn pixels. How can I access the back
(offscreen) buffer in
video memory? I would like to draw to the offscreen video buffer, then
call SDL_Flip(gScreen).
If I draw the pixels then call SDL_Flip(gScreen), I get a blank screen.

Am I missing something here :wink:

Kelly

K. Ashe wrote in message <37F4B4D3.19AB89B8 at NOSPAM.tbcdsb.on.ca>…

I should also add that this behavior for this particular question is under
Windows98/DX. I am in the process of converting several demos/small test
programs from DX to SDL (this has been a very easy conversion for sure)! I
will compile them under Linux when I can get them working properly in
Win9x. I also was assuming that in the code below the memory pointer
returned would/should be the back buffer (obviously is not). Am I missing
an equivalent SDL call like DX’s GetAttachedSurface(), which would give me
access to the flip buffer which was created at the same time the main
(primary) buffer is created?

I am seeing similar things. Blits are going right to the screen as well.
Yes, you should be writing to the back buffer by default. I think that flags
are getting lost temporarily somewhere. I traced through part of the library
and it looks like the primary is getting set up right but then things get a
little confusing. I managed to get it working by tweaking part of the
library code were the back buffer is assigned but then the mouse got all
screwed up so I went back to windowed mode. Has anyone else seen this?
DirectX SDL writes directly to screen, not back buffer.

  • Randi

I thought it was me going mad :slight_smile: I was playing with the double buffering
demos (under Direct X), and combined plasma and newvox so that I could have
a plasma sky behind the moving landscape - but even with double buffering it
was tearing horribly.

I couldn’t see why it wasn’t working. I guess plasma and newvox alone
ran fast enough that I didn’t notice any tearing until they were combined.

As far as I could tell it seemed to me that it was writing to the screen
rather than the hidden buffer.

ttfn,
JohnOn Mon, Oct 04, 1999 at 09:52:36PM -0500, Randi J. Relander wrote:

I am seeing similar things. Blits are going right to the screen as well.
Yes, you should be writing to the back buffer by default. I think that flags
are getting lost temporarily somewhere. I traced through part of the library
and it looks like the primary is getting set up right but then things get a
little confusing. I managed to get it working by tweaking part of the
library code were the back buffer is assigned but then the mouse got all
screwed up so I went back to windowed mode. Has anyone else seen this?
DirectX SDL writes directly to screen, not back buffer.

I am seeing similar things. Blits are going right to the screen as well.
Yes, you should be writing to the back buffer by default. I think that flags
are getting lost temporarily somewhere. I traced through part of the library
and it looks like the primary is getting set up right but then things get a
little confusing. I managed to get it working by tweaking part of the
library code were the back buffer is assigned but then the mouse got all
screwed up so I went back to windowed mode. Has anyone else seen this?
DirectX SDL writes directly to screen, not back buffer.

I thought it was me going mad :slight_smile: I was playing with the double buffering
demos (under Direct X), and combined plasma and newvox so that I could have
a plasma sky behind the moving landscape - but even with double buffering it
was tearing horribly.

I couldn’t see why it wasn’t working. I guess plasma and newvox alone
ran fast enough that I didn’t notice any tearing until they were combined.

As far as I could tell it seemed to me that it was writing to the screen
rather than the hidden buffer.

ttfn,
John

I have the same problem, using DIRECTX SDL (windowed or fullscreen).

byeOn Wed, 6 Oct 1999, John Marshall wrote:

On Mon, Oct 04, 1999 at 09:52:36PM -0500, Randi J. Relander wrote:

Carlo Carlini wrote:

I am seeing similar things. Blits are going right to the screen as well.
Yes, you should be writing to the back buffer by default. I think that flags
are getting lost temporarily somewhere. I traced through part of the library
and it looks like the primary is getting set up right but then things get a
little confusing. I managed to get it working by tweaking part of the
library code were the back buffer is assigned but then the mouse got all
screwed up so I went back to windowed mode. Has anyone else seen this?
DirectX SDL writes directly to screen, not back buffer.

I thought it was me going mad :slight_smile: I was playing with the double buffering
demos (under Direct X), and combined plasma and newvox so that I could have
a plasma sky behind the moving landscape - but even with double buffering it
was tearing horribly.

I couldn’t see why it wasn’t working. I guess plasma and newvox alone
ran fast enough that I didn’t notice any tearing until they were combined.

As far as I could tell it seemed to me that it was writing to the screen
rather than the hidden buffer.

ttfn,
John

I have the same problem, using DIRECTX SDL (windowed or fullscreen).

bye

I’ll take a look at this as soon as I get a chance. I won’t have time
(LokiHack '99) until the end of the month, so if anyone else wants to
investigate this, you are more than welcome.> On Wed, 6 Oct 1999, John Marshall wrote:

On Mon, Oct 04, 1999 at 09:52:36PM -0500, Randi J. Relander wrote:

-Sam Lantinga, Lead Programmer, Loki Entertainment Software