Skip to main content
gamedev.net
🔒 Locked

Double Buffering problems

Started by julienX 2 replies 200+ views
Original Post
julienX
julienX
Ok im new to directdraw and am creating a simple program which uses double buffering techniques (or so i think: i tend to mix up double buffering and page flipping!). Ok what i am trying to do is: I am working in 640x480x32 mode. I have two surfaces -the primary and the backbuffer. The backbuffer is 100x100 big. I have completely filled the back buffer to green. Then I have copied the back buffer to the primary surface. But instead of displaying a 100x100 rectangle of green in the top left corner, my program outputs the whole screen as green! I set my backbuffer as 100x100, not 640x480! Heres some of the relevant code from Game_Init() and Game_Main():
  

    //FROM GAME_INIT()


    //Create primary surface

    INIT_DXSTRUCT(ddsd);
    ddsd.dwFlags = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    
    if (FAILED(lpdd->CreateSurface(&ddsd,&lpddsPrimary,NULL)))
    {
        return (0);
    }
    
    //Create back buffer

    INIT_DXSTRUCT(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    ddsd.dwWidth = 100;
    ddsd.dwHeight = 100;
    
    if (FAILED(lpdd->CreateSurface(&ddsd,&lpddsBack,NULL)))
    {
        return (0);
    }


    

//THIS IS THE WHOLE OF GAME_MAIN()


void Game_Main(HWND hwnd)
{

    //Create colour struct

    DDBLTFX fx;
    INIT_DXSTRUCT(fx);
    fx.dwFillColor = RGB32(0,0,0,0);
    
    //Now clear back buffer

    if (FAILED(lpddsBack->Blt(NULL,NULL,NULL,
                                 DDBLT_COLORFILL | 
                                 DDBLT_WAIT,&fx)))     
    {
        //Error

    }
    
    //Now set back buffer all green

    INIT_DXSTRUCT(fx);
    fx.dwFillColor = RGB32(0,0,255,0);
    lpddsBack->Blt(NULL,NULL,NULL,DDBLT_COLORFILL | 
                   DDBLT_WAIT,&fx);
    
    //Now copy back buffer to primary surface

    lpddsPrimary->Blt(NULL,lpddsBack,NULL,DDBLT_WAIT,NULL);
    
    Sleep(1000);
    
} //End Game_Main


    
  
I bet this is some simple problem, so remember that im new to directx! Thanks for your time
chacha
VolkerG
VolkerG
That''s what Blt is doing when you don''t pass any RECT. Set at least the destination rectangle to the same size as the source surface.
julienX
julienX
Hey thanks a lot! A understand the problem now, I fixed it and it works.

Oh while I''m here, I have another question:

What is the difference between page flipping and doublebuffering?

Thanks
chacha
Jason Doucette
Jason Doucette
quote:
Original post by julienX
Hey thanks a lot! A understand the problem now, I fixed it and it works.

Oh while I''m here, I have another question:

What is the difference between page flipping and doublebuffering?

Thanks


They are basically the same thing.

Double Buffering means using two screen buffers that are the same size as the viewable screen. You view one, while you write to the other. When the frame drawing is complete, you swap buffers (this is NOT copying the backbuffer to the viewable buffer). The system basically swaps ''pointers'' to both buffers, so now you are seeing the buffer that WAS the backbuffer, and you are writing to buffer that WAS the viewable buffer - without actually copying any memory from one buffer to another. That''s double buffering.

This could also be called page flipping - it depends on exactly how you define flipping. I don''t know about everyone else, but I call double buffering page flipping. Some people MAY call page flipping only when you actually copy one buffer to the other (i.e. the pointers don''t change, you actually copy the pixels from the back buffer to the viewable buffer). I am fairly certain that page flipping refers to ANY type of animation with 2 buffers or more when you make the back buffer visible - regardless of method.

Jason Doucette
www.jasondoucette.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.