DirectX + Visual Studio 2008, ошибки компиляции.

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by Indev, 25 Feb 2012.

  1. Indev

    Indev New Member

    Joined:
    23 Dec 2011
    Messages:
    59
    Likes Received:
    3
    Reputations:
    0
    При компиляции кода:
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include "d3d9.h"
    #include "d3dx9.h"
    #include <tchar.h>
    
    HWND          g_hWnd;
    HINSTANCE     g_hInst;
    static TCHAR   g_szClass[]   = _T("Draw3DClass");
    static TCHAR   g_szCaption[] = _T("Draw3D");
    
    
    IDirect3D9       *g_pD3D       = NULL;
    IDirect3DDevice9 *g_pD3DDevice = NULL;
    
    
    typedef struct {
      FLOAT x, y, z;     
      FLOAT u, v;        
    } sVertex;
    #define VERTEXFVF (D3DFVF_XYZ | D3DFVF_TEX1)
    
    
    IDirect3DVertexBuffer9 *g_pVB = NULL;
    
    
    IDirect3DTexture9 *g_pTexture = NULL;
    
    
    int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,
                       LPSTR szCmdLine, int nCmdShow);
    long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,
                               WPARAM wParam, LPARAM lParam);
    
    BOOL DoInit();
    BOOL DoShutdown();
    BOOL DoFrame();
    BOOL SetupMeshes();
    
    int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,
                       LPSTR szCmdLine, int nCmdShow)
    {
      WNDCLASSEX wcex;
      MSG        Msg;
    
      g_hInst = hInst;
    
    
      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 = g_szClass;
      wcex.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
      if(!RegisterClassEx(&wcex))
        return FALSE;
    
    
      g_hWnd = CreateWindow(g_szClass, g_szCaption,
            WS_CAPTION | WS_SYSMENU,
            0, 0, 960, 640,
            NULL, NULL,
            hInst, NULL );
      if(!g_hWnd)
        return FALSE;
      ShowWindow(g_hWnd, SW_NORMAL);
      UpdateWindow(g_hWnd);
    
    
      if(DoInit() == FALSE)
        return FALSE;
    
    
      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;
      }
    
    
      DoShutdown();
      
      UnregisterClass(g_szClass, hInst);
    
      return Msg.wParam;
    }
    
    long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,
                               WPARAM wParam, LPARAM lParam)
    {
      switch(uMsg) {
        case WM_DESTROY:
          PostQuitMessage(0);
          return 0;
    
      }
    
      return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    
    BOOL DoInit()
    {
      D3DPRESENT_PARAMETERS d3dpp;
      D3DDISPLAYMODE        d3ddm;
      D3DXMATRIX matProj, matView;
      BYTE *Ptr;
      sVertex Verts[4] = {
          { -100.0f,  100.0f, 0.0f, 0.0f, 0.0f },
          {  100.0f,  100.0f, 0.0f, 1.0f, 0.0f },
          { -100.0f, -100.0f, 0.0f, 0.0f, 1.0f },
          {  100.0f, -100.0f, 0.0f, 1.0f, 1.0f }
        };
    
    
      if((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
        return FALSE;
      if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
        return FALSE;
      ZeroMemory(&d3dpp, sizeof(d3dpp));
      d3dpp.Windowed = TRUE;
      d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
      d3dpp.BackBufferFormat = d3ddm.Format;
      d3dpp.EnableAutoDepthStencil = TRUE;
      d3dpp.AutoDepthStencilFormat = D3DFMT_D32;
      if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &g_pD3DDevice)))
        return FALSE;
    
    
      g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
      g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
    
    
      D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4.0f, 1.5f, 1.0f, 1000.0f);
      g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);
    
    
      D3DXMatrixLookAtLH(&matView,                                
                         &D3DXVECTOR3(0.0f, 0.0f, -300.0f),       
                         &D3DXVECTOR3(0.0f, 0.0f, 0.0f),          
                         &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
      g_pD3DDevice->SetTransform(D3DTS_VIEW, &matView);
    
    
      g_pD3DDevice->CreateVertexBuffer(sizeof(sVertex)*4, 0,      
                              VERTEXFVF, D3DPOOL_DEFAULT,         
                              &g_pVB, NULL);
      g_pVB->Lock(0,0, (void**)&Ptr, 0);
      memcpy(Ptr, Verts, sizeof(Verts));
      g_pVB->Unlock();
    
    
      D3DXCreateTextureFromFile(g_pD3DDevice,(LPCWSTR)"Texture.bmp", &g_pTexture);
    
      return TRUE;
    }
    
    BOOL DoShutdown()
    {
    
      if(g_pVB != NULL)
        g_pVB->Release();
    
    
      if(g_pTexture != NULL)
        g_pTexture->Release();
    
    
      if(g_pD3DDevice != NULL)
        g_pD3DDevice->Release();
    
      if(g_pD3D != NULL)
        g_pD3D->Release();
    
      return TRUE;
    }
    
    BOOL DoFrame()
    {
      D3DXMATRIX matWorld;
    
    
      g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 
                          D3DCOLOR_RGBA(175,173,175,255), 1.0f, 0);
    
    
      if(SUCCEEDED(g_pD3DDevice->BeginScene())) {
    
        D3DXMatrixRotationZ(&matWorld, (float)timeGetTime() / 1000.0f);
        g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
    
    
        g_pD3DDevice->SetStreamSource(0, g_pVB, 0, sizeof(sVertex));
        g_pD3DDevice->SetFVF(VERTEXFVF);
        g_pD3DDevice->SetTexture(0, g_pTexture);
    
    
        g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
    
    
        g_pD3DDevice->SetTexture(0, NULL);
    
    
        g_pD3DDevice->EndScene();
      }
    
    
      g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
    
      return TRUE;
    }
    Выводит такие ошибки:
    В <Сервис> --> <Параметры> --> <Каталоги VC++> подключил либы и заголовочные файлы. Что делать?
     
  2. m1nt@ll

    m1nt@ll New Member

    Joined:
    9 Feb 2012
    Messages:
    19
    Likes Received:
    1
    Reputations:
    0
    А либы подключил? d3d10.lib если не ошибаюсь...
     
  3. GRRRL Power

    GRRRL Power Elder - Старейшина

    Joined:
    13 Jul 2010
    Messages:
    823
    Likes Received:
    185
    Reputations:
    84
    D3D9.lib, D3dx9.lib. Возможно, еще какие-то либы нужны будут.

    Вот это еще сомнительный каст. Скорее надо написать
    Code:
    D3DXCreateTextureFromFile(g_pD3DDevice, L"Texture.bmp", &g_pTexture);
    
     
  4. Indev

    Indev New Member

    Joined:
    23 Dec 2011
    Messages:
    59
    Likes Received:
    3
    Reputations:
    0
    Проблему решил. Либы нужно было дополнительно прописать в
    <Свойства> --> <Свойства проекта> --> <Компоновщик> --> <Ввод> --> <Доп. зависимости>
    Вопрос закрыт.