Sign in to follow this  
fread

DirectX9 - create cubemap texture from memory?

Recommended Posts

Hiho I have six 512x512 RGBA images loaded in memory. I want to create a DirectX9 cubemap Here's my code: why is it failing?

 IDirect3DCubeTexture9 *tex;
 HRESULT hr = pDev->CreateCubeTexture(512, 1, D3DUSAGE_WRITEONLY, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, 0);
 if(FAILED(hr)) {
        // i think im ggetting error here 
          // ERRROR output
}
 for(int i = 0; i < 6; i++)
 { 
LPDIRECT3DSURFACE9 face; hr = tex->GetCubeMapSurface(_D3DCUBEMAP_FACES(D3DCUBEMAP_FACE_POSITIVE_X+i), 0, &face);
 if(FAILED(hr)) 
{
        // ERRROR output 
}
 D3DLOCKED_RECT rect;
 hr = face->LockRect(&rect, 0, 0);
 if (FAILED(hr))
 { 
          // ERRROR output
 } 
CopyRGBAPixelsTo(i,rect.pBits); 
hr = face->UnlockRect(); 
if (FAILED(hr))
 { 
          // ERRROR output
 }

 }
Edited by fread

Share this post


Link to post
Share on other sites

Where does the error occur, and what is the error code?

 

You can determine the error as follows (I can;t remember whether the header is dxerr9.h or dxerr.h):

#include <dxerr.h> // dxerr9.h maybe
// also add dxerr.lib or dxerr9.lib to the linker inputs
...
HRESULT hr = pDev->Create..();
if( FAILED(hr) )
{
   MessageBox(NULL, DXGetErrorDescription( hr ), "Failed some function call..", MB_OK);
   return false;
}

Share this post


Link to post
Share on other sites

http://msdn.microsoft.com/en-us/library/windows/desktop/bb172625%28v=vs.85%29.aspx

 

This page only speaks of buffers, but we may assume that it's valid for textures too: D3DUSAGE_WRITEONLY is only valid for D3DPOOL_DEFAULT.

 

You can continue using the managed pool but just specify a usage of 0 and everything will continue to work.

Share this post


Link to post
Share on other sites

thank you guys, i managed to fix it, but when rendering cubemap with shaders (texCube stuff) the corners of my skybox are "cut off". They are black, while the rest of cubemap is drawn valid. What's wrong?

Share this post


Link to post
Share on other sites

It sounds as though the skybox corners are going beyond your far clipping plane.  One way to resolve this is to set up a new viewport for your skybox, with MinZ and MaxZ both set to 1, then draw your skybox as a 10x10x10 cube (you may need to make this slightly larger depending on your near clipping plane) centered on the viewpoint.  Restore the old viewport when done.

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