directx 8

This is a discussion on directx 8 within the Windows Programming forums, part of the Platform Specific Boards category; I'm using the andy pike tutorials of Directx 8 and i'm using Dev C++. The problem is i can't get ...

  1. #1
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161

    directx 8

    I'm using the andy pike tutorials of Directx 8 and i'm using Dev C++. The problem is i can't get the first tutorial to compile. In Dev C++ i create a windows application but when i try and compile the below it says that the header file d3d8.h doesn't exist.

    Code:
    #include <d3d8.h>
    
    LPDIRECT3D8 g_pD3D = NULL;
    LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;
    
    HRESULT InitialiseD3D(HWND hWnd)
    {
        //First of all, create the main D3D object. If it is created successfully we
        //should get a pointer to an IDirect3D8 interface.
        g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
        if(g_pD3D == NULL)
        {
            return E_FAIL;
        }
    
        //Get the current display mode
        D3DDISPLAYMODE d3ddm;
        if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
        {
            return E_FAIL;
        }
    
        //Create a structure to hold the settings for our device
        D3DPRESENT_PARAMETERS d3dpp;
        ZeroMemory(&d3dpp, sizeof(d3dpp));
    
        //Fill the structure.
        //We want our program to be windowed, and set the back buffer to a format
        //that matches our current display mode
        d3dpp.Windowed = TRUE;
        d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
        d3dpp.BackBufferFormat = d3ddm.Format;
    
        //Create a Direct3D device.
        if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                       D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
        {
            return E_FAIL;
        }
        
        return S_OK;
    }
    
    void Render()
    {
        if(g_pD3DDevice == NULL)
        {
            return;
        }
    
        //Clear the backbuffer to a green color
        g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
        
        //Begin the scene
        g_pD3DDevice->BeginScene();
        
        //Rendering of our game objects will go here
        
        //End the scene
        g_pD3DDevice->EndScene();
        
        //Filp the back and front buffers so that whatever has been rendered on the back buffer
        //will now be visible on screen (front buffer).
        g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
    }
    
    void CleanUp()
    {
        if(g_pD3DDevice != NULL)
        {
            g_pD3DDevice->Release();
            g_pD3DDevice = NULL;
        }
    
        if(g_pD3D != NULL)
        {
            g_pD3D->Release();
            g_pD3D = NULL;
        }
    }
    
    void GameLoop()
    {
        //Enter the game loop
        MSG msg;
        BOOL fMessage;
    
        PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
        
        while(msg.message != WM_QUIT)
        {
            fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);
    
            if(fMessage)
            {
                //Process message
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
            else
            {
                //No message to process, so render the current scene
                Render();
            }
    
        }
    }
    
    //The windows message handler
    LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
            break;
            case WM_KEYUP:
                switch (wParam)
                {
                    case VK_ESCAPE:
                        //User has pressed the escape key, so quit
                        DestroyWindow(hWnd);
                        return 0;
                    break;
                }
            break;
    
        }
    
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    
    //Application entry point
    INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
    {
        //Register the window class
        WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L,
                         GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                         "DX Project 1", NULL};
        RegisterClassEx(&wc);
    
        //Create the application's window
        HWND hWnd = CreateWindow("DX Project 1", "www.andypike.com: Tutorial 1",
                                  WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,
                                  GetDesktopWindow(), NULL, wc.hInstance, NULL);
    
        //Initialize Direct3D
        if(SUCCEEDED(InitialiseD3D(hWnd)))
        {
            //Show our window
            ShowWindow(hWnd, SW_SHOWDEFAULT);
            UpdateWindow(hWnd);
    
            //Start game running: Enter the game loop
            GameLoop();
        }
        
        CleanUp();
    
        UnregisterClass("DX Project 1", wc.hInstance);
        
        return 0;
    }
    I started out with nothing and I still have most of it left.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Have you tried setting "Additional Include Paths" to point to where the DirectX 8 SDK is installed? You normally have to set paths for both the Includes and Library files. I'm not sure how to do this exactly with Dev-Cpp but either read the documentation or just poke around.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Isometric Tile Engine using DirectX
    By Wraithan in forum Game Programming
    Replies: 3
    Last Post: 07-17-2006, 12:16 PM
  2. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 06:16 PM
  3. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-24-2004, 11:49 PM
  4. DirectX 8 with Borland
    By Tommaso in forum Game Programming
    Replies: 11
    Last Post: 08-12-2003, 09:30 AM
  5. Directx SDK Documentation
    By Zoalord in forum Game Programming
    Replies: 4
    Last Post: 05-08-2003, 06:07 AM

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