Jump to content
  • Advertisement

Archived

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

sdoherty55

Zen: D3DXLoadSurfaceFromSurface 2D

This topic is 6017 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

Using the Zen code, I displayed a background image behind my 3D scene. However, my framerate jumped from 260+ to 8 in Windowed mode and 60 to 20 in full screen? I am thinking of replacing the code with a texture mapped rectangle defined as D3DFVF_XYZRHW with a large z value. Should the code below be fast, what is my best option for rendering a 2D rectangle in the background. Thanks for the advice Source for Render:
          
D3DXLoadSurfaceFromSurface( g_pBackSurface, 0, 0, g_pBackground, 0, 0, D3DX_FILTER_NONE, 0 );
  

Source for Destroy Device Object:
      
	LoadBitmapToSurface( "ex1Background.bmp", &g_pBackground, m_pd3dDevice );

	// Get a pointer to the back buffer and save it in a global variable

	hr = m_pd3dDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &g_pBackSurface );
	if( FAILED( hr ) ){
		OutputDebugString("...Error: Couldnt get backbuffer\n");
		return E_FAIL;
	}	
  
Fixed Source for InvaildateDeviceObject:
              
	if( g_pBackground ){
		g_pBackground->Release();
		g_pBackground = 0;
	}

	if ( g_pBackSurface ){
		g_pBackSurface->Release();
		g_pBackSurface = 0;
	}
  
  
Source for custom LoadBitmapToSurface Code:
        
// Loads a bitmap to a surface

int LoadBitmapToSurface( char* PathName, LPDIRECT3DSURFACE8* ppSurface, LPDIRECT3DDEVICE8 pDevice )
{
	HRESULT r;
	HBITMAP hBitmap;
	BITMAP Bitmap;
	
	// Load the bitmap first using the GDI to get info about it

	hBitmap = (HBITMAP)LoadImage( NULL, PathName, IMAGE_BITMAP, 0, 0, 
									LR_LOADFROMFILE | LR_CREATEDIBSECTION );
	if( hBitmap == NULL ){
		// The file probably does not exist

		OutputDebugString("...Error: Unable to Load Bitmap\n");
		return E_FAIL;
	}

	// Get information about the object

	GetObject( hBitmap, sizeof( BITMAP ), &Bitmap );
	// Unload the bitmap from memory

	DeleteObject( hBitmap );

	// Now create a surface using the information gained from

	// the previous load

	r = pDevice->CreateImageSurface( Bitmap.bmWidth, 
								Bitmap.bmHeight, D3DFMT_A8R8G8B8, ppSurface );
	if( FAILED( r ) ){
		OutputDebugString("...Error: Unable to create surface for Bitmap\n");
		return E_FAIL;
	}

	// Load the image again, this time using Direct3D to load

	// it directly to the new surface

	r = D3DXLoadSurfaceFromFile( *ppSurface, NULL, NULL, PathName, 
									NULL, D3DX_FILTER_NONE, 0, NULL );
	if( FAILED( r ) ){
		OutputDebugString("...Error: Unable to load file to surface\n");
		return E_FAIL;
	}

	return S_OK;
}
          
Edited by - sdoherty55 on December 28, 2001 11:44:43 AM

Share this post


Link to post
Share on other sites
Advertisement
My frame rate went from 8 to 64 (windowed) and 20 to 60 (full screen) by replacing the Zen code shown above with the following custom code:

Is this as good as it gets, or is there a faster way?



  
ICESPRITE_VERTEX cvIceSpriteVertices[] =
{
{ 0.0f, 767.0f, 1000.0f, 1.0f, 0.0f, 1.0f,}, // x, y, z, a, tu, tv {v1}

{ 0.0f, 0.0f, 1000.0f, 1.0f, 0.0f, 0.0f,}, // x, y, z, a, tu, tv {v2}

{ 1023.0f, 767.0f, 1000.0f, 1.0f, 1.0f, 1.0f,}, // x, y, z, a, tu, tv {v3}

{ 1023.0f, 0.0f, 1000.0f, 1.0f, 1.0f, 0.0f} // x, y, z, a, tu, tv {v4}

};


// --------------------------------------------------------------------------------------

// IceSprite Constructor

// --------------------------------------------------------------------------------------

CIceSprite::CIceSprite(){
;
}

// --------------------------------------------------------------------------------------

// IceSprite Destructor

// --------------------------------------------------------------------------------------

CIceSprite::~CIceSprite(){

;

}



// --------------------------------------------------------------------------------------

// InitDeviceObject

// --------------------------------------------------------------------------------------

HRESULT CIceSprite::InitDeviceObject(LPDIRECT3DDEVICE8 pd3dDevice){

// Load the texture for the background image

if( FAILED( D3DUtil_CreateTexture( pd3dDevice, _T("ex1Background.bmp"), &m_pIceSpriteTexture) ) ){
return D3DAPPERR_MEDIANOTFOUND;
}

return D3D_OK;
}


// --------------------------------------------------------------------------------------

// InvalidateDeviceObject

// --------------------------------------------------------------------------------------

HRESULT CIceSprite::InvalidateDeviceObject(){

SAFE_RELEASE( m_pVB );

return D3D_OK;
}


// --------------------------------------------------------------------------------------

// DeleteDeviceObjects

// --------------------------------------------------------------------------------------

HRESULT CIceSprite::DeleteDeviceObjects(){

SAFE_RELEASE( m_pIceSpriteTexture );

return D3D_OK;
}


// --------------------------------------------------------------------------------------

// Render

// --------------------------------------------------------------------------------------

HRESULT CIceSprite::Render(LPDIRECT3DDEVICE8 pd3dDevice){
pd3dDevice->SetTexture( 0, m_pIceSpriteTexture );

pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(ICESPRITE_VERTEX) );
pd3dDevice->SetVertexShader( D3DFVF_ICESPRITE_VERTEX );
pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );


return D3D_OK;
}

// --------------------------------------------------------------------------------------

// RestoreDeviceObjects

// --------------------------------------------------------------------------------------

HRESULT CIceSprite::RestoreDeviceObject(LPDIRECT3DDEVICE8 pd3dDevice){

m_dwSizeofVertices = sizeof(cvIceSpriteVertices);

// Create the vertex buffer

if( FAILED( pd3dDevice->CreateVertexBuffer( m_dwSizeofVertices,
0, D3DFVF_ICESPRITE_VERTEX,
D3DPOOL_SYSTEMMEM, &m_pVB ) ) )
return E_FAIL;


VOID* pVertices;
if( FAILED( m_pVB->Lock( 0, m_dwSizeofVertices, (BYTE**)&pVertices, 0 ) ) ){
return E_FAIL;
}

memcpy( pVertices, cvIceSpriteVertices, m_dwSizeofVertices);
m_pVB->Unlock();

return D3D_OK;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!