2 Replies - 970 Views - Last Post: 15 December 2009 - 01:20 PM Rate Topic: -----

#1 FrozenSnake  Icon User is offline

  • En man från Sverige!

Reputation: 122
  • View blog
  • Posts: 995
  • Joined: 30-July 08

Problem with transparent tiles (not transparent)

Posted 15 December 2009 - 12:11 PM

I am trying to get the color (in this case black) to be transparent. I am going to change it later if I find the correct one for ff00ff but for now black works.
Anyway this is the result: http://data.fuskbugg...01/--sample.jpg

void DxManager::Render()
{
	IDirect3DSurface9* pSurface;
	RECT destRect;

	if(!pd3dDevice)
		return;
	pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
	pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &BackBuffer);

	textures.push_back(this->getSurfaceFromBitmap("./gfx/1001.bmp"));
	textures.push_back(this->getSurfaceFromBitmap("./gfx/1002.bmp"));
	textures.push_back(this->getSurfaceFromBitmap("./gfx/1003.bmp"));
	textures.push_back(this->getSurfaceFromBitmap("./gfx/1004.bmp"));

	pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	pd3dDevice->SetRenderState(D3DRS_ALPHAREF, 10);
	pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

	pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	for(int x = 0; x != 24; ++x)
	{
		for(int y = 0; y != 24; ++y)
		{
			int index = groundMap[y][x];
			destRect.left   = x * S_WIDTH;				
			destRect.top	= y * S_HEIGHT;				
			destRect.bottom = destRect.top + S_HEIGHT;
			destRect.right  = destRect.left + S_WIDTH;		

			pSurface = textures[index];
			hResult = pd3dDevice->StretchRect(pSurface, NULL, BackBuffer, &destRect, D3DTEXF_NONE);
		}
	}
	if(hResult != D3D_OK)
	{
		MessageBox(NULL, "D3D är hjuk fixa!", "Hjukling", MB_OK);
		exit(1);
		return;
	}
	pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false); 
	pd3dDevice->Present(NULL, NULL, NULL, NULL);
}


IDirect3DSurface9* DxManager::getSurfaceFromBitmap(std::string filename)
{
	surface = NULL;
	hResult = D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo);

	if (FAILED(hResult))
		return NULL;

	hResult = pd3dDevice->CreateOffscreenPlainSurface(imageInfo.Width, imageInfo.Height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
	if (FAILED(hResult))
		return NULL;

	hResult = D3DXLoadSurfaceFromFile(surface, NULL, NULL, filename.c_str(), NULL, D3DX_DEFAULT, 0, NULL);
	if (FAILED(hResult))
		return NULL;

	return surface;
}


What have I missed?

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with transparent tiles (not transparent)

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: Problem with transparent tiles (not transparent)

Posted 15 December 2009 - 01:09 PM

It is my understanding that Direct X doesn't have native support for color keying and instead you can use a seperate alpha channel for this sort of thing, but you can do it if you want to and you need to use this function.

D3DXCreateTextureFromFileEx(m_pd3dDevice,
							"test.bmp",
							D3DX_DEFAULT,
							D3DX_DEFAULT,
							1,
							0,
							D3DFMT_UNKNOWN,
							D3DPOOL_DEFAULT,
							D3DX_FILTER_LINEAR,
							D3DX_FILTER_LINEAR,
ColorKey ->		  0xffff00ff,
							NULL,
							NULL,
							&m_texture);



Hope that helps :)
Was This Post Helpful? 0
  • +
  • -

#3 FrozenSnake  Icon User is offline

  • En man från Sverige!

Reputation: 122
  • View blog
  • Posts: 995
  • Joined: 30-July 08

Re: Problem with transparent tiles (not transparent)

Posted 15 December 2009 - 01:20 PM

View Poststayscrisp, on 15 Dec, 2009 - 08:09 PM, said:

It is my understanding that Direct X doesn't have native support for color keying and instead you can use a seperate alpha channel for this sort of thing, but you can do it if you want to and you need to use this function.

D3DXCreateTextureFromFileEx(m_pd3dDevice,
							"test.bmp",
							D3DX_DEFAULT,
							D3DX_DEFAULT,
							1,
							0,
							D3DFMT_UNKNOWN,
							D3DPOOL_DEFAULT,
							D3DX_FILTER_LINEAR,
							D3DX_FILTER_LINEAR,
ColorKey ->		  0xffff00ff,
							NULL,
							NULL,
							&m_texture);



Hope that helps :)


Oh thanks, gona take a look might take a while but I post a reply if I get anywhere :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1