0
所以我在DirectX 9編碼,每當我把一個精靈放入2D世界。在精靈圖像p周圍出現白色的「光暈」。我使用的是PNG,而精靈背後的背景是透明的。我也嘗試使用粉紅色背景。似乎光環只出現在像素的直線上,但只出現在一些邊緣上。任何幫助是極大的讚賞!使用DirectX 9;雪碧反鋸齒光暈
m_d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface
D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information
ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear out the struct for use
d3dpp.Windowed = windowed; // is program fullscreen, not windowed?
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
d3dpp.BackBufferWidth = screenWidth; // set the width of the buffer
d3dpp.BackBufferHeight = screenHeight; // set the height of the buffer
d3dpp.EnableAutoDepthStencil = TRUE; // automatically run the z-buffer for us
d3dpp.AutoDepthStencilFormat = D3DFMT_D16; // 16-bit pixel format for the z-buffer
// create a device class using this information and the info from the d3dpp stuct
m_d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&m_d3ddev);
D3DXCreateSprite(m_d3ddev, &m_d3dspt); // create the Direct3D Sprite object
LPDIRECT3DTEXTURE9 texture;
D3DXCreateTextureFromFileEx(m_d3ddev, "DC.png", D3DX_DEFAULT, D3DX_DEFAULT,
D3DX_DEFAULT, NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255), NULL, NULL, &texture);
m_d3ddev->BeginScene();
m_d3dspt->Begin(D3DXSPRITE_ALPHABLEND); // begin sprite drawing with transparency
D3DXVECTOR3 center(0.0f, 0.0f, 0.0f), position((appropriate x), (appropriate y), 1);
m_d3dspt->Draw(texture, NULL, ¢er, &position, D3DCOLOR_ARGB(255, 255, 255, 255));
m_d3dspt->End(); // end sprite drawing
m_d3ddev->EndScene();
m_d3ddev->Present(NULL, NULL, NULL, NULL);
感謝 彼得
感謝您的幫助!嗯,但是什麼是精靈圖譜? – Peter 2011-06-15 01:01:50
另外,通過紋理座標來表示它在屏幕上繪製的x,y座標嗎?我認爲紋理座標是紋理化3D網格時使用的。 – Peter 2011-06-15 01:04:41
@Peter:雪碧圖紋是在一個紋理上製作多個精靈,然後渲染該紋理的一部分的地方。它速度更快,但將texcoords錯誤會產生有趣的結果。紋理座標用於渲染任何紋理 - 2D或3D,其中0,0是紋理的左上角(我認爲),1,1是右下角。如果您使用的是ID3DXSprite,那麼它會爲您執行此轉換,但您仍需指定正確的值。如果您發佈了您的問題的圖片,並且可能使用了一些基本的渲染代碼,它將幫助我診斷問題。 – Puppy 2011-06-15 01:07:58