Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


annoying problem trying to create a dynamic texture in Direct3D9


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Enerjak   Members   -  Reputation: 233

Like
0Likes
Like

Posted 21 June 2012 - 10:59 PM

Ok, for SOME REASON, my creation of the texture isn't working as it says i specified a wrong format for it;

here is the create resources function

bool VideoDemo::createResources()
{
HRESULT hr;
hr = m_Direct3D->CheckDeviceFormat(0,D3DDEVTYPE_HAL,m_DispMode.Format,D3DUSAGE_DYNAMIC,D3DRTYPE_TEXTURE,D3DFMT_X8B8G8R8);
if(FAILED(hr))
{
  const char* err = DXGetErrorDescriptionA(hr);
  MessageBoxA(NULL,(LPCSTR)err,NULL,MB_OK);
}
hr = m_Direct3DDevice->CreateTexture(512,512,1,D3DUSAGE_DYNAMIC,D3DFMT_A8B8G8R8,D3DPOOL_DEFAULT,&m_pTexture,NULL);
if(FAILED(hr))
{
  const char* err = DXGetErrorDescriptionA(hr);
  MessageBoxA(NULL,(LPCSTR)err,NULL,MB_OK);
}
hr = m_pTexture->LockRect(0,&this->m_Rect,NULL,D3DLOCK_DISCARD);
if(FAILED(hr))
{
  const char* err = DXGetErrorDescriptionA(hr);
  MessageBoxA(NULL,(LPCSTR)err,"",MB_OK);
}
for(int x = 0; x < this->m_pTexture->Width; x++)
{
  for(int y = 0; y < this->m_pTexture->Height; y++)
  {
   DWORD* imageData = reinterpret_cast<DWORD*>(&m_Rect.pBits);
   int index = x * m_Rect.Pitch / 4 * y;
   imageData[index++] = 0xFF000000;
   imageData[index++ / 2] = 0xFF00FF00;
  }
}
m_pTexture->UnlockRect(0);
hr = D3DXSaveTextureToFileA("Image.png",D3DXIFF_PNG,m_pTexture,NULL);
if(FAILED(hr))
{
  const char* err = DXGetErrorDescriptionA(hr);
  MessageBoxA(NULL,(LPCSTR)err,"",MB_OK);
}
return true;
}

not really sure WHY it does this.

Sponsor:

#2 kubera   Members   -  Reputation: 946

Like
0Likes
Like

Posted 22 June 2012 - 12:39 AM

Maybe you would consider calling:
  • D3DXFillTextureTX
  • D3DXFillTexture


#3 mhagain   Crossbones+   -  Reputation: 8141

Like
0Likes
Like

Posted 22 June 2012 - 03:05 AM

Try D3DFMT_A8R8B8B8 instead of D3DFMT_A8B8G8R8 (i.e. ARGB instead of ABGR).

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 Enerjak   Members   -  Reputation: 233

Like
0Likes
Like

Posted 28 June 2012 - 08:53 PM

well, that worked (switching from A8B and all) i didn't even notice i had that :-D isn't that A8B8G8R8 for openGL? just wondering

#5 mhagain   Crossbones+   -  Reputation: 8141

Like
1Likes
Like

Posted 29 June 2012 - 05:54 AM

Not really. Internally the GPU will store textures in the same format, irrespecive of what you specify in the API (for this purposes of this discussion it's assumed that "format" refers to 32-bit 4-component textures, of which the fourth component may be alpha or unused). So far as this internal GPU storage is concerned there is no difference between D3D or OpenGL - it's just a chunk of data that's accessed by the hardware. Where API differences do come in is with respect to how you specify the texture format CPU-side, which will affect transfers of texture data from system RAM to video RAM. OpenGL allows for fairly flexible specification of how data is stored in system RAM, but the tradeoff is that transfers to GPU RAM may need to go through an additional software stage to convert this to the GPU-side format and layout. With D3D the system RAM format and layout must match the GPU-side format and layout. This of course will only be relevant for initial specification of all textures and for subsequent updates of dynamic textures. So far as all other usages are concerned it's not something that you need to be concerned about.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS