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
Anonymous
unregistriert
Quellcode |
|
1 2 3 4 |
tbDirect3D::SetFVF(D3DFVF_STD); //selbstdefiniertes Format (D3DFVF_XYZ | D3DFVF_DIFFUSE) tbDirect3D::SetRS (D3DRS_LIGHTING,FALSE); tbDirect3D::SetRS (D3DRS_CULLMODE,D3DCULL_NONE); |
Administrator
Anonymous
unregistriert
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 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 |
#include <Windows.h> #include <TriBase.h> // ****************************************************************** // Vertex - Struktur struct SVertex { tbVector3 vPosition; DWORD dwColor; }; #define D3DFVF_STD (D3DFVF_XYZ | D3DFVF_DIFFUSE) // ****************************************************************** // Globale Variablen tbConfig g_Config; // Konfigurationsstruktur float g_fTime = 0.0f; // Zeitzähler SVertex g_aDreieck[3]; // Dreieck // ****************************************************************** // Die Render-Funktion tbResult RenderProc(float fNumSecsPassed) { HRESULT hResult; tbMatrix mRotation; // Rotationsmatrix tbMatrix mTranslation; // Translationsmatrix tbMatrix mWorld; // Vereinende Weltmatrix // Rotations- und Translationsmatrix des Dreiecks 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 Weltmatrix einsetzen mWorld = mRotation * mTranslation; tbDirect3D::GetDevice()->SetTransform(D3DTS_WORLD, (D3DMATRIX*)(&mWorld)); // Z-Buffer leeren und die Szene beginnen tbDirect3D::GetDevice()->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0); tbDirect3D::GetDevice()->BeginScene(); // Nun das Dreieck zeichnen if(FAILED(hResult = tbDirect3D::GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, // Dreiecksliste 1, // 1 Dreieck g_aDreieck, // Vertexdaten sizeof(SVertex)))) // Vertexgröße { // Fehler beim Zeichnen! MessageBox(tbDirect3D::GetWindow(), "Fehler beim Zeichnen des Dreiecks!", "Fehler", MB_OK | MB_ICONEXCLAMATION); TB_ERROR_DIRECTX("g_pD3DDevice->DrawPrimitiveUP", hResult, TB_STOP); } // Szene beenden tbDirect3D::GetDevice()->EndScene(); //Den Bildpuffer sichtbar machen tbDirect3D::GetDevice()->Present(NULL, NULL, NULL, NULL); return TB_OK; } // ****************************************************************** // Die Render-Funktion tbResult MoveProc(float fNumSecsPassed) { g_fTime += fNumSecsPassed; return TB_OK; } // ****************************************************************** // Aufräumen tbResult CleanUp() { // Alles löschen tbDirect3D::Exit(); // Die TriBase-Engine herunterfahren tbExit(); return TB_OK; } tbResult InitScene() { float fAspect; tbMatrix mProjection; //Vertexformat und Renderstates tbDirect3D::SetFVF(D3DFVF_STD); tbDirect3D::SetRS (D3DRS_LIGHTING,FALSE); tbDirect3D::SetRS (D3DRS_CULLMODE,D3DCULL_NONE); tbDirect3D::SetRS (D3DRS_DITHERENABLE,TRUE); // Das Bildseitenverhältnis berechnen fAspect = (float)(g_Config.Direct3D.VideoMode.Width) / (float)(g_Config.Direct3D.VideoMode.Height); // Die Projektionsmatrix erzeugen mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f), // Sichtfeld: 90° fAspect, // Bildseitenverhältnis 0.1f, // Nahe Clipping-Ebene 100.0f); // Ferne Clipping-Ebene // Projektionsmatrix einsetzen tbDirect3D::GetDevice()->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)(&mProjection)); //Dreieck - Initialisierung g_aDreieck[0].vPosition = tbVector3( 0.0f, 1.0f, 0.0f); g_aDreieck[1].vPosition = tbVector3( 1.0f,-1.0f, 0.0f); g_aDreieck[2].vPosition = tbVector3(-1.0f,-1.0f, 0.0f); g_aDreieck[0].dwColor = tbColor( 1.0f, 0.0f, 0.0f); g_aDreieck[1].dwColor = tbColor( 0.0f, 1.0f, 0.0f); g_aDreieck[2].dwColor = tbColor( 0.0f, 0.0f, 1.0f); return TB_OK; } // ****************************************************************** // Windows-Hauptfunktion int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { int r; // TriBase-Engine initialisieren tbInit(); // Konfiguration abfragen if(r = tbDoConfigDialog(&g_Config)) { if(r == TB_CANCELED) return 0; else { // Fehler! MessageBox(NULL, "Fehler im Konfigurationsdialog!", "Fehler", MB_OK | MB_ICONEXCLAMATION); return 1; } } // Direct3D initialisieren if(tbDirect3D::Init(&g_Config, "Beispielprogramm Nr. 1: tbDirect3D", NULL, NULL)) { // Fehler! MessageBox(NULL, "Fehler bei der Direct3D-Initialisierung!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } if(tbDoMessageLoop(MoveProc, RenderProc)) { MessageBox(tbDirect3D::GetWindow(), "Fehler beim Zeichnen!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } //Aufräumen CleanUp(); return 0; } |
Anonymous
unregistriert
Werbeanzeige