MrOsamaful Temat założony przez niniejszego użytkownika |
[DirectX]Problem z linkerem. » 2010-11-22 20:51:17 Linker coś "odwala", prawdopodobnie nie może odnaleźć lib'ów d3d9.lib i d3dx9.lib chociaż je dodałem, ostatnio hulało bez problemów a teraz nie wiem czemu nie działa. Ogólnie jestem newbem więc nie bądźcie surowi ^^
#include <windows.h> #include <tchar.h> #include <d3d9.h> #include <d3dx9.h> #include <fstream> #include <vector> using namespace std;
IDirect3D9 * pD3D = 0; IDirect3DDevice9 * pD3DDevice = 0;
IDirect3DVertexBuffer9 * pVBsciany = 0; IDirect3DVertexBuffer9 * pVBpodlogi = 0;
IDirect3DIndexBuffer9 * pIBsciany = 0; IDirect3DIndexBuffer9 * pIBpodlogi = 0;
IDirect3DTexture9 * pTextureS = 0; IDirect3DTexture9 * pTextureP = 0;
HRESULT hr;
struct Vertex { Vertex( FLOAT x, FLOAT y, FLOAT z, FLOAT u, FLOAT v ) : x( x ) , y( y ) , z( z ) , u( u ) , v( v ) { } FLOAT x, y, z; FLOAT u, v; }; #define FVF_VERTEX ( D3DFVF_XYZ | D3DFVF_TEX1 )
int num_v = 0; int num_sciany = 0; int num_podlogi = 0;
int mapa_size[ 3 ] = { 0, 0, 0 };
struct mapa_node { char przejscie[ 3 ][ 2 ]; };
vector < mapa_node > mapa; #define V(x,y,z) ((x) + (y)*(mapa_size[ 0 ]+1) + (z)*(mapa_size[ 0 ]+1)*(mapa_size[ 1 ]+1) ) #define MAPA(x,y,z) mapa[(x) + (y)*mapa_size[0] + (z)*mapa_size[0]*mapa_size[1]]
ifstream file;
D3DXVECTOR3 pozycja; D3DXVECTOR3 kierunek; D3DXVECTOR3 gora;
D3DXVECTOR3 pozycja_real; D3DXVECTOR3 kierunek_real; D3DXVECTOR3 gora_real;
char klawisze[ 256 ];
LRESULT WINAPI WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_DESTROY: PostQuitMessage( 0 ); return 0; case WM_KEYDOWN: klawisze[ wParam ] = 1; return 0; case WM_KEYUP: klawisze[ wParam ] = 0; return 0; } return DefWindowProc( hWnd, msg, wParam, lParam ); }
void Przesun( D3DXVECTOR3 & vec ) { mapa_node & node = MAPA(( UINT ) pozycja.x,( UINT ) pozycja.y,( UINT ) pozycja.z ); if( vec.x > 0.9 && node.przejscie[ 0 ][ 1 ] ) pozycja += vec; if( vec.x <- 0.9 && node.przejscie[ 0 ][ 0 ] ) pozycja += vec; if( vec.y > 0.9 && node.przejscie[ 1 ][ 1 ] ) pozycja += vec; if( vec.y <- 0.9 && node.przejscie[ 1 ][ 0 ] ) pozycja += vec; if( vec.z > 0.9 && node.przejscie[ 2 ][ 1 ] ) pozycja += vec; if( vec.z <- 0.9 && node.przejscie[ 2 ][ 0 ] ) pozycja += vec; }
void Input() { if( klawisze[ 'W' ] ) { Przesun( kierunek ); klawisze[ 'W' ] = 0; } if( klawisze[ 'S' ] ) { Przesun( - kierunek ); klawisze[ 'S' ] = 0; } if( klawisze[ 'A' ] ) { D3DXVECTOR3 v; D3DXVec3Cross( & v, & kierunek, & gora ); Przesun( v ); klawisze[ 'A' ] = 0; } if( klawisze[ 'D' ] ) { D3DXVECTOR3 v; D3DXVec3Cross( & v, & gora, & kierunek ); Przesun( v ); klawisze[ 'D' ] = 0; } if( klawisze[ VK_SPACE ] ) { Przesun( gora ); klawisze[ VK_SPACE ] = 0; } if( klawisze[ VK_CONTROL ] ) { Przesun( - gora ); klawisze[ VK_CONTROL ] = 0; } if( klawisze[ VK_LEFT ] ) { D3DXMATRIX mat; D3DXMatrixRotationAxis( & mat, & gora, - D3DX_PI / 2 ); D3DXVec3TransformCoord( & kierunek, & kierunek, & mat ); klawisze[ VK_LEFT ] = 0; } if( klawisze[ VK_RIGHT ] ) { D3DXMATRIX mat; D3DXMatrixRotationAxis( & mat, & gora, D3DX_PI / 2 ); D3DXVec3TransformCoord( & kierunek, & kierunek, & mat ); klawisze[ VK_RIGHT ] = 0; } if( klawisze[ VK_UP ] ) { D3DXVECTOR3 v = kierunek; kierunek = - gora; gora = v; klawisze[ VK_UP ] = 0; } if( klawisze[ VK_DOWN ] ) { D3DXVECTOR3 v = kierunek; kierunek = gora; gora = - v; klawisze[ VK_DOWN ] = 0; } if( klawisze[ VK_DELETE ] ) { D3DXMATRIX mat; D3DXMatrixRotationAxis( & mat, & kierunek, D3DX_PI / 2 ); D3DXVec3TransformCoord( & gora, & gora, & mat ); klawisze[ VK_DELETE ] = 0; } if( klawisze[ VK_NEXT ] ) { D3DXMATRIX mat; D3DXMatrixRotationAxis( & mat, & kierunek, - D3DX_PI / 2 ); D3DXVec3TransformCoord( & gora, & gora, & mat ); klawisze[ VK_NEXT ] = 0; } }
void Render() { pozycja_real = 0.9 * pozycja_real + 0.1 * pozycja; kierunek_real = 0.9 * kierunek_real + 0.1 * kierunek; gora_real = 0.9 * gora_real + 0.1 * gora; pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 50, 40, 30 ), 1.0f, 0 ); hr = pD3DDevice->BeginScene(); if( FAILED( hr ) ) return; D3DXMATRIXA16 matView; D3DXMatrixLookAtLH( & matView, & pozycja_real, &( pozycja_real + kierunek_real ), & gora_real ); pD3DDevice->SetTransform( D3DTS_VIEW, & matView ); D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( & matProj, D3DX_PI / 1.9f, 8.0 / 6.0, 0.1f, 100.0f ); pD3DDevice->SetTransform( D3DTS_PROJECTION, & matProj ); pD3DDevice->SetFVF( FVF_VERTEX ); pD3DDevice->SetTexture( 0, pTextureS ); pD3DDevice->SetStreamSource( 0, pVBsciany, 0, sizeof( Vertex ) ); pD3DDevice->SetIndices( pIBsciany ); pD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0U, num_v, 0U, num_sciany * 2 ); pD3DDevice->SetTexture( 0, pTextureP ); pD3DDevice->SetStreamSource( 0, pVBpodlogi, 0, sizeof( Vertex ) ); pD3DDevice->SetIndices( pIBpodlogi ); pD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0U, num_v, 0U, num_podlogi * 2 ); pD3DDevice->EndScene(); pD3DDevice->Present( NULL, NULL, NULL, NULL ); }
int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE, LPTSTR, INT ) { WNDCLASSEX wc; ZeroMemory( & wc, sizeof( WNDCLASSEX ) ); wc.cbSize = sizeof( WNDCLASSEX ); wc.style = CS_CLASSDC; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.lpszClassName = _T( "LabiryntWndClass" ); RegisterClassEx( & wc ); HWND hWnd = CreateWindow( _T( "LabiryntWndClass" ), _T( "Trójwymiarowy labirynt ;)" ), WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL ); pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( !pD3D ) goto WinMain_end; D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( & d3dpp, sizeof( d3dpp ) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, & d3dpp, & pD3DDevice ); if( FAILED( hr ) ) goto WinMain_end; file.open( _T( "mapa1.txt" ) ); file >> mapa_size[ 0 ] >> mapa_size[ 1 ] >> mapa_size[ 2 ]; mapa.resize( mapa_size[ 0 ] * mapa_size[ 1 ] * mapa_size[ 2 ] ); int x, y, z; file >> x >> y >> z; pozycja = D3DXVECTOR3( x + 0.5, y + 0.5, z + 0.5 ); kierunek = D3DXVECTOR3( 1, 0, 0 ); gora = D3DXVECTOR3( 0, 1, 0 ); pozycja_real = pozycja; kierunek_real = kierunek; gora_real = gora; num_v =( mapa_size[ 0 ] + 1 ) *( mapa_size[ 1 ] + 1 ) *( mapa_size[ 2 ] + 1 ); hr = pD3DDevice->CreateVertexBuffer( num_v * sizeof( Vertex ), 0, FVF_VERTEX, D3DPOOL_DEFAULT, & pVBsciany, NULL ); if( FAILED( hr ) ) goto WinMain_end; hr = pD3DDevice->CreateVertexBuffer( num_v * sizeof( Vertex ), 0, FVF_VERTEX, D3DPOOL_DEFAULT, & pVBpodlogi, NULL ); if( FAILED( hr ) ) goto WinMain_end; Vertex * pVerticesS, * pVerticesP; hr = pVBsciany->Lock( 0, 0,( void ** ) & pVerticesS, 0 ); if( FAILED( hr ) ) goto WinMain_end; hr = pVBpodlogi->Lock( 0, 0,( void ** ) & pVerticesP, 0 ); if( FAILED( hr ) ) { pVBsciany->Unlock(); goto WinMain_end; } for( int z = 0; z <= mapa_size[ 2 ]; ++z ) for( int y = 0; y <= mapa_size[ 1 ]; ++y ) for( int x = 0; x <= mapa_size[ 0 ]; ++x ) { pVerticesS[ V( x, y, z ) ] = Vertex(( FLOAT ) x,( FLOAT ) y,( FLOAT ) z,( FLOAT )( x + z ),( FLOAT )( y ) ); pVerticesP[ V( x, y, z ) ] = Vertex(( FLOAT ) x,( FLOAT ) y,( FLOAT ) z,( FLOAT )( x ),( FLOAT )( z ) ); } pVBsciany->Unlock(); pVBpodlogi->Unlock(); for( int z = 0; z < mapa_size[ 2 ]; ++z ) for( int y = 0; y < mapa_size[ 1 ]; ++y ) for( int x = 0; x < mapa_size[ 0 ]; ++x ) for( int wymiar = 0; wymiar < 3; ++wymiar ) for( int strona = 0; strona < 2; ++strona ) { int b; file >> b; MAPA( x, y, z ).przejscie[ wymiar ][ strona ] = b; if( !b && wymiar == 1 ) ++num_podlogi; if( !b && wymiar != 1 ) ++num_sciany; } file.close(); UINT * pS; pD3DDevice->CreateIndexBuffer( num_sciany * 2 * 3 * sizeof( UINT ), D3DUSAGE_DONOTCLIP, D3DFMT_INDEX32, D3DPOOL_DEFAULT, & pIBsciany, NULL ); pIBsciany->Lock( 0U, 0U,( void ** ) & pS, 0 ); UINT * pP; pD3DDevice->CreateIndexBuffer( num_podlogi * 2 * 3 * sizeof( UINT ), D3DUSAGE_DONOTCLIP, D3DFMT_INDEX32, D3DPOOL_DEFAULT, & pIBpodlogi, NULL ); pIBpodlogi->Lock( 0U, 0U,( void ** ) & pP, 0 ); for( int z = 0; z < mapa_size[ 2 ]; ++z ) for( int y = 0; y < mapa_size[ 1 ]; ++y ) for( int x = 0; x < mapa_size[ 0 ]; ++x ) for( int wymiar = 0; wymiar < 3; ++wymiar ) for( int strona = 0; strona < 2; ++strona ) if( !MAPA( x, y, z ).przejscie[ wymiar ][ strona ] ) { if( wymiar == 1 ) { * pP++ = V( x, y + strona, z ); * pP++ = V( x + strona, y + strona, z + 1 - strona ); * pP++ = V( x + 1 - strona, y + strona, z + strona ); * pP++ = V( x + 1, y + strona, z + 1 ); * pP++ = V( x + 1 - strona, y + strona, z + strona ); * pP++ = V( x + strona, y + strona, z + 1 - strona ); } else if( wymiar == 0 ) { * pS++ = V( x + strona, y, z ); * pS++ = V( x + strona, y + 1 - strona, z + strona ); * pS++ = V( x + strona, y + strona, z + 1 - strona ); * pS++ = V( x + strona, y + 1, z + 1 ); * pS++ = V( x + strona, y + strona, z + 1 - strona ); * pS++ = V( x + strona, y + 1 - strona, z + strona ); } else { * pS++ = V( x, y, z + strona ); * pS++ = V( x + 1 - strona, y + strona, z + strona ); * pS++ = V( x + strona, y + 1 - strona, z + strona ); * pS++ = V( x + 1, y + 1, z + strona ); * pS++ = V( x + strona, y + 1 - strona, z + strona ); * pS++ = V( x + 1 - strona, y + strona, z + strona ); } } pIBsciany->Unlock(); pIBpodlogi->Unlock(); pD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW ); pD3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); pD3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); D3DXCreateTextureFromFile( pD3DDevice, _T( "sciana.bmp" ), & pTextureS ); D3DXCreateTextureFromFile( pD3DDevice, _T( "podloga.bmp" ), & pTextureP ); ZeroMemory( & klawisze, sizeof( char ) * 256 ); ShowWindow( hWnd, SW_SHOWDEFAULT ); MSG msg; for(;; ) { if( !PeekMessage( & msg, NULL, 0U, 0U, PM_REMOVE ) ) { Input(); Render(); continue; } if( msg.message == WM_QUIT ) break; TranslateMessage( & msg ); DispatchMessage( & msg ); } if( 0 ) { WinMain_end: msg.wParam = 1; } if( pTextureS ) pTextureS->Release(); if( pTextureP ) pTextureP->Release(); if( pVBsciany ) pVBsciany->Release(); if( pVBpodlogi ) pVBpodlogi->Release(); if( pIBsciany ) pIBsciany->Release(); if( pIBpodlogi ) pIBpodlogi->Release(); if( pD3DDevice ) pD3DDevice->Release(); if( pD3D ) pD3D->Release(); UnregisterClass( _T( "LabiryntWndClass" ), hInstance ); return msg.wParam; }
Blędy:
Error 16 error LNK1120: 15 unresolved externals
Error 14 error LNK2019: unresolved external symbol __imp__CreateWindowExW@48 referenced in function _wWinMain@16
Error 1 error LNK2019: unresolved external symbol __imp__DefWindowProcW@16 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
Error 8 error LNK2019: unresolved external symbol __imp__DispatchMessageW@4 referenced in function _wWinMain@16
Error 10 error LNK2019: unresolved external symbol __imp__PeekMessageW@20 referenced in function _wWinMain@16
Error 2 error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
Error 15 error LNK2019: unresolved external symbol __imp__RegisterClassExW@4 referenced in function _wWinMain@16
Error 11 error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function _wWinMain@16
Error 9 error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function _wWinMain@16
Error 7 error LNK2019: unresolved external symbol __imp__UnregisterClassW@8 referenced in function _wWinMain@16
Error 12 error LNK2019: unresolved external symbol _D3DXCreateTextureFromFileW@12 referenced in function _wWinMain@16
Error 6 error LNK2019: unresolved external symbol _D3DXMatrixLookAtLH@16 referenced in function "void __cdecl Render(void)" (?Render@@YAXXZ)
Error 5 error LNK2019: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20 referenced in function "void __cdecl Render(void)" (?Render@@YAXXZ)
Error 4 error LNK2019: unresolved external symbol _D3DXMatrixRotationAxis@12 referenced in function "void __cdecl Input(void)" (?Input@@YAXXZ)
Error 3 error LNK2019: unresolved external symbol _D3DXVec3TransformCoord@12 referenced in function "void __cdecl Input(void)" (?Input@@YAXXZ)
Error 13 error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function _wWinMain@16
Używam visual express c++ 2010
Sdk mam najnowsze. Przypominam, że wcześniej działało :P |