7 Replies - 1228 Views - Last Post: 21 November 2012 - 01:13 PM Rate Topic: -----

#1 vince0656  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-November 12

Issue with D3DXLoadSurfaceFromFile() in loading pngs

Posted 19 November 2012 - 07:31 AM

Hello there,

I'm pulling out my hair here trying to understand what I am doing wrong but I am having issues in loading and rendering pngs using D3DXLoadSurfaceFromFile() using the D3D9 API. They load but not correctly because they seem to be corrupt after rendering when the files are OK. A good example is from the files attached. The one on the left is loaded into a surface and being rendered using StrechRect(). However as you can see from the original on the right, its not doing it correctly and that not to mention that the alpha channel is being used around the character. Therefore, I should only be seeing the cleared back buffer and the silhouette of the character but I'm not. I don't know if there is anything I'm not doing but here is my initialisation and render code from the sprite class:

void MySprite::Initialise(LPCTSTR fileName)
{
	//Create the offscreen surface to load the image
	hResult = CreateOffscreenPlainSurface(
		787,
		428,
		D3DFMT_A2R10G10B10,
		D3DPOOL_DEFAULT,
		&m_bitmap, // a previously defined offscreen surface
		NULL);
		

		if( fileName != L"" )
		{
			hResult = D3DXLoadSurfaceFromFile(
				m_bitmap,
				NULL,
				NULL,
				fileName,
				NULL,
				D3DX_DEFAULT,
				0,
				NULL );
		}
	}
}

void MySprite::Render(const RECT& destRect)
{
	hResult = m_pD3Ddevice->StretchRect(
		m_bitmap,
		NULL,
		m_backBuffer,
		&destRect,
		D3DTEXF_NONE);
} 


I don't know if it is the format of the offscreen surface I'm using or what. BTW: the screen is being cleared but that is being called elsewhere. It is being cleared to D3DCOLOR_XRGB(255,100,0).

Also, I was playing around with using the system memory pool (D3DPOOL_SYSTEMMEM) for offscreen surface to be created to but that fails miserably. I even tried creating a REF device instead of using the HAL but to no avail. Any ideas on that?

Attached image(s)

  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Issue with D3DXLoadSurfaceFromFile() in loading pngs

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Issue with D3DXLoadSurfaceFromFile() in loading pngs

Posted 19 November 2012 - 09:22 AM

It's clear that your code is expecting a file with different attributes to the one supplied. I'm looking at this on my iPhone, but first of all do the x and y dimensions of the image file match those expected?
Was This Post Helpful? 0
  • +
  • -

#3 vince0656  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-November 12

Re: Issue with D3DXLoadSurfaceFromFile() in loading pngs

Posted 19 November 2012 - 10:12 AM

View PostButchDean, on 19 November 2012 - 09:22 AM, said:

It's clear that your code is expecting a file with different attributes to the one supplied. I'm looking at this on my iPhone, but first of all do the x and y dimensions of the image file match those expected?


No they don't but even when I adjust the surface to the correct resolution it doesn't fix the issue. I get the same weird lines/.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Issue with D3DXLoadSurfaceFromFile() in loading pngs

Posted 19 November 2012 - 11:27 AM

Yes I am right, your avatar is stretched. Adjusting the surface does not mean it will match the surface. You need to make sure that the image is being being read correctly, which it isn't.
Was This Post Helpful? 0
  • +
  • -

#5 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Issue with D3DXLoadSurfaceFromFile() in loading pngs

Posted 19 November 2012 - 01:14 PM

You are likely not using StretchRect() correctly either. You have default values everywhere.
Was This Post Helpful? 0
  • +
  • -

#6 vince0656  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-November 12

Re: Issue with D3DXLoadSurfaceFromFile() in loading pngs

Posted 19 November 2012 - 02:14 PM

View PostButchDean, on 19 November 2012 - 01:14 PM, said:

You are likely not using StretchRect() correctly either. You have default values everywhere.

Yeah I have been using default values to see where I get. I am new to D3D9 so for the moment I am happy that something is rendering but I need to probably change an argument or two in D3DXLoadSurfaceFromFile() and or StretchRect(). Though, the only thing I can see changing in StrechRect() is the last flag.
Was This Post Helpful? 0
  • +
  • -

#7 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Issue with D3DXLoadSurfaceFromFile() in loading pngs

Posted 20 November 2012 - 03:22 PM

Have you read the docs for those functions? If not, you need to.
Was This Post Helpful? 0
  • +
  • -

#8 vince0656  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-November 12

Re: Issue with D3DXLoadSurfaceFromFile() in loading pngs

Posted 21 November 2012 - 01:13 PM

I'll have a look at them but I think its due to the fact that I don't have alpha blend enabled. However, I tried this and its not working:

// Enable alpha blending.
lpD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,
                            TRUE);
 
// Set the source blend state.
lpD3DDevice->SetRenderState(D3DRS_SRCBLEND,
                          D3DBLEND_SRCCOLOR);
 
// Set the destination blend state.
lpD3DDevice->SetRenderState(D3DRS_DESTBLEND,
                            D3DBLEND_INVSRCCOLOR);

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1