DirectX9 - create cubemap texture from memory?

Started by
4 comments, last by 21st Century Moose 9 years, 9 months ago

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
 }

 }
Advertisement

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;
}

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

you can use dxtex tool to create a cubemap and use D3DXCreateCubeTextureFromFile to load it

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?

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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement