Thread: texture displays improperly

  1. #1
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972

    texture displays improperly

    Ok, I decided to get a little into directx again, and I decided to use direct3d for 2d graphics (rather than use direcdraw).

    I managed to get things to display just fine with transparency until I went to make a small cursor (17x17 pixels). It looks fine, except there's a square around it! I thought maybe photoshop was playing tricks on me and somehow I had changed the red by 1 or something around the edge. Nope, its the right color (magenta).

    So I try to make the image larger and draw something around the outside. Run the program again, cursor looks the same! Hmm, maybe I saved under the wrong name. But I try to draw inside the square and when I run the program again, the inside of the square has changed, but nothing outside has changed!

    Here's how I load the texture:
    Code:
    bool object::LoadTexture(char *fileName, LPDIRECT3DDEVICE9 d3dDevice)
    {
        			
        //Use a magenta colourkey
        D3DCOLOR colorkey = 0xFFFF00FF;
       
        // Load image from file
        if (FAILED(D3DXCreateTextureFromFileEx (d3dDevice, fileName, 0, 0, 1, 0, 
              D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 
              colorkey, NULL, NULL, &texture)))
        {
            return false;
        }
        D3DSURFACE_DESC surfaceDesc;
        texture->GetLevelDesc(0, &surfaceDesc);
        width = surfaceDesc.Width;
        height = surfaceDesc.Height;
      
       
       return true;
    }
    And I use a D3DXSprite to display it:
    Code:
    Sprite->Draw(texture,NULL,NULL,&D3DXVECTOR2(width/2,height/2),rot,&D3DXVECTOR2(x,y),0xFFFFFFFF);
    I'll also attach images of what my cursor looks like in photoshop then in the program.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Well I fixed the problem but I still don't know why it wasn't working.

    I had the file saved as a 32 bit *.tga so I decided to save it as a *.png and that worked. So then I saved it as a 24 bit tga and that worked as well. Can anyone explain why that happened?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Well its hard to tell from that little chunk of code what exactly went wrong. I could only say it sounds like the d3dxcreatetexturefromfileEx was having issues, or it returned S_OK when it shouldn't (it will do that from time to time, for me at least). Might help to post your render loop as that would shed some light on the situation.

  4. #4
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Photoshop has some bugs. CS doesn't save alpha to files correctly at all, so I wouldn't be surprised if it was doing some other funky stuff to you.

    It may have been the mag filter since it's just on the edge, but in your screen shot it's very well defined. However if it actually looks blurry, then it's because of the filtering.
    Last edited by skorman00; 08-09-2005 at 06:02 PM.

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Yup it was definitely a clearly defined border, and I wouldn't be surprised if it was an issue with photoshop. Anyways, it isn't really an issue since it works with 24-bit textures; I guess I don't even need it to be 32-bit
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #6
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Technically, from what I've read, things are converted into 32-bit mostly anyway. Its hard to say what exactly happens, but I believe 32-bit is the "true" color depth its shown at regardless of anything else. ( I could be wrong as I am in no way a expert in directx... a somewhat seasoned user, but by far no expert )

    As for PS I didn't know it had that bug, you learn something new every day

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. d3d9 c++ texture wrapper... again...
    By yaya in forum Game Programming
    Replies: 0
    Last Post: 04-01-2009, 01:08 PM
  2. D3d Texture Wrapper == ARRRGGGGHHH
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 03-25-2009, 06:41 PM
  3. Replies: 4
    Last Post: 02-27-2008, 03:10 PM
  4. OpenGL - look trough surface -nehe lesson
    By GanglyLamb in forum Game Programming
    Replies: 8
    Last Post: 08-24-2006, 11:06 PM
  5. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM