Jump to content
  • Advertisement
Sign in to follow this  
Taha Ansari

DirectX on i-mate PDAL

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

Greetings! I'm running my D3D application on i-mate PDAL. The only back buffer format supported by device is D3DMFMT_R5G6B5. Because of this, I want to know for sure: 1) Alpha blending (even one-bit alpha) is not possible? Loading my texture with D3DMXCreateTextureFromFileEx() with the appropriate color key (0xFFFF00FF) works fine as i can see in the final output of texture that the FF00FF color has been replaced/cleared out with black. But when i perform my render states with Alpha blending i dont get the desired result and the image is drawn with the color key pixels as well. I am preety sure that this is because of the 565 format. I am not sure if i can use AlphaTest as well for my render states because that will also require a back buffer with atleast 1 bit of alpha channel. 2) Does any one know of a good Windows Mobile 5 compatible device that supports back buffer (and texture) format D3DMFMT_A8R8G8B8? If the answer is 'no', then, any WM5 device that has atleast support for one-bit alpha operation (D3DMFMT_A1R5G5B5)? Here's the code I use to load my .bmp:
BOOL CImage::LoadBMP( char* filename, int &fileW, int &fileH, D3DMPOOL eD3DMPool)
{
	BOOL rv = FALSE;
	HRESULT hr = 0;
	int iRet = 0;
	CSTLogFile* log = CSTLogFile::GetLogFile();
	log->Write( L"***LoadBMP()***");
	char str[190]="";
	WCHAR wstr[190]=L"";
	iRet = MultiByteToWideChar( CP_ACP,	0, filename, -1, wstr, 190 );

	Bitmap bmp;
	rv = bmp.loadBMP( filename );
	if ( rv )
	{
		fileW = bmp.width;
		fileH = bmp.height;
	}
	hr = D3DMXCreateTextureFromFileEx( g_pD3DMDevice, wstr, D3DMX_DEFAULT, D3DMX_DEFAULT, 1, 0,
		D3DMFMT_R5G6B5, eD3DMPool, D3DMX_DEFAULT, D3DMX_DEFAULT, 0xffff00ff, 0, 0, &m_pTexture );
	if ( FAILED(hr) )
	{
		log->Write( L"*E: Cannot load BMP" );
		sprintf(str, "* hr = 0x%x",hr );
		log->Write(str);
		return rv;
	}
	else rv = TRUE;
	D3DMSURFACE_DESC desc;
	m_pTexture->GetLevelDesc( 0, &desc );
	sprintf(str,"*M: texW: %d, texH: %d, texFmt: %d", desc.Width, desc.Height, desc.Format );
	log->Write(str);
	sprintf(str,"*M: fileW: %d, fileH: %d", fileW, fileH );
	log->Write(str);
	return rv;
}

Here's the code I use to draw my texture:
void CImage::DrawImage(int x, int y) 
{
	CSTLogFile* log = CSTLogFile::GetLogFile();
	log->Write( L"*DrawImage()");
	if (!img_loaded) return;
	if ( m_pVB == NULL ) return;
	HRESULT hr = 0;

	D3DMXMATRIX matWorld;
	D3DMXMATRIX matWorldOld;
	D3DMXMATRIX matTrans;
	D3DMFORMAT fmt = D3DMFMT_D3DMVALUE_FLOAT;
	g_pD3DMDevice->GetTransform( D3DMTS_WORLD, (D3DMMATRIX*)&matWorldOld, &fmt );

	CustomTextureVertex* pVertices = NULL;
	float fw = (float)imsize_w, fh = (float)imsize_h;
	CustomTextureVertex vertices[4] = 
	{
	{ (float)-fw/2,	(float)-fh/2,		0.0f,	0xffffffff,		0.0f,	0.0f },
	{ (float)fw/2,	(float)-fh/2,		0.0f,	0xffffffff,		1.0f,	0.0f },
	{ (float)-fw/2,	(float)fh/2,		0.0f,	0xffffffff,		0.0f,	1.0f },
	{ (float)fw/2,	(float)fh/2,		0.0f,	0xffffffff,		1.0f,	1.0f },
	};
	hr = m_pVB->Lock( 0,0, (void**)&pVertices, 0 );
	memcpy( pVertices, vertices, sizeof(vertices) );
	hr = m_pVB->Unlock();

	hr = g_pD3DMDevice->SetStreamSource( 0, m_pVB, sizeof(CustomTextureVertex) );
	if ( m_pTexture )
	{
		hr = g_pD3DMDevice->SetTexture( 0, m_pTexture );
	}

	g_pD3DMDevice->SetRenderState(D3DMRS_ALPHABLENDENABLE, TRUE);
	g_pD3DMDevice->SetRenderState(D3DMRS_SRCBLEND,D3DMBLEND_SRCALPHA);
	g_pD3DMDevice->SetRenderState(D3DMRS_DESTBLEND,D3DMBLEND_INVSRCALPHA);

	D3DMXMatrixTranslation( &matTrans, (float)(x + imsize_w/2), (float)(y + imsize_h/2), 0 );
	matWorld =  matTrans * matWorldOld ;
	g_pD3DMDevice->SetTransform( D3DMTS_WORLD, (D3DMMATRIX*)&matWorld, D3DMFMT_D3DMVALUE_FLOAT );

	hr = g_pD3DMDevice->DrawPrimitive( D3DMPT_TRIANGLESTRIP, 0, 2 );
	hr = g_pD3DMDevice->SetTexture( 0, NULL );

	hr = g_pD3DMDevice->SetRenderState(D3DMRS_ALPHABLENDENABLE, FALSE);
	g_pD3DMDevice->SetTransform( D3DMTS_WORLD, (D3DMMATRIX*)&matWorldOld, D3DMFMT_D3DMVALUE_FLOAT );

	log->Write( L"* End Draw Image");

}

Thanks in anticipation!

Share this post


Link to post
Share on other sites
Advertisement
Normally texture formats are less restricted than backbuffer formats. A quick search didn't find any documentation for that device, but you may find that say D3DFMT_A4R4G4B4 is supported for textures which will give you alpha blending.

Share this post


Link to post
Share on other sites
Quote:
Quote by Adam_42
Normally texture formats are less restricted than backbuffer formats. A quick search didn't find any documentation for that device, but you may find that say D3DFMT_A4R4G4B4 is supported for textures which will give you alpha blending.

Thanks for letting me know this!

I borrowed some 'stronger' i-mate from a friend and bench marked it for the textures supported. Along with R5G6B5, I also got A1R5G5B5 format. Also, my samples does alpha blending on that i-mate, and results are much better (no alpha blending resulting in big black region as compared to most of the transparent part appearing transparent with some artifacts around edges).

Now I know I'll have to focus on some other i-mate than the one i was using till now.

Thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!