Problem accessing cube map face textures

Started by
5 comments, last by hoopjones 20 years, 6 months ago
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
Advertisement
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
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
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
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
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
One way to do it would be to assign the correct s,t,r coordinate to each vertex in you skybox and render using the whole cubemap directly as a texture.

This topic is closed to new replies.

Advertisement