This topic is now archived and is closed to further replies.

Double Buffering help

This topic is 5150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to add code for a back buffer to my 2D renderer. I understand all the theory behind back buffers etc, it''s just the implementation is eluding me. render:
    DWORD clearcolour = D3DCOLOR_XRGB(64,128,255);
    m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET, clearcolour, 1.0f, 0L );

    if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
	static float x=0;

	static int tx=0;
	static int ty=0;
	sprintf(buf, "LHS: %d,  Offset: %d,  Pos_x: %d,  Pos_x%32: %d", lhs, offset, (int)pos_x, (int)pos_x%32);
	TextOut(hdc, lhs+20, 50, buf, strlen(buf));

	// draw ground

	for(int gt = lhs; gt < lhs+26; gt++){
        	CHECK( DrawBitmap( 0, (32*(gt-lhs))-offset, m_dwCreationHeight-16, 32*tx, 32*ground[gt], 32, 32,0) );


	CHECK( DrawBitmap( 0, /*10+x*3.0f, 100+pt.y,*/pos_x, pos_y, 0, 0, 32, 32,0) );

    return S_OK;
The draw bitmap function is:
DrawBitmap(int ID, int x, int y, int left, int top, int width, int height )
    if( (g_VB[ID] == NULL) || (g_Tex[ID] == NULL) )
	return S_OK;

    CHECK( g_VB[ID]->Lock( 0, 0, (void**)&v, 0 ) );
    v[0].p = D3DXVECTOR4( (float)x,            (float)y+height, 0.0f, 1.0f );
    v[1].p = D3DXVECTOR4( (float)x,            (float)y,              0.0f, 1.0f );
    v[2].p = D3DXVECTOR4( (float)x+width, (float)y+height,  0.0f, 1.0f );
    v[3].p = D3DXVECTOR4( (float)x+width, (float)y,              0.0f, 1.0f );
    float tw = (float)g_TexDesc[ID].Width;
    float th = (float)g_TexDesc[ID].Height;
    v[0].tu = ((float)left)/tw; v[0].tv = ((float)top+height)/th;
    v[1].tu = ((float)left)/tw; v[1].tv = ((float)top)/th;
    v[2].tu = ((float)left+width)/tw; v[2].tv = ((float)top+height)/th;
    v[3].tu = ((float)left+width)/tw; v[3].tv = ((float)top)/th;
    m_pd3dDevice->SetTexture( 0, g_Tex[ID] );
    m_pd3dDevice->SetFVF( D3DFVF_VERTEXFOR2D );
		0, g_VB[ID], 0, sizeof(VERTEXFOR2D) );
    m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
    m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
    m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

    m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
    m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
    return S_OK;
How would I adapt that to draw to a back buffer & then flip. Can I write to a surface/backbuffer in the same way as I''m writing to m_pd3dDevice? I''ve picked up that there is stuff for backbuffers in DirectX but I''ve found MS''s help to be fairly useless on the subject. Any help/suggestions or even being pointed towards a good tutorial would help. thanks

Share this post

Link to post
Share on other sites