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 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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
#include <Windows.h> #include <TriBase.h> #include <D3D9.h> #include "InitWindow.h" #include "Direct3DEnum.h" #include "InitDirect3D.h" #include "Resource.h" // ****************************************************************** // Globale Strukturen struct SVertex { tbVector3 vPosition; //Position DWORD dwColor; //Farbe static const DWORD dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE; //Vertexformat }; // ****************************************************************** //Globale Variablen SDirect3DParameters g_Direct3DParameters; SVertex g_aTriangleVertex[4]; float g_fTime = 0.0f; // ****************************************************************** // Prototypen tbResult InitApplication(); tbResult ExitApplication(); tbResult InitScene(); tbResult ExitScene(); tbResult Render(float fNumSecsPassed); tbResult Move(float fNumSecsPassed); // ****************************************************************** // ****************************************************************** // Windows-Hauptfunktion int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* pcCmdLine, int iShowCmd) { tbResult Result; //Initialisierung Result = InitApplication(); if(Result == TB_CANCELED) { MessageBoxA(NULL, "Fehler beim initialisieren der Anwendung! (Abbruch)", "Fehler", MB_OK | MB_ICONEXCLAMATION); return 0; } else if(Result == TB_ERROR) { MessageBoxA(NULL, "Fehler beim initialisieren der Anwendung! (Error)", "Fehler", MB_OK | MB_ICONEXCLAMATION); return 1; } // Nachrichtenschleife tbDoMessageLoop(Render, Move); // Herunterfahren ExitApplication(); return 0; } // ****************************************************************** // ****************************************************************** // Render-Funktion tbResult Render(float fNumSecsPassed) { HRESULT hResult; tbMatrix mRotation; tbMatrix mTranslation; tbMatrix mWorld; //Rotations und Translationsmatrix erzeugen mRotation = tbMatrixRotationY(TB_DEG_TO_RAD(g_fTime * 90.0f)); mTranslation = tbMatrixTranslation(tbVector3(0.0f, 0.0f, 2.0f)); //Beide Matrizen kombinieren und als Weltmatriz einsetzen mWorld = mRotation * mTranslation; g_pD3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)(&mWorld)); //Den Bildbuffer und den Z-Buffer leeren if(FAILED(hResult = g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0))) { //Fehler TB_ERROR_DIRECTX("g_pD3DDevice->Clear", hResult, TB_STOP); } //Szene beginnen g_pD3DDevice->BeginScene(); //Dreieck zeichnen if(FAILED(hResult = g_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, //Verbundene Dreiecke 2, //2 Dreiecke g_aTriangleVertex, //Vertizes sizeof(SVertex)))) //Vertexgrösse { //Fehler TB_ERROR_DIRECTX("g_pD3DDevice->DrawPrimitiveUP", hResult, TB_STOP); } //Szene beenden g_pD3DDevice->EndScene(); //Bildpuffer sichtbar machen g_pD3DDevice->Present(NULL, NULL, NULL, NULL); return TB_OK; } // ****************************************************************** // Move-Funktion tbResult Move(float fNumSecsPassed) { //Zeitzähler erhöhen g_fTime += fNumSecsPassed; return TB_OK; } // ****************************************************************** // ****************************************************************** tbResult InitApplication() { tbResult Result; // TriBase-Engine initialisieren tbInit(); // Direct3D-Optionen abfragen (vom Benutzer gewählt) Result = GetDirect3DParameters(&g_Direct3DParameters); if(Result == TB_ERROR) { // Es trat ein Fehler auf! MessageBoxA(NULL, "Fehler beim Abzählen!", "Fehler", MB_OK | MB_ICONEXCLAMATION); ExitApplication(); return TB_ERROR; } else if(Result == TB_CANCELED) { // Der Dialog wurde abgebrochen! ExitApplication(); return TB_ERROR; } // Fenster initialisieren. Die Größe hängt vom gewählten // Videomodus ab, der in der Parameterstruktur gespeichert ist. if(InitWindow(g_Direct3DParameters.VideoMode.Width, g_Direct3DParameters.VideoMode.Height, "First Poly", LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)))) { // Fehler beim Erstellen des Fensters! MessageBoxA(NULL, "Fehler beim Erstellen des Fensters!", "Fehler", MB_OK | MB_ICONEXCLAMATION); ExitApplication(); return TB_ERROR; } // Direct3D mit den abgefragten Einstellungen initialisieren if(InitDirect3D(&g_Direct3DParameters, g_hWindow)) { // Fehler! MessageBoxA(g_hWindow, "Fehler beim Initialisieren von Direct3D!", "Fehler", MB_OK | MB_ICONEXCLAMATION); ExitWindow(); ExitApplication(); return TB_ERROR; } if(InitScene()) { //Fehler! MessageBoxA(g_hWindow, "Fehler beim Initialisieren der Szene!", "Fehler", MB_OK | MB_ICONEXCLAMATION); ExitApplication(); return TB_ERROR; } return TB_OK; } //InitApplication // ****************************************************************** tbResult ExitApplication() { //Szene herunterfahren ExitScene(); //Direct3D und Fenster herunterfahren ExitDirect3D(); ExitWindow(); //Tribase herunterfahren tbExit(); return TB_OK; } // ****************************************************************** tbResult InitScene() { HRESULT hResult; tbMatrix mProjection; float fAspect; //VertexformatSetzen(Position-, Farbangabe) if(FAILED(hResult = g_pD3DDevice->SetFVF(SVertex::dwFVF))) { //Fehler TB_ERROR_DIRECTX("g_pD3DDevice->SetFVF", hResult, TB_ERROR); } //Beleuchtung und Culling ausschalten, Dithering aktivieren g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); g_pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE); //Bildseitenverhältnis berechnen fAspect = (float)(g_Direct3DParameters.VideoMode.Width) / (float)(g_Direct3DParameters.VideoMode.Height); //Die Projektionsmatrix erzeugen mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f), // Sichtfeld: 90° (180°) fAspect, // Bildseitenverhältnis 0.1f, // Nahe Clipping-Ebene 100.0f); // Ferne Clipping-Ebene //Projektionsmatrix einsetzen (aktivieren) g_pD3DDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)(&mProjection)); //Vertizes Speichern g_aTriangleVertex[0].vPosition = tbVector3(0.0f, 1.0f, 0.5f); g_aTriangleVertex[1].vPosition = tbVector3(1.0f, -1.0f, -0.5f); g_aTriangleVertex[2].vPosition = tbVector3(-1.0f, -1.0f, -0.5f); g_aTriangleVertex[3].vPosition = tbVector3(0.0f, -1.0f, 0.5f); g_aTriangleVertex[0].dwColor = tbColor(1.0f, 0.0f, 0.0f); g_aTriangleVertex[1].dwColor = tbColor(0.0f, 1.0f, 0.0f); g_aTriangleVertex[2].dwColor = tbColor(0.0f, 0.0f, 1.0f); g_aTriangleVertex[3].dwColor = tbColor(1.0f, 1.0f, 1.0f); return TB_OK; } //InitScene // ****************************************************************** tbResult ExitScene() { return TB_OK; } // ****************************************************************** |