Archived

This topic is now archived and is closed to further replies.

Problem accessing cube map face textures

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

I''m trying to render a skybox using a cubemap texture. I use D3DXCreateCubeMapTexture and pass it in a .dds cube map file. Ok, when i render my cube I go through a loop rendering each face of the cube. In each iteration of the loop I need to change the texture because each face has a different texture obviously. To access this texture I''m using the GetCubeMapSurface which gives back a IDirect3DSurface pointer. Now my question is how do I get a IDirect3DTexture* from this? I tried using GetContainer(IID_IDirect3DTexture9,&pContainer) but my program crashes at this statement for some reason. Does anyone have any idea what the problem could be? Thanks. Sri

Share this post


Link to post
Share on other sites
You''re right in trying to use GetContainer. That''s the way to do it. Why does it crash? Is there any debug output? I''ve used this function and it works fine for me. Make sure you''re using the debug runtime and have the debug output level at the maximum. Make sure you also check all HRESULT values.

Could you post the snippet of code where you call GetContainer? Maybe that would help narrow down the problem.

neneboricua

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by neneboricua19
You''re right in trying to use GetContainer. That''s the way to do it. Why does it crash? Is there any debug output? I''ve used this function and it works fine for me. Make sure you''re using the debug runtime and have the debug output level at the maximum. Make sure you also check all HRESULT values.

Could you post the snippet of code where you call GetContainer? Maybe that would help narrow down the problem.

neneboricua



Hi,
Thanks for your response. It was late at night so I guess I wasn''t looking at the debug output (duh). Anyway this is what it spits out : Direct3D9: (ERROR) :Unsupported Interface identifier passed to QueryInterface for Cubemap. Is this a problem with the REFIID? I''m using IID_IDirect3DTexture9 so I can''t see why that would have anyting to do with it....

Sri

Share this post


Link to post
Share on other sites
Ok I changed the REFIID from IID_IDirect3DTexture9 to IID_IDirect3DCubeTexture9 and it doesn''t crash anymore. Unfortunately I''m not getting the results I''m hoping for. Is this not the way its supposed to be done? Here''s a code snippet:



if(FAILED(hr = m_pCubeTexture->GetCubeMapSurface((D3DCUBEMAP_FACES)i,0,&pSurface)))
{
DXTraceQuick("Error at GetCubeMapSurface",hr);
return hr;
}
D3DSURFACE_DESC desc;
pSurface->GetDesc(&desc);

hr = pSurface->GetContainer(IID_IDirect3DCubeTexture9, &pContainer);

if (SUCCEEDED(hr)/* && pContainer*/)
{
uint startIndex = 0;
uint minIndex = 0;

pTexture = (LPDIRECT3DTEXTURE9)pContainer;
GetDevice()->SetTexture( 0, pTexture );
GetDevice()->SetFVF( SkyboxVertex::FVF );

GetDevice()->SetStreamSource( 0, m_pVertexBuffer, 0,
D3DXGetFVFVertexSize(SkyboxVertex::FVF) );
GetDevice()->SetIndices( m_pIndexBuffer );

switch((D3DCUBEMAP_FACES)i)
{
case D3DCUBEMAP_FACE_POSITIVE_X:
startIndex = 12;
minIndex = 0;
break;
case D3DCUBEMAP_FACE_NEGATIVE_X:
startIndex = 0;
minIndex = 0;
break;
case D3DCUBEMAP_FACE_POSITIVE_Y:
startIndex = 6;
minIndex = 0;
break;
case D3DCUBEMAP_FACE_NEGATIVE_Y:
startIndex = 18;
minIndex = 0;
break;
case D3DCUBEMAP_FACE_POSITIVE_Z:
startIndex = 24;
minIndex = 0;
break;
case D3DCUBEMAP_FACE_NEGATIVE_Z:
startIndex = 30;
minIndex = 0;
break;
}

GetDevice()->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0,6,startIndex,2);

SAFE_RELEASE(pTexture);


Is there another way to access the cubemap face textures? Thanks for all your help.

Sri

Share this post


Link to post
Share on other sites
Sorry, but I should have read your post more carefully. In general, an environment map (and in your case, a cube map) is mainly used to reflect the world around a specific object.

Since all you''re trying to do is draw a skybox that doesn''t change, it would be much easier to just load the cube map faces into six individual textures instead into a cube map texture. I could be wrong, but to me, what you''re trying to do should work, but actually using a cube map object is a little bit of overkill when you''re extracting the faces of the cube map to render anyway.

neneboricua

Share this post


Link to post
Share on other sites
quote:
Original post by neneboricua19
Sorry, but I should have read your post more carefully. In general, an environment map (and in your case, a cube map) is mainly used to reflect the world around a specific object.

Since all you''re trying to do is draw a skybox that doesn''t change, it would be much easier to just load the cube map faces into six individual textures instead into a cube map texture. I could be wrong, but to me, what you''re trying to do should work, but actually using a cube map object is a little bit of overkill when you''re extracting the faces of the cube map to render anyway.

neneboricua


Well I''m planning on using the same cubemap texture for reflections on objects, I just thought that it would be convenient to be able to load those textures for the skybox from the same cubemap. I guess the only real way to do this is to copy memory from the cube map texture object to another regular texture object which is a bit overkill. Anyway thanks for your help again.

Sri

Share this post


Link to post
Share on other sites