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
Quellcode |
|
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 |
#include <d3d9.h> #include <stdio.h> #include <windows.h> int g_iNumAdapters; D3DADAPTER_IDENTIFIER9* g_pAdapters; PDIRECT3D9 g_pD3D = 0; class initD3D { public: void Messages(void) { LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch(msg) { case WM_CREATE: { return(0); } break; case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); return(0); } break; case WM_DESTROY: { PostQuitMessage(0); return(0); } break; default: break; } return(DefWindowProc(hwnd, msg, wparam, lparam)); } void InitWindow(void) { WNDCLASSEX winclass; HWND hwnd; MSG msg; winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hInstance; winclass.hIcon = LoadCursor(0, IDC__ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = 0; winclass.lpszClassName = WINDOWS_CLASS_NAME; winclass.hIconSm = LoadIcon(0, IDI_APPLICATION); } D3Dinit(void) { g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); if(g_pD3D == NULL) { MessageBox(0,"Direct3D Schnittstelle konnte nicht erzeugt werden", "Fehler", MB_OK | MB_ICONEXCLAMATION); return 1; } else if(g_pD3D != 0) { MessageBox(0,"Es wurde eine Direct3D Schnittstelle erzeugt.", "Information",MB_OK|MB_ICONINFORMATION); } D3DDISPLAYMODE d3ddm; D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; } void D3Dexit(void) { g_pD3D -> Release(); MessageBox(0,"Direct3D wurde erfolgreich heruntergefahren.","Information",MB_OK | MB_ICONINFORMATION); } }; |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <windows.h> #include <d3d9.h> #include "functions.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { initD3D D3D; D3D.Messages(); D3D.InitWindow(); D3D.D3Dinit(); D3D.D3Dexit(); return(0); } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 |
--------------------Konfiguration: initd3dwindow - Win32 Debug-------------------- Kompilierung läuft... start.cpp d:\my own progs\initd3dwindow\start.cpp(3) : error C2059: Syntaxfehler : 'PCH creation point' d:\my own progs\initd3dwindow\start.cpp(7) : error C2334: Unerwartete(s) Token vor '{'; sichtbarer Funktionsrumpf wird übersprungen d:\my own progs\initd3dwindow\start.cpp(15) : fatal error C1004: Unerwartetes Dateiende gefunden Fehler beim Ausführen von cl.exe. initd3dwindow.exe - 3 Fehler, 0 Warnung(en) |
Administrator
Quellcode |
|
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 |
//Diese Funktion initialisiert Direct3D und erzeugt ein Fenster result InitD3D(HINSTANCE hinst) { CONFIG Settings; //Die Daten aus der Datei 'config.cfg' FILE *SettingFile; //Zeiger auf die Datei mit den Einstellungen aus dem Konfigurationsdialog D3DPRESENT_PARAMETERS PParams; //PresentParameters-Struktur von Direct3D HRESULT result; //Rückgabewert WNDCLASSEX WinClass; //Struktur mit den Daten für die erzeugung des Fensters if(StartConfigDialog(hinst, TRUE)!=R_OK) { //Fehler: Konfigurationsdialog fehlgeschlagen. Funktion abbrechen! return R_ERROR; } //Datei öffnen SettingFile = fopen("config.cfg", "r"); if(SettingFile == NULL) { //Fehler: Datei konnte nicht geöffnet werden. Funktion abbrechen! MSGERR(NULL, "Konfigurationsdatei konnte nicht geöffnet werden"); return R_ERROR; } //Daten auslesen und Datei wieder schiessen fread(&Settings, sizeof(CONFIG), 1, SettingFile); fclose(SettingFile); //Fenster-Struktur ausfüllen WinClass.cbSize = sizeof(WNDCLASSEX); WinClass.style = CS_HREDRAW | CS_VREDRAW; WinClass.lpfnWndProc = WindowProc; WinClass.cbClsExtra = 0; WinClass.cbWndExtra = 0; WinClass.hInstance = hinst; WinClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); WinClass.hCursor = LoadCursor(NULL, IDC_ARROW); WinClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); WinClass.lpszMenuName = NULL; WinClass.lpszClassName = "Terrain Engine 0.1"; WinClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //Fenster registriern if (!RegisterClassEx(&WinClass)) return R_ERROR; //Handle des Fensters erzeugen und global speichern if (!(D3DWindow = CreateWindowEx(NULL, "Terrain Engine 0.1", "Terrain Engine 0.1", WS_OVERLAPPED | WS_VISIBLE, 0, 0, Settings.VideoMode.Width, Settings.VideoMode.Height, NULL, NULL, hinst, NULL))) return R_ERROR; //Direct3D-Schnittstelle erzeugen Direct3D = Direct3DCreate9(D3D_SDK_VERSION); if(Direct3D == NULL) { //Fehler: Die Schnittstelle konnte nicht erzeugt werden. Programm abbrechen! MSGERR(D3DWindow, "Die IDirect3D9-Schnittstelle konnte nicht generiert werden! DirectX 9 oder höher wird benötigt!"); return R_ERROR; } //Direct3D-Info-Struktur ausfüllen ZeroMemory(&PParams, sizeof(D3DPRESENT_PARAMETERS)); PParams.BackBufferWidth = Settings.VideoMode.Width; PParams.BackBufferHeight = Settings.VideoMode.Height; PParams.BackBufferFormat = Settings.VideoMode.Format; PParams.BackBufferCount = 1; PParams.MultiSampleType = D3DMULTISAMPLE_NONE; PParams.MultiSampleQuality = 0; PParams.SwapEffect = D3DSWAPEFFECT_DISCARD; PParams.hDeviceWindow = D3DWindow; PParams.Windowed = FALSE; PParams.EnableAutoDepthStencil = TRUE; PParams.AutoDepthStencilFormat = D3DFMT_D24S8; PParams.Flags = 0; PParams.FullScreen_RefreshRateInHz = Settings.VideoMode.RefreshRate; PParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; //Direct3D-Device erzeugen result = Direct3D->CreateDevice(Settings.Adapter, Settings.Device, D3DWindow, D3DCREATE_MIXED_VERTEXPROCESSING, &PParams, &D3DDevice); if(result != D3D_OK) { //Fehler: Direct3D-Device konnte nicht erzeugt werden MSGERR(D3DWindow, "Fehler beim erzeugen der IDirect3DDevice9-Schnittstelle"); return R_ERROR; } //Windows-Cursor ausschalten ShowCursor(FALSE); return R_OK; } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { switch (message) { //Fenster wurde zerstört --> Programm beenden! case WM_DESTROY: { PostQuitMessage(0); return 1; } break; default:break; } return (DefWindowProc(hwnd, message, wparam, lparam)); } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <windows.h> #include <d3d9.h> #include "functions.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { mD3D D3D; D3D.InitD3D(); D3D.Nachrichten(); D3D.InitWindow(); D3D.ExitD3D(); } |
Quellcode |
|
1 2 3 4 5 6 7 8 |
--------------------Konfiguration: initd3dwindow - Win32 Debug-------------------- Kompilierung läuft... start.cpp d:\my own progs\initd3dwindow\functions.h(45) : warning C4183: 'InitD3D': Definition der Member-Funktion sieht aus wie ctor, aber der Name entspricht nicht der umschliessenden Klasse D:\my own progs\initd3dwindow\start.cpp(14) : fatal error C1004: Unerwartetes Dateiende gefunden Fehler beim Ausführen von cl.exe. initd3dwindow.exe - 1 Fehler, 1 Warnung(en) |
Werbeanzeige