Results 1 to 5 of 5
  1. #1
    trojan.win128's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Location
    Nix Olympica, Mars
    Posts
    58
    Reputation
    10
    Thanks
    90

    Smile How to use: D3DXCreateTextureFromResource

    Hello people!

    After struggling a lot and spotting out each mistake, I finally managed to overcome this problem: Rendering picture from a resource.

    Without much talk, let's get straight to the code:

    1) Navigate to Solution Explorer and right click on Project and choose Add -> Resource.
    Click "Import" and select an image file (.png, .jpg, .dds, etc.. .gif won't work!). Hit OK.

    For this project, I selected .JPG

    2) Now Visual Studio should have added 3 new things in your project:
    resource.h
    (projectname).rc
    (image).jpg

    The (image).jpg is just a reference, others are newly created.

    3) Right-click on (projectname).rc and click "View Code"

    *If a dialog appears, click "OK".

    Scroll down the editor and you should see a code similar to this:
    Code:
    IDB_BITMAP1             JPG                     "C:\\Users\\X\\Desktop\\x.JPG"
    It can be slightly different.

    Now, after "IDB_BITMAP1", you see "JPG". Rename this to "RCDATA"

    Code:
    It should look like this:
    IDB_BITMAP1             RCDATA                    "C:\\Users\\X\\Desktop\\x.JPG"
    * This step is necessary or DirectX will give "invalid data" error.
    * Now, save all.

    4) Goto your script.
    And add these as Global Variables:

    Code:
    LPD3DXSPRITE Sprite;
    LPDIRECT3DTEXTURE9 Texture;
    bool TexturesLoaded = false;
    5) Add this to where you want the image to be loaded:

    (Assuming that your global LPDIRECT3DDEVICE9 is declared as iDevice)
    Code:
    if(!TexturesLoaded)
    {
    	HRESULT DTEX = D3DXCreateTextureFromResourceA(iDevice, GetModuleHandleA("(yourmodulename).dll"), MAKEINTRESOURCEA( IDB_BITMAP1 ), &Texture);
    	HRESULT DSPR = D3DXCreateSprite(iDevice, &Sprite);
    	if(DTEX == D3D_OK && DSPR == S_OK) TexturesLoaded = true;
    }
    6) Add this to BeginScene or EndScene:

    Code:
    if(TexturesLoaded)
    {
    	D3DXVECTOR3 POS;
    	POS.x = 10;
    	POS.y = 10;
    	POS.z = 0;
    
    	Sprite->Begin(0); //For transparent images, set the flag value to 16.
    	Sprite->Draw(Texture, NULL, NULL, &POS, 0xFFFFFFFF);
    	Sprite->End();
    }
    That's it, now Build this project and inject the DLL to see if it works. If not, check if you made any mistakes in:
    - Importing.
    - Renaming.
    - Initiating resources before drawing.
    - Drawing on wrong callbacks.
    - Module name.

    Tip:
    Make sure you resize the images to a square with pixel sizes which is a power of 2.
    Like 16x16, 32x32, 64x64, 128x128 and so on.

    Demonstration:
    Check attachment.
    Attached Images Attached Images
    Last edited by trojan.win128; 05-14-2013 at 11:45 PM.
    Successful trades with:
    Dark21890 (Genuine Trader)

  2. The Following User Says Thank You to trojan.win128 For This Useful Post:

    WhiteHat PH (05-21-2013)

  3. #2
    ~Syphox's Avatar
    Join Date
    May 2012
    Gender
    male
    Location
    The Third Reich
    Posts
    1,307
    Reputation
    337
    Thanks
    344
    My Mood
    Angelic
    I think I saw this tutorial before, if you C&P it, give credits! Anyway, thanks

  4. #3
    WhiteHat PH's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Location
    Some Where I Belong
    Posts
    1,350
    Reputation
    25
    Thanks
    3,100
    My Mood
    Aggressive
    wow grat thank's ^^






    When Im gone dont forget me cause I will come back someday.



    Youtube Channel


     


  5. #4
    trojan.win128's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Location
    Nix Olympica, Mars
    Posts
    58
    Reputation
    10
    Thanks
    90
    Quote Originally Posted by justindufisch View Post
    I think I saw this tutorial before, if you C&P it, give credits! Anyway, thanks
    This isn't a copy at all... The codes for creating a texture for D3D may seem similar.
    @justindufisch, @Coderz: My pleasure.
    Successful trades with:
    Dark21890 (Genuine Trader)

  6. #5
    WhiteHat PH's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Location
    Some Where I Belong
    Posts
    1,350
    Reputation
    25
    Thanks
    3,100
    My Mood
    Aggressive
    @trojan.win128 this not so simple .... edit for your front menu d3d9






    When Im gone dont forget me cause I will come back someday.



    Youtube Channel


     


Similar Threads

  1. [TUT] How to use kssn GENERATOR
    By ktalin91 in forum WarRock Korea Hacks
    Replies: 13
    Last Post: 05-10-2009, 07:17 PM
  2. How to Use Tsearch
    By wardo1926 in forum Hack Requests
    Replies: 5
    Last Post: 12-18-2007, 09:24 PM
  3. warrock addresses and how to use
    By ragman1234 in forum WarRock - International Hacks
    Replies: 1
    Last Post: 04-15-2007, 12:38 PM
  4. Help! how to use ardamax keylogg
    By gmgundamx7 in forum WarRock - International Hacks
    Replies: 8
    Last Post: 02-28-2007, 04:43 PM
  5. How To Use A Render By Phate
    By Paolo1993 in forum Tutorials
    Replies: 0
    Last Post: 01-27-2006, 08:03 PM