Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[DirectX] Błąd: "unresolved external symbol _Direct3DCreate9@4"

Ostatnio zmodyfikowano 2011-09-28 21:10
Autor Wiadomość
DanX95X
Temat założony przez niniejszego użytkownika
[DirectX] Błąd: "unresolved external symbol _Direct3DCreate9@4"
» 2011-09-28 20:22:21
Siema.
Uczę się trochę Direct3D i próbowałem stworzyć własny obiekt ale nie chce mi się skompilować. Wyskakuje błąd:
1>sześciokąt.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "void __cdecl init(struct HWND__ *)" (?init@@YAXPAUHWND__@@@Z)

Wrzucam kod (trochę długi). Byłbym wdzięczny jeśli ktoś mi pomoże.

C/C++
#include <Windows.h>
#include <d3d9.h>

#define S_W 640
#define S_H 480
#define C_FVF (D3DFVF_DIFFUSE|D3DFVF_XYZRHW)

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
LPDIRECT3DVERTEXBUFFER9 v_buffer;

void init( HWND hWnd );
void render();
void color();
void graphics();
void clean();

struct c_vertex {
    float x, y, z, rhw;
    DWORD color;
};

short faza = 1;

c_vertex vertices[] = {
    { 300.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 255, 0, 0 ), },
    { 400.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 0, 255, 0 ), },
    { 450.0f, 136.5f, 0.5f, 1.0f, D3DCOLOR_XRGB( 0, 0, 255 ), },
    { 400.0f, 223.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 255, 255, 0 ), },
    { 300.0f, 223.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 0, 255, 255 ), },
    { 250.0f, 136.5f, 0.5f, 1.0f, D3DCOLOR_XRGB( 255, 0, 255 ), },
};


LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
    HWND hWnd;
   
    WNDCLASSEX wc;
    ZeroMemory( & wc, sizeof( WNDCLASSEX ) );
   
    wc.cbSize = sizeof( WNDCLASSEX );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hInstance = hInstance;
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = L"class";
    wc.style = CS_HREDRAW | CS_VREDRAW;
   
    RegisterClassEx( & wc );
   
    hWnd = CreateWindowEx( NULL,
    L"class",
    L"Sześciokąt",
    WS_OVERLAPPEDWINDOW,
    0, 0,
    S_W, S_H,
    NULL, NULL,
    hInstance, NULL );
   
    ShowWindow( hWnd, nCmdShow );
   
    init( hWnd );
   
    MSG msg;
   
    while( TRUE ) {
        while( PeekMessage( & msg, NULL, 0, 0, PM_REMOVE ) ) {
            TranslateMessage( & msg );
            DispatchMessage( & msg );
        }
        if( msg.message == WM_QUIT ) break;
       
        render();
    }
    clean();
    return msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {
    switch( message ) {
    case WM_DESTROY:
        PostQuitMessage( 0 );
        return 0;
    }
    return DefWindowProc( hWnd, message, wParam, lParam );
}

void init( HWND hWnd ) {
    d3d = Direct3DCreate9( D3D_SDK_VERSION );
    D3DPRESENT_PARAMETERS d3dpp;
   
    ZeroMemory( & d3dpp, sizeof( d3dpp ) );
    d3dpp.Windowed = TRUE;
    d3dpp.hDeviceWindow = hWnd;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferWidth = S_W;
    d3dpp.BackBufferHeight = S_H;
   
   
    d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, & d3dpp, & d3ddev );
   
    d3ddev->CreateVertexBuffer( 6 * sizeof( c_vertex ), 0, C_FVF, D3DPOOL_MANAGED, & v_buffer, NULL );
}

