• Advertisement
Sign in to follow this  

How do I get D3DXLoadSurfaceFromFile to have trancparentcy?

This topic is 2892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The issue is that my program draws a black box around the bmp when I want it not to draw anything that is solid green or 0,255,0. What do I need to add or change to get that to work?

     //get width and height from bitmap file
     D3DXIMAGE_INFO info;
     HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info);
     if (result != D3D_OK) return NULL;

     //create surface
     result = d3ddev->CreateOffscreenPlainSurface(
          info.Width,         //width of the surface
          info.Height,        //height of the surface
          D3DFMT_X8R8G8B8,    //surface format
          D3DPOOL_DEFAULT,    //memory pool to use
          &image,             //pointer to the surface
          NULL);              //reserved (always NULL)

      if (result != D3D_OK) return NULL;

      //load surface from file into newly created surface
      result = D3DXLoadSurfaceFromFile(
          image,                  //destination surface
          NULL,                   //destination palette
          NULL,                   //destination rectangle
          filename.c_str(),       //source filename
          NULL,                   //source rectangle
          D3DX_DEFAULT,           //controls how image is filtered
          D3DCOLOR_XRGB(0,255,0),   //for transparency (0 for none)
          NULL);                  //source image info (usually NULL)

      //make sure file was loaded okay
      if (result != D3D_OK) return NULL;

      return image;

Share this post

Link to post
Share on other sites
Try creating a D3DFMT_A8R8G8B8 image instead - you need an alpha channel to get transparency. Also make sure the alpha blending render states are set correctly when you draw it.

Share this post

Link to post
Share on other sites
Thanks I will try that as soon as I can get my program to compile.

the issue is

1>MyDirectX.obj : error LNK2001: unresolved external symbol "struct ID3DXSprite * spriteobj" (?spriteobj@@3PAUID3DXSprite@@A)
1>MyGame.obj : error LNK2001: unresolved external symbol "struct ID3DXSprite * spriteobj" (?spriteobj@@3PAUID3DXSprite@@A)

this is what I have

#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib,"d3dxof.lib")
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9d.lib")
#pragma comment(lib,"dinput8.lib")
#pragma comment(lib,"xinput.lib")

#include <d3dx9.h>
#include <windows.h>
#include <d3d9.h>
#include <dinput.h>
#include <xinput.h>
#include <ctime>
#include <iostream>
#include <iomanip>

I also have the folders set right becuase it was working tell I tryed adding LPD3DXSPRITE to the project and now for some reason its not finding the lib or I am starting it wrong

extern LPD3DXSPRITE spriteobj;

D3DXCreateSprite(d3ddev, &spriteobj);

D3DXVECTOR3 pos2( bomb.x, bomb.y, 0);
spriteobj->Draw( bomb_surf,NULL ,NULL, &pos2,

if (spriteobj) spriteobj->Release();

other then that I have no idea

I am using vc++ 2010
and windows 7 64bit

Share this post

Link to post
Share on other sites
You have:
extern LPD3DXSPRITE spriteobj;
Which tells the compiler that a LPD3DXSPRITE named spriteobj exists, but you don't declare it anywhere. You need to add this in one .cpp file at global scope:
LPD3DXSPRITE spriteobj = NULL;

Also, about the original problem: If you want alpha, you almost certainly want to use textures rather than surfaces, especially if you're using ID3DXSprite - in which case you should be using D3DXCreateTextureFromFileEx instead of D3DXLoadSurfaceFromFile.

Share this post

Link to post
Share on other sites
thanks that was what the issue was.

Its working now but its going way to fast and I am tring to figure a way to slow the images down.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement