D3D9 - Text & ein simples Fenster
-
Hi Pros,
hier spricht der low.
Ich habe seit kurzem mit D3D angefangen (bzw. auch mit C++) und fange gerade an zu verzweifeln.
Auf einer Website (ka ob ich Link posten darf) habe ich das Tutorial gemacht, ging alles: SUPER!Ich hatte also eine Anwendung, die ein Fenster öffnet und dieses blau ist. Ich war schonmal ziemlich Happy.
Nun wollte ich aber gerne noch Text mit D3D einfügen. Ist ja mit "ID3DXFont" wohl einfach. Nun gibt es aber folgendes Problem.(Als erstes mal den Code)
// include the basic windows header files and the Direct3D header file #include "stdafx.h" // define the screen resolution #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 // include the Direct3D Library file #pragma comment (lib, "d3d9.lib") // global declarations LPDIRECT3D9 d3d; LPDIRECT3DDEVICE9 d3ddev; ID3DXFont *m_font; // function prototypes void initD3D(HWND hWnd); // sets up and initializes Direct3D void render_frame(void); // renders a single frame void cleanD3D(void); // closes Direct3D and releases memory // the WindowProc function prototype LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // the entry point for any Windows program int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); // wc.hbrBackground = (HBRUSH)COLOR_WINDOW; // not needed any more wc.lpszClassName = L"WindowClass"; RegisterClassEx(&wc); hWnd = CreateWindowEx(NULL, L"WindowClass", L"Our Direct3D Program", WS_EX_TOPMOST | WS_POPUP, // fullscreen values 0, 0, // the starting x and y positions should be 0 SCREEN_WIDTH, SCREEN_HEIGHT, // set the window to 640 x 480 NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); // set up and initialize Direct3D initD3D(hWnd); // enter the main loop: MSG msg; while(TRUE) { while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if(msg.message == WM_QUIT) break; render_frame(); } // clean up DirectX and COM cleanD3D(); return msg.wParam; } HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc ) { return S_OK; } // this is the main message handler for the program LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: { PostQuitMessage(0); return 0; } break; } return DefWindowProc (hWnd, message, wParam, lParam); } // this function initializes and prepares Direct3D for use void initD3D(HWND hWnd) { d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear out the struct for use d3dpp.Windowed = FALSE; // program fullscreen, not windowed d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit d3dpp.BackBufferWidth = SCREEN_WIDTH; // set the width of the buffer d3dpp.BackBufferHeight = SCREEN_HEIGHT; // set the height of the buffer // create a device class using this information and the info from the d3dpp stuct d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); D3DXCreateFont( d3ddev, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &m_font ); } // this is the function used to render a single frame void render_frame(void) { // clear the window to a deep blue d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); d3ddev->BeginScene(); // begins the 3D scene // DO THE RENDERING D3DCOLOR fontColor = D3DCOLOR_ARGB(255,255,0,0); RECT rct; rct.left=2; rct.right=780; rct.top=10; rct.bottom=rct.top+20; SetRect(&rct,0,0,800,600); m_font->DrawText(NULL, L"Hello World", -1, &rct, DT_LEFT | DT_NOCLIP, fontColor ); // /DO THE RENDERING d3ddev->EndScene(); // ends the 3D scene d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame on the screen } // this is the function that cleans up Direct3D and COM void cleanD3D(void) { d3ddev->Release(); // close and release the 3D device d3d->Release(); // close and release Direct3D m_font->Release(); }
Ich klicke auf erstellen. So und nun kommt folgender Fehler:
1>------ Erstellen gestartet: Projekt: test1, Konfiguration: Debug Win32 ------ 1>Kompilieren... 1>DisplaySomeText.cpp 1>Verknüpfen... 1>DisplaySomeText.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_D3DXCreateFontW@48". 1>C:\Users\Jan\Desktop\Programmieren\C-C++\d3d\test1\test1\Debug\test1.exe : fatal error LNK1120: 1 nicht aufgelöste externe Verweise. 1>Das Buildprotokoll wurde unter "file://c:\Users\Jan\Desktop\Programmieren\C-C++\d3d\test1\test1\test1\Debug\BuildLog.htm" gespeichert. 1>test1 - 2 Fehler, 0 Warnung(en) ========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
Hat jemand eine Idee woran das liegt bzw. wie ich das fixen kann?
-
Du hast vergessen, d3dx9.lib zu linken.
Btw: Das sollte wohl eher dahin.
-
Danke schonmal für die schnelle Antwort.
Nun kommt aber noch ein Fehler -.-!Geändert:
// include the basic windows header files and the Direct3D header file #include "stdafx.h" // define the screen resolution #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 // include the Direct3D Library file #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib"
stdafx.h:
#include <windows.h> #include <windowsx.h> #include <d3d9.h> #include <d3dx9.h>
Fehler:
1>------ Erstellen gestartet: Projekt: test1, Konfiguration: Debug Win32 ------ 1>Kompilieren... 1>DisplaySomeText.cpp 1>Verknüpfen... 1>LINK : fatal error LNK1104: Datei "d3dx9.lib" kann nicht geöffnet werden. 1>Das Buildprotokoll wurde unter "file://c:\Users\Jan\Desktop\Programmieren\C-C++\d3d\test1\test1\test1\Debug\BuildLog.htm" gespeichert. 1>test1 - 1 Fehler, 0 Warnung(en) ========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
-
Naja, der Compiler findet die lib wohl nicht. Ist wohl was mit deinen Pfaden durcheinander...
-
Meine Includes sind:
C:\Program Files (x86)\Microsoft DirectX 9.0 SDK (Summer 2004)\Include C:\Program Files (x86)\Microsoft DirectX SDK (August 2007)\Lib\x86 C:\Program Files (x86)\Microsoft DirectX SDK (August 2007)\Include
-
Mit den Includes hat das aber nix zu tun. Das ist ein Linkerfehler. Das Problem ist der lib-Pfad, den du offenbar versehentlich zu den include-Pfaden gepackt hast...
-
D3Dlow schrieb:
Ich habe seit kurzem mit D3D angefangen (bzw. auch mit C++)
Fail.
-
Vielen Dank!
Damit hast du mir gerade (sry aber) SCHEIßE viel Aufregung "abgenommen"..
Nochmals Vielen Dank und Daumen hoch!