Sign in to follow this  
j_7h0r

cube maps with directx 9

Recommended Posts

Hello there, i'm presently trying to write a piece of code to implement a simple environment mapping shader but i experience some problems with directX even before the shader is called. Actually my problem is quite precise. I follow the instructions given on the MSDN site to code a cube map http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/creating_cubic_environment_map_surfaces.asp but there are some errors in their code and i can't figure out a way to solve them. First i Init the device, the LPDIRECT3DCUBETEXTURE9 m_pCubeMap then i save my transformation matrices, then i store the current back buffer and z-buffer etc. then i loop through my 6 cube map faces in order to render them one by one but there comes the problem. On the MSDN site, this is what they tell to do: // Get pointer to surface in order to render to it LPDIRECT3DSURFACE9 pFace; pCubeMap->GetCubeMapSurface((D3DCUBEMAP_FACES)i, 0, &pFace); d3dDevice->SetRenderTarget (pFace , pZBuffer); //pZBuffer is also a LPDIRECT3DSURFACE9 SAFE_RELEASE(pFace); d3dDevice->BeginScene(); // Render scene here ... d3dDevice->EndScene(); } // Change the render target back to the main back buffer. d3dDevice->SetRenderTarget(pBackBuffer, pZBuffer); //pBackBuffer is also a LPDIRECT3DSURFACE9 The problem comes with the call to "d3dDevice->SetRenderTarget(pFace , pZBuffer);" and "d3dDevice->SetRenderTarget(pBackBuffer, pZBuffer);" It simply doesn't compile. The Visual C++ .Net compiler says: dx9_cg_simple.cpp(522): error C2664: 'IDirect3DDevice9::SetRenderTarget' : cannot convert parameter 1 from 'LPDIRECT3DSURFACE9' to 'DWORD'... In deed, the first parameter is a LPDIRECT3DSURFACE9 (pointer to IDirect3DSurface9) and not a DWORD... so i'm stuck and i only have 2 days left to complete this task... Can somebody help me please...!!! Thank you in advance... Jon. K.

Share this post


Link to post
Share on other sites
You're looking at DX8 code.

In DX8, SetRenderTarget took two arguments, the render target and the depth target. It also set the viewport to cover the entire render target.

In DX9, SetRenderTarget takes two arguments, the render target index, and the render target. The index is usually 0. The point of the index is for MRT (multiple render targets), where your shader can write to several buffers at the same time. SetDepthStencilSurface is now used to set the depth surface. The viewport should be set any time you change the render target (even if it shouldn't have changed... set it, or dx and/or driver bugs will plague your soul).

Share this post


Link to post
Share on other sites
Thanks a lot for the answer. I appreciate...
Since you seem to know about this stuff, i will ask you one more question.

I want to set my skybox as the cube map and then reflect it on my object to implement the environment mapping in the shader.

Now i'd like to know if by doing:

D3DXCreateCubeTextureFromFile(g_pd3dDevice, "cubemap.dds", &m_pCubeMap);
m_pCubeMap->GetCubeMapSurface(D3DCUBEMAP_FACE_POSITIVE_Y, 0, &pFace2);

and all the rest that is said on the msdn site (the inits and the for loop to render the 6 faces of my cube map), am i suppose to see the cube map appearing on the screen as if i would have coded a skybox or do i still have to code the skybox as usual?

And by the way, do you know any good site that explains well all the DX setups and other setups that have to be done before calling the shader to do the environment map effects (vertex format setup, inverting the transformation matrices etc)?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this