Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
//DirectX_Init.h #ifndef _DIRECTX_INIT_ #define _DIRECTX_INIT_ class DirectX_Init { public: /********Funktinsdeklarationen***************/ //Fenster: tbResult InitWindow(int iWidth, int iHeight, char* pcName, HICON hIcon); tbResult ExitWindow(); tbResult DoMessageLoop(tbResult (* pRenderProc)(float), tbResult (* pMoveProc)(float)); LRESULT WINAPI WindowProc(HWND hWindow, unsigned int uiMessage, WPARAM WParam, LPARAM LParam); //DirectX: tbResult InitDirectX(); tbResult ExitDirectX(); tbResult InitAll() { tbInit(); InitWindow(1024,768,"Beispiel",0); InitDirectX(); return TB_OK; } tbResult ExitAll() { ExitWindow(); ExitDirectX(); tbExit(); return TB_OK; } }; #endif //Passt perfekt auf eine Seite |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
//DirectX_Init.cpp #include <TriBase.h> #include <D3D9.h> #include <windows.h> #include "DirectX_Init.h" #include "DirectX_Globals.h" /*******Fenster Initalisieren*********/ tbResult InitWindow(int iWidth, int iHeight, char* pcName, HICON hIcon) { // Fensterklassenstruktur ausfüllen WNDCLASSEX WindowClass = {sizeof(WNDCLASSEX), CS_CLASSDC, WindowProc, 0, 0, GetModuleHandle(NULL), hIcon, LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)), NULL, NULL, "Direct3D window", NULL}; // Klasse registrieren if(!RegisterClassEx(&WindowClass)) { TB_ERROR("Fensterklassenregistrierung fehlgeschlagen!", TB_ERROR); } TB_INFO("Fensterklasse wurde registriert!"); RECT Rect; SetRect(&Rect, 0, 0, iWidth, iHeight); AdjustWindowRect(&Rect, WS_VISIBLE | WS_OVERLAPPEDWINDOW, FALSE); iWidth = Rect.right - Rect.left; iHeight = Rect.bottom - Rect.top; // Fenster erstellen und prüfen g_hWindow = CreateWindow("Direct3D window", pcName, WS_VISIBLE | WS_OVERLAPPEDWINDOW, GetSystemMetrics(SM_CXSCREEN) / 2 - iWidth / 2, GetSystemMetrics(SM_CYSCREEN) / 2 - iHeight / 2, iWidth, iHeight, NULL, NULL, GetModuleHandle(NULL), NULL); if(g_hWindow == NULL) { TB_ERROR("Erstellung des Fensters ist fehlgeschlagen!\n", TB_ERROR); } // Alles OK! TB_INFO("Fenster wurde erstellt!"); return TB_OK; } /*************************************/ /*******Fenster herunterfahren********/ tbResult ExitWindow() { // Klasse löschen UnregisterClass("Direct3D window", GetModuleHandle(NULL)); TB_INFO("Fensterkomponente wurde heruntergefahren!"); return TB_OK; } /*************************************/ /*Die Nachrichtenfunktion des Fensters*/ LRESULT WINAPI WindowProc(HWND hWindow, unsigned int uiMessage, WPARAM WParam, LPARAM LParam) { PAINTSTRUCT Paint; switch(uiMessage) { case WM_CREATE: break; case WM_PAINT: // Das Fenster mit Schwarz füllen BeginPaint(hWindow, &Paint); FillRect(Paint.hdc, &Paint.rcPaint, (HBRUSH)(GetStockObject(BLACK_BRUSH))); EndPaint(hWindow, &Paint); break; case WM_CLOSE: DestroyWindow(hWindow); PostQuitMessage(0); break; default: return DefWindowProc(hWindow, uiMessage, WParam, LParam); } return TRUE; } /*********************************/ /****DirectX initalisieren********/ tbResult InitDirectX() { HRESULT hResult; D3DPRESENT_PARAMETERS PresentParams; // Globale IDirect3D9-Schnittstelle erzeugen g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); if(g_pD3D == NULL) TB_ERROR("IDirect3D9-Schnittstelle konnte nicht erstellt werden!", TB_ERROR); TB_INFO("IDirect3D9-Schnittstelle wurde erzeugt!"); // Präsentationsstruktur ausfüllen ZeroMemory(&PresentParams, sizeof(D3DPRESENT_PARAMETERS)); PresentParams.BackBufferWidth = 800; PresentParams.BackBufferHeight = 600; PresentParams.BackBufferFormat = D3DFMT_R5G6B5; PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE; PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD; PresentParams.hDeviceWindow = g_hWindow; PresentParams.Windowed = false; PresentParams.EnableAutoDepthStencil = true; PresentParams.AutoDepthStencilFormat = D3DFMT_D16;; UINT uiAdapter = g_pD3D->GetAdapterCount(); // Und nun die Geräteschnittstelle generieren if(FAILED(hResult = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresentParams, &g_pD3DDevice))) { MessageBox(g_hWindow,"DirectX Fehler","DX",MB_OK); // Fehler beim Generieren der Schnittstelle! TB_SAFE_RELEASE(g_pD3D); TB_SAFE_RELEASE(g_pD3DDevice); TB_ERROR_DIRECTX("g_pD3D->CreateDevice", hResult, TB_ERROR); } // Es hat geklappt! TB_INFO("Geräteschnittstelle wurde generiert!"); // Cursor ausblenden ShowCursor(FALSE); return TB_OK; } /*****DirectX herunterfahren*******/ tbResult ExitDirectX() { TB_SAFE_RELEASE(g_pD3D); TB_SAFE_RELEASE(g_pD3DDevice); return TB_OK; } /**********************************/ |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//DirectX_Globals.h #ifdef _DIRECTX_GLOBALS_CPP #undef VAR #define VAR #else #undef VAR #define VAR extern #endif /******Globale Variablen******/ static HWND g_hWindow(0); static PDIRECT3D9 g_pD3D(0); static PDIRECT3DDEVICE9 g_pD3DDevice(0); /******************************/ |
Zitat
1>DirectX_Init.obj : error LNK2005: "struct HWND__ * g_hWindow" (?g_hWindow@@3PAUHWND__@@A) ist bereits in DirectX_Globals.obj definiert.
1>DirectX_Init.obj : error LNK2005: "struct IDirect3D9 * g_pD3D" (?g_pD3D@@3PAUIDirect3D9@@A) ist bereits in DirectX_Globals.obj definiert.
1>DirectX_Init.obj : error LNK2005: "struct IDirect3DDevice9 * g_pD3DDevice" (?g_pD3DDevice@@3PAUIDirect3DDevice9@@A) ist bereits in DirectX_Globals.obj definiert.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <TriBase.h> #include <D3D9.h> #include <windows.h> #include "C:\Dokumente und Einstellungen\GliderBugFix\Desktop\MyClasses\Second Release\DirectX_Init.h" tbResult Render(float fNumSecsPassed) { return TB_OK; } tbResult Move(float fNumSecsPassed) { return TB_OK; } int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) { DirectX_Init Init; Init.DoMessageLoop(Render,Move); return FALSE; } |
Zitat
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: enum tbResult __thiscall DirectX_Init:oMessageLoop(enum tbResult (__cdecl*)(float),enum tbResult (__cdecl*)(float))" (?DoMessageLoop@DirectX_Init@@QAE?AW4tbResult@@P6A?AW42@M@Z0@Z)" in Funktion "_WinMain@16".
C-/C++-Quelltext |
|
1 2 3 4 |
tbResult InitWindow(...) { ... } |
C-/C++-Quelltext |
|
1 2 3 4 |
tbResult DirectX_Init::InitWindow(...) { ... } |
Zitat von »"grek40"«
Also was mir als erste auffällt ist, dass du deine sämtlichen Implementierungen von DirectX_Init Memberfunktionen nicht mit dem Klassenname qualifizierst... also statt
C-/C++-Quelltext
1 2 3 4 tbResult InitWindow(...) { ... }
lieber
C-/C++-Quelltext
1 2 3 4 tbResult DirectX_Init::InitWindow(...) { ... }
Könnte sein, dass das dein Problem löst, ansonsten ma weiter schaun.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
//...... tbResult DirectX_Init::InitWindow(int iWidth, int iHeight, char* pcName, HICON hIcon) { // Fensterklassenstruktur ausfüllen WNDCLASSEX WindowClass = {sizeof(WNDCLASSEX), CS_CLASSDC, WindowProc, 0, 0, GetModuleHandle(NULL), hIcon, LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)), NULL, NULL, "Direct3D window", NULL}; //.... |
Zitat
1>..\..\..\..\MyClasses\Second Release\DirectX_Init.cpp(12) : error C2440: 'Initialisierung': 'overloaded-function' kann nicht in 'WNDPROC' konvertiert werden
1> Keine Funktion mit diesem Namen im Gültigkeitsbereich stimmt mit dem Zieltyp überein
C-/C++-Quelltext |
|
1 |
...CS_CLASSDC, WindowProc, ... |
C-/C++-Quelltext |
|
1 |
...CS_CLASSDC, (WNDPROC)WindowProc, ... |
C-/C++-Quelltext |
|
1 |
LRESULT CALLBACK WindowProc(HWND hWindow, UINT uiMessage, WPARAM WParam, LPARAM LParam) |
Zitat von »"Deviloper"«
Hmm wenn die WindowProc teil der Klasse sein soll, musst du diese als static setzen ...
(wie man dann wieder auf eine non-static-Funktion kommt, sag ich dir, falls du es brauchst In dem Fall sollte es aber ohne gehen, da du keine Variablen deiner Klasse zu brauchen scheinst ...)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#ifndef _DIRECTX_INIT_H_ #define _DIRECTX_INIT_H_ class DirectX_Init { public: /********Funktionsdeklarationen***************/ //Fenster: tbResult InitWindow(int iWidth, int iHeight, char* pcName, HICON hIcon); tbResult ExitWindow(); tbResult DoMessageLoop(tbResult (* pRenderProc)(float), tbResult (* pMoveProc)(float)); static LRESULT CALLBACK WINAPI WindowProc(HWND hWindow, unsigned int uiMessage, WPARAM WParam, LPARAM LParam); //DirectX: tbResult InitDirectX(); tbResult ExitDirectX(); tbResult InitAll() { tbInit(); InitWindow(1024,768,"Beispiel",0); InitDirectX(); return TB_OK; } tbResult ExitAll() { ExitWindow(); ExitDirectX(); tbExit(); return TB_OK; } }; #endif //Passt perfekt auf eine Seite |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
#include <TriBase.h> #include <D3D9.h> #include <windows.h> #include "DirectX_Globals.h" #include "DirectX_Init.h" /*******Fenster Initalisieren*********/ tbResult DirectX_Init::InitWindow(int iWidth, int iHeight, char* pcName, HICON hIcon) { // Fensterklassenstruktur ausfüllen WNDCLASSEX WindowClass = {sizeof(WNDCLASSEX), CS_CLASSDC, WindowProc, 0, 0, GetModuleHandle(NULL), hIcon, LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)), NULL, NULL, "Direct3D window", NULL}; // Klasse registrieren if(!RegisterClassEx(&WindowClass)) { TB_ERROR("Fensterklassenregistrierung fehlgeschlagen!", TB_ERROR); } TB_INFO("Fensterklasse wurde registriert!"); RECT Rect; SetRect(&Rect, 0, 0, iWidth, iHeight); AdjustWindowRect(&Rect, WS_VISIBLE | WS_OVERLAPPEDWINDOW, FALSE); iWidth = Rect.right - Rect.left; iHeight = Rect.bottom - Rect.top; // Fenster erstellen und prüfen g_hWindow = CreateWindow("Direct3D window", pcName, WS_VISIBLE | WS_OVERLAPPEDWINDOW, GetSystemMetrics(SM_CXSCREEN) / 2 - iWidth / 2, GetSystemMetrics(SM_CYSCREEN) / 2 - iHeight / 2, iWidth, iHeight, NULL, NULL, GetModuleHandle(NULL), NULL); if(g_hWindow == NULL) { TB_ERROR("Erstellung des Fensters ist fehlgeschlagen!\n", TB_ERROR); } // Alles OK! TB_INFO("Fenster wurde erstellt!"); return TB_OK; } /*************************************/ /*******Fenster herunterfahren********/ tbResult DirectX_Init::ExitWindow() { // Klasse löschen UnregisterClass("Direct3D window", GetModuleHandle(NULL)); TB_INFO("Fensterkomponente wurde heruntergefahren!"); return TB_OK; } /*************************************/ /*Die Nachrichtenfunktion des Fensters*/ LRESULT CALLBACK WINAPI DirectX_Init::WindowProc(HWND hWindow, unsigned int uiMessage, WPARAM WParam, LPARAM LParam) { PAINTSTRUCT Paint; switch(uiMessage) { case WM_CREATE: break; case WM_PAINT: // Das Fenster mit Schwarz füllen BeginPaint(hWindow, &Paint); FillRect(Paint.hdc, &Paint.rcPaint, (HBRUSH)(GetStockObject(BLACK_BRUSH))); EndPaint(hWindow, &Paint); break; case WM_CLOSE: DestroyWindow(hWindow); PostQuitMessage(0); break; default: return DefWindowProc(hWindow, uiMessage, WParam, LParam); } return TRUE; } /*********************************/ /****DirectX initalisieren********/ tbResult DirectX_Init::InitDirectX() { HRESULT hResult; D3DPRESENT_PARAMETERS PresentParams; // Globale IDirect3D9-Schnittstelle erzeugen g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); if(g_pD3D == NULL) TB_ERROR("IDirect3D9-Schnittstelle konnte nicht erstellt werden!", TB_ERROR); TB_INFO("IDirect3D9-Schnittstelle wurde erzeugt!"); // Präsentationsstruktur ausfüllen ZeroMemory(&PresentParams, sizeof(D3DPRESENT_PARAMETERS)); PresentParams.BackBufferWidth = 800; PresentParams.BackBufferHeight = 600; PresentParams.BackBufferFormat = D3DFMT_R5G6B5; PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE; PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD; PresentParams.hDeviceWindow = g_hWindow; PresentParams.Windowed = false; PresentParams.EnableAutoDepthStencil = true; PresentParams.AutoDepthStencilFormat = D3DFMT_D16;; UINT uiAdapter = g_pD3D->GetAdapterCount(); // Und nun die Geräteschnittstelle generieren if(FAILED(hResult = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresentParams, &g_pD3DDevice))) { MessageBox(g_hWindow,"DirectX Fehler","DX",MB_OK); // Fehler beim Generieren der Schnittstelle! TB_SAFE_RELEASE(g_pD3D); TB_SAFE_RELEASE(g_pD3DDevice); TB_ERROR_DIRECTX("g_pD3D->CreateDevice", hResult, TB_ERROR); } // Es hat geklappt! TB_INFO("Geräteschnittstelle wurde generiert!"); // Cursor ausblenden ShowCursor(FALSE); return TB_OK; } /*****DirectX herunterfahren*******/ tbResult DirectX_Init::ExitDirectX() { TB_SAFE_RELEASE(g_pD3D); TB_SAFE_RELEASE(g_pD3DDevice); return TB_OK; } /**********************************/ |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 |
#pragma once #ifndef _DIRECTX_GLOBALS_H #define _DIRECTX_GLOBALS_H /******Globale Variablen******/ static HWND g_hWindow(0); static PDIRECT3D9 g_pD3D(0); static PDIRECT3DDEVICE9 g_pD3DDevice(0); /******************************/ #endif |
C-/C++-Quelltext |
|
1 2 3 4 5 |
#include <TriBase.h> #include <D3D9.h> #include <windows.h> #include "DirectX_Globals.h" |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <TriBase.h> #include <D3D9.h> #include <windows.h> #include "C:\Dokumente und Einstellungen\GliderBugFix\Desktop\MyClasses\Second Release\DirectX_Init.h" tbResult Render(float fNumSecsPassed) { return TB_OK; } tbResult Move(float fNumSecsPassed) { return TB_OK; } int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) { DirectX_Init Init; Init.InitWindow(1024,768,"Beispiel",0); tbDoMessageLoop(Move,Render); Init.ExitWindow(); return FALSE; } |
Zitat
LNK-Error 2 unaufgelöst externe Verweise...
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#if !defined(DIRECTXWINDOW_HPP_INCLUDED) #define DIRECTXWINDOW_HPP_INCLUDED #if (_MSC_VER >= 1300) #pragma once #endif // (_MSC_VER >= 1300) #include <windows.h> #include <TriBase.h> #include <D3D9.h> class DirectXWindow { ::HWND m_hWnd; ::IDirect3D9* m_ptrD3D; ::IDirect3DDevice9* m_ptrDevice; public: DirectXWindow(unsigned int cx = 1024, unsigned int cy = 768, const char* caption = "DirectX", ::HICON const& icon) : m_ptrD3D(::Direct3DCreate9(D3D_SDK_VERSION)) { tbInit(); init_window(cx, cy, caption, icon); if (m_ptrD3D == NULL) throw std::runtime_error("directx not installed"); init_directx(); } ~DirectXWindow() { exit_window(); exit_directx(); tbExit(); } public: operator ::HWND() const { return m_hWnd; } #pragma warning(disable: 4312) static DirectXWindow* FromHandle(::HWND const & hWnd) { return reinterpret_cast<DirectXWindow*>(GetWindowLongPtr(hWnd, GWL_USERDATA)); }; #pragma warning(default: 4312) protected: bool init_window(unsigned int, unsigned int, const char*, ::HICON const&); void exit_window(); virtual LRESULT window_proc(HWND, UINT, WPARAM, LPARAM); private: static LRESULT CALLBACK WINAPI __window_proc(HWND, UINT, WPARAM, LPARAM); protected: void init_directx(); void exit_directx(); tbResult message_loop(tbResult (* pRenderProc)(float), tbResult (* pMoveProc)(float)); }; #endif // DIRECTXWINDOW_HPP_INCLUDED |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
#include "DirectXWindow.hpp" bool DirectXWindow::init_window(unsigned int width, unsigned int height, const char* caption, ::HICON const& icon) { ::WNDCLASSEXA wc = {}; wc.cbSize = sizeof(::WNDCLASSEXA); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = &DirectXWindow::__window_proc; wc.hInstance = ::GetModuleHandleA(NULL); wc.hIcon = wc.hIconSm = icon; wc.hCursor = ::LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_ARROW)); wc.hbrBackground = reinterpret_cast<::HBRUSH>(::GetStockObject(LTGRAY_BRUSH)); wc.lpszClassName = "DirectXWindow"; if (::RegisterClassExA(&WindowClass) == 0) return false; m_hWnd = ::CreateWindowExA(NULL, "DirectXWindow", caption, WS_VISIBLE | WS_OVERLAPPEDWINDOW, ::GetSystemMetrics(SM_CXSCREEN) / 2.0 - width / 2.0, ::GetSystemMetrics(SM_CYSCREEN) / 2.0 - height / 2.0, NULL, NULL, wc.hInstance, reinterpret_cast<LPVOID>(this)); return m_hWnd != NULL } void DirectX_Init::exit_window() { ::UnregisterClassA("DirectXWindow", ::GetModuleHandleA(NULL)); } LRESULT DirectXWindow::window_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_PAINT: { ::RECT rect; ::GetClientRect(hWnd, &rect); ::PAINTSTRUCT ps; ::HDC hDC(::BeginPaint(hWnd, &ps)); ::FillRect(hDC, &rect, static_cast<::HBRUSH>(::GetStockObject(BLACK_BRUSH))); ::EndPaint(hWnd, &ps); } break; case WM_CLOSE: { ::PostQuitMessage(0); } break; default: return ::DefWindowProcA(hWnd, msg, wParam, lParam); } return 0L; } LRESULT CALLBACK DirectXWindow::__window_proc(::HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { DirectXWindow* ptr_window(DirectXWindow::FromHandle(hWnd)); #pragma warning(disable: 4311) if (message == WM_NCCREATE) { ptr_window = reinterpret_cast<DirectXWindow*>(reinterpret_cast<::LPCREATESTRUCT>(lParam)->lpCreateParams); ::SetWindowLongPtr(hWnd, GWL_USERDATA, reinterpret_cast<LONG>(ptr_window)); } #pragma warning(default: 4311) return (ptr_window != NULL ? ptr_window->window_proc(hWnd, message, wParam, lParam) : ::DefWindowProcA(hWnd, message, wParam, lParam)); } void DirectXWindow::init_directx() { D3DPRESENT_PARAMETERS ppm = {0}; ppm.BackBufferWidth = 800; ppm.BackBufferHeight = 600; ppm.BackBufferFormat = D3DFMT_R5G6B5; ppm.MultiSampleType = D3DMULTISAMPLE_NONE; ppm.SwapEffect = D3DSWAPEFFECT_DISCARD; ppm.hDeviceWindow = m_hWnd; ppm.Windowed = true; ppm.EnableAutoDepthStencil = true; ppm.AutoDepthStencilFormat = D3DFMT_D16;; if (FAILED(m_ptrD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &ppm, &m_ptrDevice))) { TB_SAFE_RELEASE(m_ptrD3D); TB_SAFE_RELEASE(m_ptrDevice); throw std::runtime_error("could not create device"); } } void DirectXWindow::exit_directx() { TB_SAFE_RELEASE(m_pD3D); TB_SAFE_RELEASE(m_pD3DDevice); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
#include <TriBase.h> #include "DirectXWindow.hpp" tbResult Render(float) { return TB_OK; } tbResult Move(float) { return TB_OK; } int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) { DirectXWindow window(1024, 768, "Beispiel", NULL); tbDoMessageLoop(Move, Render); return 0; } |
Werbeanzeige