c++directx-9

D3D9 CubeMap texture


I am making a texture cubemap, and the image is output on all 6 sides. How to print a split image on 6 sides? I want to make it without using shaders and I want to know a site where I can study directX Are there any sites you can recommend?

this is my code. ㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁ

struct CUBEVERTEX
{
    float x, y, z;
    float tu, tv;
};
void SkyBox::onInit(float scale)
{
    CUBEVERTEX vertice[] =
    {
   {-1.0f,  1.0f, -1.0f,   0.0f, 0.0f },
   { 1.0f,  1.0f, -1.0f,   1.0f, 0.0f },
   { 1.0f, -1.0f, -1.0f,   1.0f, 1.0f },
   { 1.0f, -1.0f, -1.0f,   1.0f, 1.0f },
   {-1.0f, -1.0f, -1.0f,   0.0f, 1.0f },
   {-1.0f,  1.0f, -1.0f,   0.0f, 0.0f },
                                  
   { 1.0f,  1.0f,  1.0f,   0.0f, 0.0f },
   {-1.0f,  1.0f,  1.0f,   1.0f, 0.0f },
   {-1.0f, -1.0f,  1.0f,   1.0f, 1.0f },
   {-1.0f, -1.0f,  1.0f,   1.0f, 1.0f },
   { 1.0f, -1.0f,  1.0f,   0.0f, 1.0f },
   { 1.0f,  1.0f,  1.0f,   0.0f, 0.0f },
                                  
   {-1.0f, -1.0f, -1.0f,   0.0f, 0.0f },
   { 1.0f, -1.0f, -1.0f,   1.0f, 0.0f },
   { 1.0f, -1.0f,  1.0f,   1.0f, 1.0f },
   { 1.0f, -1.0f,  1.0f,   1.0f, 1.0f },
   {-1.0f, -1.0f,  1.0f,   0.0f, 1.0f },
   {-1.0f, -1.0f, -1.0f,   0.0f, 0.0f },
                                  
   {-1.0f,  1.0f,  1.0f,   0.0f, 0.0f },
   { 1.0f,  1.0f,  1.0f,   1.0f, 0.0f },
   { 1.0f,  1.0f, -1.0f,   1.0f, 1.0f },
   { 1.0f,  1.0f, -1.0f,   1.0f, 1.0f },
   {-1.0f,  1.0f, -1.0f,   0.0f, 1.0f },
   {-1.0f,  1.0f,  1.0f,   0.0f, 0.0f },
                                  
   {-1.0f,  1.0f,  1.0f,   0.0f, 0.0f },
   {-1.0f,  1.0f, -1.0f,   1.0f, 0.0f },
   {-1.0f, -1.0f, -1.0f,   1.0f, 1.0f },
   {-1.0f, -1.0f, -1.0f,   1.0f, 1.0f },
   {-1.0f, -1.0f,  1.0f,   0.0f, 1.0f },
   {-1.0f,  1.0f,  1.0f,   0.0f, 0.0f },
                                  
   { 1.0f,  1.0f, -1.0f,   0.0f, 0.0f },
   { 1.0f,  1.0f,  1.0f,   1.0f, 0.0f },
   { 1.0f, -1.0f,  1.0f,   1.0f, 1.0f },
   { 1.0f, -1.0f,  1.0f,   1.0f, 1.0f },
   { 1.0f, -1.0f, -1.0f,   0.0f, 1.0f },
   { 1.0f,  1.0f, -1.0f,   0.0f, 0.0f }
};
m_pd3dDevice->CreateVertexBuffer(sizeof(vertice), 0, D3DFVF_CUBEVERTEX, D3DPOOL_DEFAULT, 
&m_pVB, 0);

void* pVertice;
m_pVB->Lock(0, sizeof(vertice), &pVertice, 0);
memcpy(pVertice, vertice, sizeof(vertice));
m_pVB->Unlock();
}
void SkyBox::render()
{
D3DXMATRIX matWorld;
D3DXMatrixIdentity(&matWorld);

m_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
m_pd3dDevice->SetTexture(0, texture);

m_pd3dDevice->SetStreamSource(0, m_pVB, 0, sizeof(CUBEVERTEX));
m_pd3dDevice->SetFVF(D3DFVF_CUBEVERTEX);
m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 12);

 }

Solution

  • Rendering a cubemap directly as a skybox in Direct3D 9 is not achievable, especially with a "no shaders" requirement. In Direct3D 9, you need to create the resource as a cubemap to use in environment scenarios, and then create SIX individual 2D textures to render it as a skybox--which means having two copies of each cubemap face in memory.

    In Direct3D 10 or later, you can create a resource and then create two shader resource views: One as a cubemap and another resource as a 2D texture array. This results in one copy of each cubemap face in memory. You can then using shaders render the individual faces of the 2D texture array on a skybox.

    Here's an example implementation using DirectX 12 Skybox that leverages the DirectX Tool Kit for DX12. Same technique will work for Direct3D 11 as long as you require Direct3D Hardware Feature Level 10.0 or better.

    Unless you are specifically using Windows XP, there's no reason you should learn Direct3D 9 at this point. Direct3D 11 is the 'mainstream' graphics API you should look at. See Microsoft Docs and DirectX Tool Kit.