void color() {
    switch( faza ) {
    case 1:
        Sleep( 1000 );
        vertices[ 0 ].color = D3DCOLOR_XRGB( 255, 0, 0 );
        vertices[ 1 ].color = D3DCOLOR_XRGB( 0, 255, 0 );
        vertices[ 2 ].color = D3DCOLOR_XRGB( 0, 0, 255 );
        vertices[ 3 ].color = D3DCOLOR_XRGB( 255, 255, 0 );
        vertices[ 4 ].color = D3DCOLOR_XRGB( 0, 255, 255 );
        vertices[ 5 ].color = D3DCOLOR_XRGB( 255, 0, 255 );
        faza++;
        break;
    case 2:
        Sleep( 1000 );
        vertices[ 0 ].color = D3DCOLOR_XRGB( 0, 255, 0 );
        vertices[ 1 ].color = D3DCOLOR_XRGB( 0, 0, 255 );
        vertices[ 2 ].color = D3DCOLOR_XRGB( 255, 255, 0 );
        vertices[ 3 ].color = D3DCOLOR_XRGB( 0, 255, 255 );
        vertices[ 4 ].color = D3DCOLOR_XRGB( 255, 0, 255 );
        vertices[ 5 ].color = D3DCOLOR_XRGB( 255, 0, 0 );
        faza++;
        break;
    case 3:
        Sleep( 1000 );
        vertices[ 0 ].color = D3DCOLOR_XRGB( 0, 0, 255 );
        vertices[ 1 ].color = D3DCOLOR_XRGB( 255, 255, 0 );
        vertices[ 2 ].color = D3DCOLOR_XRGB( 0, 255, 255 );
        vertices[ 3 ].color = D3DCOLOR_XRGB( 255, 0, 255 );
        vertices[ 4 ].color = D3DCOLOR_XRGB( 255, 0, 0 );
        vertices[ 5 ].color = D3DCOLOR_XRGB( 0, 255, 0 );
        faza++;
        break;
    case 4:
        Sleep( 1000 );
        vertices[ 0 ].color = D3DCOLOR_XRGB( 255, 255, 0 );
        vertices[ 1 ].color = D3DCOLOR_XRGB( 0, 255, 255 );
        vertices[ 2 ].color = D3DCOLOR_XRGB( 255, 0, 255 );
        vertices[ 3 ].color = D3DCOLOR_XRGB( 255, 0, 0 );
        vertices[ 4 ].color = D3DCOLOR_XRGB( 0, 255, 0 );
        vertices[ 5 ].color = D3DCOLOR_XRGB( 0, 0, 255 );
        faza++;
        break;
    case 5:
        Sleep( 1000 );
        vertices[ 0 ].color = D3DCOLOR_XRGB( 0, 255, 255 );
        vertices[ 1 ].color = D3DCOLOR_XRGB( 255, 0, 255 );
        vertices[ 2 ].color = D3DCOLOR_XRGB( 255, 0, 0 );
        vertices[ 3 ].color = D3DCOLOR_XRGB( 0, 255, 0 );
        vertices[ 4 ].color = D3DCOLOR_XRGB( 0, 0, 255 );
        vertices[ 5 ].color = D3DCOLOR_XRGB( 255, 255, 0 );
        faza++;
        break;
    case 6:
        Sleep( 1000 );
        vertices[ 0 ].color = D3DCOLOR_XRGB( 255, 0, 255 );
        vertices[ 1 ].color = D3DCOLOR_XRGB( 255, 0, 0 );
        vertices[ 2 ].color = D3DCOLOR_XRGB( 0, 255, 0 );
        vertices[ 3 ].color = D3DCOLOR_XRGB( 0, 0, 255 );
        vertices[ 4 ].color = D3DCOLOR_XRGB( 255, 255, 0 );
        vertices[ 5 ].color = D3DCOLOR_XRGB( 0, 255, 255 );
        faza++;
        break;
    }
   
    void * pvoid;
   
    v_buffer->Lock( 0, 0,( void ** ) & pvoid, 0 );
   
    memcpy( pvoid, vertices, sizeof( vertices ) );
   
    v_buffer->Unlock();
}

void render() {
    d3ddev->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 );
   
    d3ddev->BeginScene();
    color();
   
    d3ddev->SetFVF( C_FVF );
    d3ddev->SetStreamSource( 0, v_buffer, 0, sizeof( c_vertex ) );
    d3ddev->DrawPrimitive( D3DPT_LINESTRIP, 0, 1 );
    d3ddev->EndScene();
    d3ddev->Present( NULL, NULL, NULL, NULL );
}

void clean() {
    v_buffer->Release();
    d3d->Release();
    d3ddev->Release();
}
P-41522
DejaVu
» 2011-09-28 20:43:26
To jest błąd linkera, a nie kompilatora. Wklej błąd w wyszukiwarkę google, a dostaniesz nazwę biblioteki jaką należy dolinkować do projektu aby kompilacja zakończyła się sukcesem.
P-41523
DanX95X
Temat założony przez niniejszego użytkownika
» 2011-09-28 21:10:48
Ok dzięki. Znalazłem to czego mi brakowało
P-41524
« 1 »
  Strona 1 z 1