Menu

DirectX linking on last time.

2007-06-27
2012-09-26
  • Nobody/Anonymous

    Hi I have Jonathan S. Harbour’s book Beginning Game Programming I had a problem at first getting DirectX9 to work right. But somebody helped me get the program to link correct by going –ld3d9. The problem I have now is the next file needs a d3dx9 link and I can’t get it to work correct. He has some executable files that will work with the d3dx9.dll just this file won’t when I compile it with the Dev-C++.

    He says inside the book something about adding support using Microsoft’s compiler how would this work with your Dev-C++. Here is what he says to do on page 106 of his book go to project settings Settings For Win32 Debug in the category it is General. Then in the Object/library modules it has d3d9.lib d3dx9.lib kernel32.lib user32.lib gdi32.lib winspool.lib.

    He uses your compiler as a Free compiler with the book I said this to you before. It has some check marks that say in the Microsoft Visual C++ in his book the first one is Generate debug info and then link incrementally is checked. Below are the parameters section to link things in your Dev-C++ program I put in.

    -ld3d9
    -ld3dx9

    Here is what the Compile Log said since somebody here asked me before for it on my last problem I fixed.

    Compiler: Default compiler
    Building Makefile: "C:\C++ Book by Jonathan Harbour\sources\chapter06\load_bitmap\Makefile.win"
    Executing make...
    make.exe -f "C:\C++ Book by Jonathan Harbour\sources\chapter06\load_bitmap\Makefile.win" all
    g++.exe -DDEBUG -c winmain.cpp -o winmain.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -fexceptions -g3
    winmain.cpp: In function int Game_Init(HWND__*)': winmain.cpp:206: error:D3DX_DEFAULT' undeclared (first use this function)
    winmain.cpp:206: error: (Each undeclared identifier is reported only once for each function it appears in.)
    winmain.cpp:208: error: `D3DXLoadSurfaceFromFile' undeclared (first use this function)
    make.exe: *** [winmain.o] Error 1
    Execution terminated

    And now below is the code to the project he has from his book.

    // Beginning Game Programming, 2nd Edition
    // Chapter 6
    // Load_Bitmap program

    //header files to include

    include <d3d9.h>

    include <d3dx9.h>

    include <time.h>

    //application title

    define APPTITLE "Create_Surface"

    //macros to read the keyboard asynchronously

    define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

    define KEY_UP(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

    //screen resolution

    define SCREEN_WIDTH 640

    define SCREEN_HEIGHT 480

    //forward declarations
    LRESULT WINAPI WinProc(HWND,UINT,WPARAM,LPARAM);
    ATOM MyRegisterClass(HINSTANCE);
    int Game_Init(HWND);
    void Game_Run(HWND);
    void Game_End(HWND);

    //Direct3D objects
    LPDIRECT3D9 d3d = NULL;
    LPDIRECT3DDEVICE9 d3ddev = NULL;

    LPDIRECT3DSURFACE9 backbuffer = NULL;
    LPDIRECT3DSURFACE9 surface = NULL;

    //window event callback function
    LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
    switch( msg )
    {
    case WM_DESTROY:
    Game_End(hWnd);
    PostQuitMessage(0);
    return 0;
    }

    return DefWindowProc( hWnd, msg, wParam, lParam );
    

    }

    //helper function to set up the window properties
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    //create the window class structure
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);

    //fill the struct with info
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WinProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = APPTITLE;
    wc.hIconSm       = NULL;
    
    //set up the window with the class info
    return RegisterClassEx(&amp;wc);
    

    }

    //entry point for a Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {
    // declare variables
    MSG msg;

    // register the class
    MyRegisterClass(hInstance);
    
    // initialize application 
    //note--got rid of initinstance
    HWND hWnd;
    
    //create a new window
    hWnd = CreateWindow(
       APPTITLE,              //window class
       APPTITLE,              //title bar
       WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP,   //window style
       CW_USEDEFAULT,         //x position of window
       CW_USEDEFAULT,         //y position of window
       SCREEN_WIDTH,          //width of the window
       SCREEN_HEIGHT,         //height of the window
       NULL,                  //parent window
       NULL,                  //menu
       hInstance,             //application instance
       NULL);                 //window parameters
    
    //was there an error creating the window?
    if (!hWnd)
      return FALSE;
    
    //display the window
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    
    //initialize the game
    if (!Game_Init(hWnd))
        return 0;
    
    // main message loop
    int done = 0;
    while (!done)
    {
        if (PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE)) 
        {
            //look for quit message
            if (msg.message == WM_QUIT)
                done = 1;
    
            //decode and pass messages on to WndProc
            TranslateMessage(&amp;msg);
            DispatchMessage(&amp;msg);
        }
        else
            //process game loop (else prevents running after window is closed)
            Game_Run(hWnd);
    }
    
    return msg.wParam;
    

    }

    int Game_Init(HWND hwnd)
    {
    HRESULT result;

    //initialize Direct3D
    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if (d3d == NULL)
    {
        MessageBox(hwnd, &quot;Error initializing Direct3D&quot;, &quot;Error&quot;, MB_OK);
        return 0;
    }
    
    //set Direct3D presentation parameters
    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory(&amp;d3dpp, sizeof(d3dpp));
    
    d3dpp.Windowed = FALSE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = SCREEN_WIDTH;
    d3dpp.BackBufferHeight = SCREEN_HEIGHT;
    d3dpp.hDeviceWindow = hwnd;
    
    //create Direct3D device
    d3d-&gt;CreateDevice(
        D3DADAPTER_DEFAULT, 
        D3DDEVTYPE_HAL, 
        hwnd,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING,
        &amp;d3dpp, 
        &amp;d3ddev);
    
    if (d3ddev == NULL)
    {
        MessageBox(hwnd, &quot;Error creating Direct3D device&quot;, &quot;Error&quot;, MB_OK);
        return 0;
    }
    
    //set random number seed
    srand(time(NULL));
    
    //clear the backbuffer to black
    d3ddev-&gt;Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
    
    //create surface
    result = d3ddev-&gt;CreateOffscreenPlainSurface(
        640,                //width of the surface
        480,                //height of the surface
        D3DFMT_X8R8G8B8,    //surface format
        D3DPOOL_DEFAULT,    //memory pool to use
        &amp;surface,           //pointer to the surface
        NULL);              //reserved (always NULL)
    
    if (result != D3D_OK)
        return 1;
    
    //load surface from file into newly created surface
    result = D3DXLoadSurfaceFromFile(
        surface,            //destination surface
        NULL,               //destination palette
        NULL,               //destination rectangle
        &quot;legotron.bmp&quot;,     //source filename
        NULL,               //source rectangle
        D3DX_DEFAULT,       //controls how image is filtered
        0,                  //for transparency (0 for none)
        NULL);              //source image info (usually NULL)
    
    //make sure file was loaded okay
    if (result != D3D_OK)
        return 1;
    
    //return okay
    return 1;
    

    }

    void Game_Run(HWND hwnd)
    {
    //make sure the Direct3D device is valid
    if (d3ddev == NULL)
    return;

    //start rendering
    if (d3ddev-&gt;BeginScene())
    {
        //create pointer to the back buffer
        d3ddev-&gt;GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &amp;backbuffer);
    
        //draw surface to the backbuffer
        d3ddev-&gt;StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE);
    
        //stop rendering
        d3ddev-&gt;EndScene();
    }
    
    //display the back buffer on the screen
    d3ddev-&gt;Present(NULL, NULL, NULL, NULL);
    
    //check for escape key (to exit program)
    if (KEY_DOWN(VK_ESCAPE))
        PostMessage(hwnd, WM_DESTROY, 0, 0);
    

    }

    void Game_End(HWND hwnd)
    {
    //free the surface
    surface->Release();

    //release the Direct3D device
    if (d3ddev != NULL) 
        d3ddev-&gt;Release();
    
    //release the Direct3D object
    if (d3d != NULL)
        d3d-&gt;Release();
    

    }

    Thanks for the help before whoever it was and I hope you can help on this one too.

     
    • Nobody/Anonymous

      I looked I forgot above you said the DirectX90c file. That is what I put in it at first it still will not work on this program others it does. But the DirectX stuff using this d3dx9.dll it seems to have a problem.

       
    • Anonymous

      Anonymous - 2007-06-28

      Stop moving the goal posts! It is getting very confusing. It is best to wait for an answer to your last question before posting a new one!

      >> Hi thank you for the help yes I already have that file in the include folder.
      No! You have to include it in the source file! Just being close to your code won't help; that is like placing the tea bag next to the pot and expecting to make tea!

      >> This is why I don't understand why when all these files are
      >> inside the folders they need to be in why it won't link correctly.

      As I already pointed out; this was a COMPILER error NOT a LINKER error. Can you sense my frustration yet!?

      >> And yes it does look the same the compile log nothing really has changed why I do not know.

      Because you did not do as I suggested and fix the problem!

      Your code should look like this:

      //header files to include

      include <d3d9.h>

      include <d3dx9.h>

      include <D3dx9tex.h> // INCLUDE THIS HERE!

      include <time.h>

      >> I looked at the code I commented out the part on d3dx9.h my fault.
      >> But I still stop after putting in the other lib files he wants the
      >> compile log below.
      Good grief. You mean the code you posted was not the code you were compiling!? Give me strength. Presumably d3dx9.h includes D3dx9tex.h which is why it now compiles (but has not linked).

      It is now failing at the linker stage, but this is an OS related error rather than a linker error. I note that you have not heeded the advice in the "PLEASE READ BEFORE POSTING A QUESTION" thread and avoided spaces in your project path. This is almost certainly the cause of your latest problem (even if it has previously worked!).

      Clifford

       
    • Nobody/Anonymous

      I found the problem it was the fact that when I installed the DirectX9 SDK with Dev-C++ it had the dll files inside a folder. It ran the d3d9.dll stuff just that other d3dx9.dll once I put it in the windows system32 folder everything worked.

       
    • Anonymous

      Anonymous - 2007-06-29

      The DLL is not referenced during the build, only the export library. Having the wrong DLL would cause a runtime error not a linker error. What you are saying bears no relationship to the evidence you have posted.

      Clifford

       
    • Nobody/Anonymous

      I linked those other files correct I think, but it still stops at this point in the code. D3DX_DEFAULT, //controls how image is filtered

      And this is what the Compile Log said below here.

      Compiler: Default compiler
      Building Makefile: "C:\load_bitmap\Makefile.win"
      Executing make...
      make.exe -f "C:\load_bitmap\Makefile.win" all
      g++.exe -DDEBUG -c winmain.cpp -o winmain.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -fexceptions -g3
      winmain.cpp: In function int Game_Init(HWND__*)': winmain.cpp:206: error:D3DX_DEFAULT' undeclared (first use this function)
      winmain.cpp:206: error: (Each undeclared identifier is reported only once for each function it appears in.)
      winmain.cpp:208: error: `D3DXLoadSurfaceFromFile' undeclared (first use this function)
      make.exe: *** [winmain.o] Error 1
      Execution terminated

      I hope you can help me fix the problem trying to get this to run I want to learn how to work with DirectX9 and I don’t want to get Microsoft’s Visual C++ program. I think yours has worked really great for me up until this DirectX9 linking problems. And you helped me before at the beginning of the book

       
    • Windsting

      Windsting - 2007-06-27

      your code is ok,problem is that ,you need a DirectX include(.h) , library(.a) and dll(.dll) pack,goto:
      http://www.g-productions.net
      and click "All downloads",
      select the "DirectX.DevPak 9.0c",
      after downloaded,just install it,
      now, you get all what you need,
      just different name from the vc++ version,
      for example:"d3d9.lib" called "libd3d9.a"
      in the directory "Dev-Cpp\lib" now,
      and do not forget to copy all files in "Dev-Cpp\DLL" to your
      "WINDOWS\system32"(or any other registed path),

      enjoy it! :)
      I hope this is useful for you.

       
      • Anonymous

        Anonymous - 2007-06-27

        I think he already mentioned at the start that he has this. However it stands as a good point for anyone else who might need it.

         
    • Anonymous

      Anonymous - 2007-06-27

      The errors in teh log are compiler errors, not linker errors, so no ammount of fiddling with linker options will get you past that point (compilation preceded linking).

      The documentation for D3DXLoadSurfaceFromFile() ( http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c_Dec_2005/D3DXLoadSurfaceFromFile.asp ) shows that you need to include D3dx9tex.h, which you have not done.

      Clifford

       
    • Nobody/Anonymous

      The last guy was right I did install this already that is how I got the first DirectX9 file to work correct. But this one will not work it stops at this point I tried to re-download the Dev-C++ DirectX9c and it still will not work. Here is where it stops again with the same comments on the Compile Log. D3DX_DEFAULT, //controls how image is filtered

      The Compile Log below.

      Compiler: Default compiler
      Building Makefile: "C:\load_bitmap\Makefile.win"
      Executing make...
      make.exe -f "C:\load_bitmap\Makefile.win" all
      g++.exe -DDEBUG -c winmain.cpp -o winmain.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -fexceptions -g3

      winmain.cpp: In function int Game_Init(HWND__*)': winmain.cpp:206: error:D3DX_DEFAULT' undeclared (first use this function)
      winmain.cpp:206: error: (Each undeclared identifier is reported only once for each function it appears in.)
      winmain.cpp:208: error: `D3DXLoadSurfaceFromFile' undeclared (first use this function)

      make.exe: *** [winmain.o] Error 1

      Execution terminated

       
    • Anonymous

      Anonymous - 2007-06-27

      That looks pretty much the same as the last log you posted. Did you add the "#include <D3dx9tex.h>" to your source code like I suggested?

      Clifford

       
    • Nobody/Anonymous

      Hi thank you for the help yes I already have that file in the include folder. This is why I don't understand why when all these files are inside the folders they need to be in why it won't link correctly. And yes it does look the same the compile log nothing really has changed why I do not know.

       
    • Nobody/Anonymous

      Wait a minute are you talking about a Header File or a Lib file. I say this because it isn't in the Lib file.

       
    • Nobody/Anonymous

      I looked at the code I commented out the part on d3dx9.h my fault. But I still stop after putting in the other lib files he wants the compile log below.

      Compiler: Default compiler
      Building Makefile: "C:\C++ Book by Jonathan Harbour\sources\chapter06\load_bitmap\Makefile.win"
      Executing make...
      make.exe -f "C:\C++ Book by Jonathan Harbour\sources\chapter06\load_bitmap\Makefile.win" all
      g++.exe -DDEBUG -c winmain.cpp -o winmain.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -fexceptions -g3

      kernel32.lib user32.lib gdi32.lib winpool.lib

      process_begin: CreateProcess((null), kernel32.lib user32.lib gdi32.lib winpool.lib, ...) failed.
      make (e=2): The system cannot find the file specified.

      make.exe: *** [winmain.o] Error 2

      Execution terminated

       
    • Nobody/Anonymous

      One last thing if I run the code without the other lib files it says d3dx9.dll not found you might try and re-install the program. But I thought it came from the Dev-C++ d3x9 file package file by the way the one I used is d3dx9c should I try one the d3d9 package file or the other on part b. Then see if they would work just an idea.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.