Refresher

This is a discussion on Refresher within the Game Programming forums, part of the General Programming Boards category; Hi. It has been a while since I have been able to do any programming and now I am tring ...

  1. #1
    Darkness Prevails Dark_Phoenix's Avatar
    Join Date
    Oct 2006
    Location
    Houston, Texas
    Posts
    174

    Refresher

    Hi. It has been a while since I have been able to do any programming and now I am tring to get back into it. I have an idea for a game I want to create using DirectX so I updated to the DX9 SDK and borrowed Programming Role Playing Games with DirectX from a friend ( I know not the best choice, but I am using it more as a refresher ).

    Anyway, I am having a problem with one of the examples on loading textures. When I go to compile the program windows throws up a message during the linking stage that the file 'ID.EXE has encountered a problem and needs to shut down' and throws the following errors
    Code:
      .drectve `/DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" ' unrecognized
      [Linker error] undefined reference to `??2@YAPAXI@Z'
    both are repeated several times... Anyway, I am not sure if this is an IDE option That I do not have set right (using dev-c++ / windows xp) or if there is something wrong with the install of DX9 SDK.

    Thanks in advance for any help
    Here is the code
    Code:
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    #include <d3d9.h>
    #include <d3dx9.h>
    
    #define VERTEXFVF (D3DFVF_XYZ | D3DFVF_TEX1)
    #define SCREEN_WIDTH     400
    #define SCREEN_HEIGHT    400
    #define REFRESH_RATE     0
    #define COLOR_FORMAT     D3DFMT_R5G6B5
    
    // MACROS //////////////////////////////////////////////////////////////////////
    
    #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEYUP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
    
    // Window handles, class and caption text //////////////////////////////////////
    HWND             hWndApp;
    HINSTANCE        hInstApp;
    const char       szClassApp[]   = "DirectX Demo";
    const char       szCaptionApp[] = "DX Texture Loading";
    
    // Structures //////////////////////////////////////////////////////////////////
    // 2-D vertex format and descriptor
    typedef struct {
        FLOAT x, y, z;     // 2-D coordinates
        FLOAT rhw;         // rhw
        FLOAT u, v;        // texture coordinates
    } sVertex;
    
    // Globals /////////////////////////////////////////////////////////////////////
    IDirect3D9             *g_pD3D          = NULL; // Direct3D object
    IDirect3DDevice9       *g_pD3DDevice    = NULL; // Direct3D device
    IDirect3DVertexBuffer9 *g_pVertexBuffer = NULL; // Vertex buffer
    IDirect3DTexture9      *g_pTexture   = NULL;
    
    // Function prototypes /////////////////////////////////////////////////////////
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    BOOL Initialize();
    BOOL Shutdown();
    BOOL DoFrame();
    
    //  WinMain and the Windows Procedure  /////////////////////////////////////////
    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, 
                       LPSTR szCmdLine, int nCmdShow) {
        MSG        Msg;
        hInst    = hInstApp;
    
        WNDCLASSEX wcex = {
          wcex.cbSize        = sizeof(wcex),
          wcex.style         = CS_CLASSDC,
          wcex.lpfnWndProc   = WindowProc,
          wcex.cbClsExtra    = 0,
          wcex.cbWndExtra    = 0,
          wcex.hInstance     = hInst,
          wcex.hIcon         = LoadIcon(NULL, IDI_APPLICATION),
          wcex.hCursor       = LoadCursor(NULL, IDC_ARROW),
          wcex.hbrBackground = NULL,
          wcex.lpszMenuName  = NULL,
          wcex.lpszClassName = szClassApp,
          wcex.hIconSm       = LoadIcon(NULL, IDI_APPLICATION)
        };
    
        if(!RegisterClassEx(&wcex) )
            return FALSE;
    
        if (!(hWndApp = CreateWindowEx(0,          // extended style
                                    szClassApp,    // class
                                    szCaptionApp,  // title
                                    WS_POPUP,      // use WS_OVERLAPPEDWINDOW 
                                                   //    for a window app
                                                   // use WS_VISIBLE to show window
                                    0,0,           // initial x,y
                                    SCREEN_WIDTH, 
                                    SCREEN_HEIGHT, // initial width, height
                                    NULL,          // handle to parent 
                                    NULL,          // handle to menu
                                    hInstApp,      // instance of this application
                                    NULL) ) )      // extra creation parms
            return 0;
          
        ShowWindow(hWndApp, SW_NORMAL);
        UpdateWindow(hWndApp);
    
        // Run init function and return on error
        if(Initialize() == FALSE)
            return FALSE;
    
        // Start message pump, waiting for signal to quit
        ZeroMemory(&Msg, sizeof(MSG));
        while(Msg.message != WM_QUIT) {
            if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) ) {
                TranslateMessage(&Msg);
                DispatchMessage(&Msg);
            }
        if(DoFrame() == FALSE)
            break;
        }
    
        // Run shutdown function
        Shutdown();
      
        UnregisterClass(szClassApp, hInst);
    
        return Msg.wParam;
    }
    
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg,
                                WPARAM wParam, LPARAM lParam) {
        switch(Msg) {
            case WM_DESTROY: {
                PostQuitMessage(0);
                return 0;
            } break;
        }
    
        return DefWindowProc(hWnd, Msg, wParam, lParam);
    }
    
    ////////////////////////////////////////////////////////////////////////////////
    // This initializes the program
    BOOL Initialize() {
        D3DPRESENT_PARAMETERS d3dPParam;
        D3DDISPLAYMODE        d3dDispMode;
        BYTE                  *Ptr;        // pointer to vertex buffer memory
        sVertex Verts[4] = {
          {  50.0f,  50.0f, 1.0f, 1.0f, 0.0f, 0.0f },
          { 350.0f,  50.0f, 1.0f, 1.0f, 1.0f, 0.0f },
          {  50.0f, 350.0f, 1.0f, 1.0f, 0.0f, 1.0f },
          { 350.0f, 350.0f, 1.0f, 1.0f, 1.0f, 1.0f }
        };
    
        // Do a windowed mode initialization of Direct3D
        
        // obtain the interface
        if( (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION) ) == NULL)
            return FALSE;
        
        // Set the Adapter Display Mode and Presentation Meathod
        if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3dDispMode) ) )
            return FALSE;
        ZeroMemory(&d3dPParam, sizeof(d3dPParam) );
        d3dPParam.Windowed = true;
        d3dPParam.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dPParam.BackBufferFormat = d3dDispMode.Format;
        d3dPParam.EnableAutoDepthStencil = FALSE;
    
        // Create the interface
        if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWndApp,
                                       D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                       &d3dPParam, &g_pD3DDevice) ) )
            return FALSE;
    
        // Create the vertex buffer and set data
        g_pD3DDevice->CreateVertexBuffer(sizeof(sVertex)*4, 0, VERTEXFVF, 
                                         D3DPOOL_DEFAULT, &g_pVertexBuffer, NULL);
        g_pVertexBuffer->Lock(0, 0, (void**)&Ptr, 0);
        memcpy(Ptr, Verts, sizeof(Verts) );
        g_pVertexBuffer->Unlock();
    
        // Load texture from disk and set stage parameters
        if(FAILED(D3DXCreateTextureFromFile(g_pD3DDevice, "texture.bmp",
                                            &g_pTexture) ) ) 
            return FALSE;
        g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP,   D3DTOP_MODULATE);
        g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
        g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
        g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE);
        
        // Set Magnification and Minification filters for textures
        if(FAILED(g_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, 
                                                   D3DTEXF_POINT) ) )
            return false;
        if(FAILED(g_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, 
                                                   D3DTEXF_POINT) ) )
            return false;
    
        
        return TRUE;
    }
    
    ////////////////////////////////////////////////////////////////////////////////
    // This shuts down the program, releasing the system resources
    BOOL Shutdown() {
        // Release vertex buffer
        if(g_pVertexBuffer != NULL)
            g_pVertexBuffer->Release();
    
        // Release texture
        if(g_pTexture != NULL)
            g_pTexture->Release();
    
        // Release device and 3D objects
        if(g_pD3DDevice != NULL)
            g_pD3DDevice->Release();
    
        if(g_pD3D != NULL)
            g_pD3D->Release();
    
        return TRUE;
    }
    
    ////////////////////////////////////////////////////////////////////////////////
    //  Build the frame
    BOOL DoFrame() {
       if (KEYDOWN(VK_ESCAPE) ) {
            SendMessage(hWndApp, WM_CLOSE, 0, 0);
        }
    
        // Clear device backbuffer and begin the scene
        g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,
                          D3DCOLOR_RGBA(0, 0, 0, 255), 1.0f, 0);
        if(SUCCEEDED(g_pD3DDevice->BeginScene() ) ) {
            // Set the texture
            g_pD3DDevice->SetTexture(0, g_pTexture);
            
            // Set the stream source and the vertex shader
            g_pD3DDevice->SetStreamSource(0, g_pVertexBuffer, 0,sizeof(sVertex));
            g_pD3DDevice->SetFVF(VERTEXFVF);
    
            // Release texture from memory
            g_pD3DDevice->SetTexture(0, NULL);
            
            // draw triangle list
            g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
                    
            // End the scene
            g_pD3DDevice->EndScene();
        }
    
        // Display the scene
        g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
    
        return TRUE;
    }

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    that first line looks like your options are trying to link the same library twice.

    I believe the second line is saying that it can't find the definition for operator new ( I used MSVC's undname.exe to find that ). If that is the case, your linker settings are mucked up.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Try re-installing Dev is it is a link internal error, that should reset the setup files. If this does not solve the problem, then make sure everything is linked only once

  4. #4
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    You said that you updated to the Direct X 9 SDK. Did you uninstall your old SDK before you installed Direct X 9 SDK? If you didn't that is probably why you are having problems.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    What are your linker options? In Dev-C++, it might be in project options (Alt-P) unless you only use Dev-C++ for DirectX programs, in which case it might be in compiler/linker options.

    If you have a repeated library, get rid of the duplicate.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Darkness Prevails Dark_Phoenix's Avatar
    Join Date
    Oct 2006
    Location
    Houston, Texas
    Posts
    174
    Did you uninstall your old SDK before you installed Direct X 9 SDK? If you didn't that is probably why you are having problems
    Yeah. I figured that out this morning. Realixed I still had DX7 installed. So I scrapped both DX versions, and dev-c++ just to be safe, and reinstalled. That solved half the problem. The other half was that there was a copy of d3d9.h in both the DX9 SDK inclode folder and in the dev-c++ include folder. Don't know if dev had it originally (doubt it) or if the DX install put it there. But I got rid of one of those and it solved the rest of the problem...

    Now I just have to figure out why the texture is not loading from the disk. Spent too much time on getting the library right this morning that I could not work on that before I had to go to work Oh well, Ill look into that in the morning....

  7. #7
    Darkness Prevails Dark_Phoenix's Avatar
    Join Date
    Oct 2006
    Location
    Houston, Texas
    Posts
    174
    One more quick question.... If I installed the debug version of the dx9 sdk, then I have to link to d3dx9d instead of d3dx9, correct? I assume this is true as the dx9 install did not give me a d3dx9 library file, only the 'd' version.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Applied philosophy refresher
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 04-28-2009, 09:55 PM
  2. Need a refresher, the difference between static and dynamic.
    By indigo0086 in forum C++ Programming
    Replies: 6
    Last Post: 06-27-2008, 02:28 AM
  3. Refresher..
    By jed in forum C++ Programming
    Replies: 6
    Last Post: 08-26-2006, 06:37 PM
  4. Replies: 3
    Last Post: 12-16-2002, 08:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21