DirectX 8 for 2D (colorkey, alpha masking, switching fullscreen)
i need help,
i was using tutorial for DX9, for colorkey using D3DXSprite, the code was lpD3DSprite->Begin(D3DXSPRITE_ALPHABLEND), but in DX8, the Begin Function doesn't accept any parameters...so how do i use color keying ?
i also want to ask how can i achive some thing like alpha masking..i mean like the texture is look fading only on the edge, it's using alpha channel from the picture(32bit bmp or png ?? i tried but failed) or using another texture as the mask and do some blending ? i create my texture like this :
LPDIRECT3DTEXTURE8 lpD3DTexture = NULL;
D3DXCreateTextureFromFileEx(lpD3DDevice, _lpszFileName, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, NULL, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0xff00ff00, NULL, NULL, &lpD3DTexture);
the lasting is how can i make my application switcing windowed and fullscreen back and forth ? because i tried and after i switch mode, i only get blak screen. this is how i switch my screen mode
in my main loop:
if(KeyDown(VK_F2))
{
SafeRelease(lpD3DSprite);
SafeReleaes(lpD3DDevice);
DestroyWindow(g_hWnd);
g_fFullScreen = !g_fFullScreen; //boolean flag for screen mode
myCreateWindow(); //create a popup or overlappedwindowed window
CreateScreen();
}
void CreateScreen()
{
ZeroMemory(&D3DPP, sizeof(D3DPRESENT_PARAMETERS));
if(g_fFullScreen)
{
D3DPP.Windowed = false;
D3DPP.BackBufferWidth = iScreenWidth;
D3DPP.BackBufferHeight = iScreenHeight;
switch(iScreenBPP)
{
case 32 : D3DPP.BackBufferFormat = D3DFMT_X8R8G8B8;
break;
case 16 : D3DPP.BackBufferFormat = D3DFMT_X1R5G5B5;
break;
default : D3DPP.BackBufferFormat = D3DFMT_X8R8G8B8;
}
if(FAILED(lpD3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DPP.BackBufferFormat, D3DPP.BackBufferFormat, false)))
{
MessageBox(NULL, "Failed To Check Direct3D Device Type", CLASSNAME, 0);
return false;
}
}
else
{
D3DDISPLAYMODE D3DDM;
D3DPP.Windowed = true;
D3DPP.hDeviceWindow = g_hWnd;
lpD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &D3DDM);
D3DPP.BackBufferFormat = D3DDM.Format;
}
D3DPP.BackBufferCount = 1;
D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3DPP.EnableAutoDepthStencil = true;
D3DPP.AutoDepthStencilFormat = D3DFMT_D16;
if(FAILED(lpD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DPP.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DPP.AutoDepthStencilFormat)))
{
MessageBox(NULL, "Failed To Check Direct3D Device ZBuffer Format" , CLASSNAME, 0);
return false;
}
if(FAILED(lpD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3DPP, &lpD3DDevice)))
{
MessageBox(NULL, "Failed To Create Direct3D Device", CLASSNAME, 0);
return false;
}
lpD3DDevice->SetRenderState(D3DRS_ZENABLE, true);
lpD3DDevice->SetRenderState(D3DRS_LIGHTING, false);
lpD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
lpD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
lpD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
if(FAILED(D3DXCreateSprite(lpD3DDevice, &lpD3DSprite)))
{
MessageBox(NULL, "Failed To Create Direct3D Sprite", CLASSNAME, 0);
return false;
}
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement