Results 1 to 9 of 9

Thread: filling a IDIRECT3DTEXTURE9 without the d3dx9 library

  1. #1

    filling a IDIRECT3DTEXTURE9 without the d3dx9 library

    I'm looking for a method to fill a IDIRECT3DTEXTURE9 with a Bitmap (preferable from a TBitmap) manually without using the d3dx9 library.

    If anyone has any idea how to do this or if you could send me in the right the direction I would be very thankfull !
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  2. #2

    filling a IDIRECT3DTEXTURE9 without the d3dx9 library

    Here's a slightly modified version of a function I started writing for my engine, but gave up on after I decided that D3DX did a much better job.
    You will need to have created the texture with the correct size etc., and I think it has to be in D3DPOOL_MANAGED.
    It only handles A8R8G8B8 textures at the moment.
    [pascal]procedure LoadTextureFromBitmap(Bitmap: TBitmap; Texture: IDirect3DTexture8; ColorKey: TD3DColor);
    var
    hr: HResult;

    surf: IDirect3DSurface9;
    lrect: TD3DLocked_Rect;
    i, j: Integer;
    sbits, dbits: Pointer;
    begin
    // Get surface of texture
    hr := Texture.GetSurfaceLevel(0, surf);
    if (hr <> D3D_OK) then begin
    raise Exception.Create('Get Surface Level '
    + '''' + DXGetErrorString9(hr) + '''');
    end;
    // Lock surface
    hr := surf.LockRect(lrect, nil, 0);
    if (hr <> D3D_OK) then begin
    raise Exception.Create('LockRect '
    + '''' + DXGetErrorString9(hr) + '''');
    end;
    // Convert to 32bit pixel format
    Bitmap.PixelFormat := pf32bit;
    // Copy Pixel Data with colour keying
    for i := 0 to (Bitmap.Height - 1) do begin
    dbits := lrect.pBits;
    sbits := Bitmap.ScanLine[i];
    for j := 0 to (Bitmap.Width - 1) do begin
    if ((PCardinal(sbits)^) and $00FFFFFF) = (ColorKey and $00FFFFFF) then
    PCardinal(dbits)^ := $00000000
    else
    PCardinal(dbits)^ := PCardinal(sbits)^ or $FF000000;

    sbits := Pointer(Integer(sbits) + 4);
    dbits := Pointer(Integer(dbits) + 4);
    end;

    lrect.pBits := Pointer(Integer(lrect.pBits) + lrect.Pitch);
    end;
    // Unlock surface
    hr := surf.UnlockRect;
    if (hr <> D3D_OK) then begin
    raise Exception.Create('UnlockRect '
    + '''' + DXGetErrorString9(hr) + '''');
    end;
    // Release the surface interface
    surf := nil;
    end;[/pascal]

    Hope this helps.

    BTW: I notice there are still some problems with the forum's syntax highlighting!
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  3. #3

    filling a IDIRECT3DTEXTURE9 without the d3dx9 library

    Just to note. D3DX9 gives you free and DEBUGGED code what in most easy usage scenario do the next things:
    1) Allocates texture with most close to your original bitmap format
    2) Convert your data if no matched texture format found
    3) Handles cases then your texture is
    3a. either larger then supported by video-card dimentions of texture - then D3DX downsamples your data
    3b. ether your texture dimentions are not power of 2 and current videocard do not support such textures - then D3DX stretches original data to fill square texture
    4) Generated mip-map chain on your original data.

    But you can still disable any of the "features" above.

    PS. You can point in what memory pool texture should be allocated.
    There are only 10 types of people in this world; those who understand binary and those who don't.

  4. #4

    filling a IDIRECT3DTEXTURE9 without the d3dx9 library

    Thanks for the solution!

    I know the D3DX9 provides a lot of extra functions and tricks, however all I'm going to do is use Direct3D for 2D drawing functions that I know use in DelphiX. At the moment I have been able to load every bitmap I wanted to test with and it works marvelous.

    The D3DX9 functions are great but I don't think they are worth 1.5 MB and when I can do things by hand I mostly try doing it by hand.


    P.S. Yes I know I'm crazy.
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  5. #5

    filling a IDIRECT3DTEXTURE9 without the d3dx9 library

    The D3DX9 functions are great but I don't think they are worth 1.5 MB and when I can do things by hand I mostly try doing it by hand.
    http://clootie.narod.ru - now only 444Kb for texture handling subset of D3DX9 library.
    There are only 10 types of people in this world; those who understand binary and those who don't.

  6. #6

    filling a IDIRECT3DTEXTURE9 without the d3dx9 library

    What is the difference between the d3dx9.dll included with the DirectX9 sdk from Microsoft, and the d3dx9ab.dll included with Clootie's headers? Both seem to work the same with me.
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  7. #7

    filling a IDIRECT3DTEXTURE9 without the d3dx9 library

    There is no file called "d3dx9.dll" included with the DX9 SDK. I guess what you mean is "d3dx9d.dll", with the d standing for Debug. Clear ?

    And Clootie, nice idea with the Texture Function Subset !

  8. #8

    filling a IDIRECT3DTEXTURE9 without the d3dx9 library

    Sorry, my mistake, I was getting confused between DX9 and DX8!
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  9. #9

    filling a IDIRECT3DTEXTURE9 without the d3dx9 library

    Microsoft never provided DLL version of any version of D3DX(7,8,9). Only from DirectX8 they started to provide debug version of D3DX in D3DXnD.dll.
    There are only 10 types of people in this world; those who understand binary and those who don't.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •