Skip to main content
GameDev.net gamedev.net
🔒 Locked

alpha blending / D3DFORMAT

Started by sadnessnpeace Aug 2, 2002 at 10:43 AM 1 replies 400+ views
Original Post
sadnessnpeace
sadnessnpeace
i have a very odd problem that i really hope hasn''t already been addressed in this forum. my apologies if it has been. first of all, i''m using code and example programs from tanstaafl''s "2d in direct3d" book. using example program 1_3 (i think), i listed my enumerated display modes, resulting in around 24 different modes. however, not one of them utilized a pixel format with an alpha channel; the closest i could find to D3DFMT_A8R8G8B8 was D3DFMT_X8R8G8B8. this confused the hell out of me, because the example prog using alpha blending (14_1, i think) worked perfectly -- a contradiction, i think. in any case, i''m using almost exactly the same routines to load a texture. i really can''t find any differences between my code and his. however, when i display a textured primitive on the screen using vertices that don''t have full alpha (on top of another primitive, of course), it''s fully opaque. if i turn off texturing and simply use vertex colors to color a primitive, alpha blending seems to work just fine. anyone have any ideas about what i''m doing wrong here? i might not have been entirely clear in my description, so ask any questions you need.
~brian
Evil Bill
Evil Bill
For the first problem: You''re enumerating display modes; the format of the backbuffer. The backbuffer never has an alpha channel. You want to enumerate texture formats. Here''s the code i use:

  
const DWORD dwNumFormats = 9;
D3DFORMAT theFormats[dwNumFormats] =
{
D3DFMT_A8R8G8B8,
D3DFMT_A4R4G4B4,
D3DFMT_A1R5G5B5,
D3DFMT_X8R8G8B8,
D3DFMT_R8G8B8,
D3DFMT_R5G6B5,
D3DFMT_X1R5G5B5,
D3DFMT_X4R4G4B4,
D3DFMT_A8R3G3B2
};
BYTE theDepths[dwNumFormats] = {4,2,2,4,3,2,2,2,2};
BOOL bGotOne = FALSE;

// Get Appropriate Texture Format //

for(DWORD i=0; i<dwNumFormats; i++)
{
if(SUCCEEDED(m_pD3D->CheckDeviceFormat(m_nDriver, D3DDEVTYPE_HAL, pCurrentMode->Format, 0, D3DRTYPE_TEXTURE, theFormats[i])))
{
Log(INFO,"Texture Format %d (%s) is compatible with render target!\n",i,FormatToString(theFormats[i]));
m_fmtTextures = theFormats[i];
m_dwTextureBytes = theDepths[i];
bGotOne = TRUE;
break;
}
}
if(!bGotOne)
{
RELEASE(m_pD3D);
Log(ERR,"CD3DApp::Create() Failed to find suitable texture format.\n");
return FALSE;
}
}

It should be fairly obvious what the variables are, but if not, post here or e-mail me and i''ll explain further.

HTH, Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
sadnessnpeace
sadnessnpeace
that makes perfect sense. thanks for the input. maybe i can fix the texturing problem too.
~brian

Topic Locked

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

Sign in to reply to this topic.