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 |
tbResult RenderProc(float fNumSecsPassed) { SVertex aVertex[3]; tbMatrix mCamera; tbMatrix mProjection; tbVector3 vCameraPos; tbVector3 vCameraLookAt; // Puffer leeren und die Szene beginnen tbDirect3D& D3D = tbDirect3D::Instance(); D3D.SetRS(D3DRS_ZENABLE, TRUE); D3D.SetRS(D3DRS_LIGHTING, FALSE); D3D->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , tbColor(0.0f, 0.0f, 0.0f), 1.0f, 0); D3D->BeginScene(); // Vertexformat setzen D3D.SetFVF(SVertex::dwFVF); vCameraPos = tbVector3(0.0f, 8.0f, 25.0f); vCameraLookAt = tbVector3(0.0f, 0.0f, 0.0f); // Kameramatrix erstellen und aktivieren mCamera = tbMatrixCamera(vCameraPos, vCameraLookAt); D3D.SetTransform(D3DTS_VIEW, mCamera); // Projektionsmatrix erstellen und aktivieren mProjection = tbMatrixProjection(TB_DEG_TO_RAD(70.0f), D3D.GetAspect(), 0.1f, 100.0f); D3D.SetTransform(D3DTS_PROJECTION, mProjection); D3D.SetTransform(D3DTS_WORLD, seMatrixIdentity()); aVertex[0].vPosition = tbVector3(-3.0f, 0.0f, 3.0f); aVertex[0].Color = tbColor(1.0f, 0.8f, 0.8f); aVertex[1].vPosition = seVector3(-3.0f, 0.0f, -3.0f); aVertex[1].Color = tbColor(0.8f, 1.0f, 0.8f); aVertex[2].vPosition = seVector3(3.0f, 0.0f, 3.0f); aVertex[2].Color = tbColor(0.8f, 0.8f, 1.0f); D3D->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 0, aVertex, sizeof(SVertex)); // Szene beenden D3D->EndScene(); D3D->Present(NULL, NULL, NULL, NULL); return TB_OK; } |
C-/C++-Quelltext |
|
1 |
vCameraPos = tbVector3(0.0f, 8.0f, 25.0f); |
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 |
struct SVertex { tbVector3 vPosition; D3DCOLOR Color; static const DWORD dwFVF; }; const DWORD SVertex::dwFVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE; // ****************************************************************** // Globale Variablen tbConfig g_Config; // Konfigurationsstruktur // ****************************************************************** // Die Move-Funktion tbResult MoveProc(float fNumSecsPassed) { return TB_OK; } // ****************************************************************** // Die Render-Funktion tbResult RenderProc(float fNumSecsPassed) { SVertex aVertex[3]; // Puffer leeren und die Szene beginnen tbDirect3D& D3D = tbDirect3D::Instance(); // Vertexformat setzen D3D.SetFVF(SVertex::dwFVF); D3D->BeginScene(); aVertex[0].vPosition = tbVector3(320.0f, 50.0f, 0.5f); aVertex[0].Color = tbColor(1.0f, 0.8f, 0.8f); aVertex[1].vPosition = tbVector3(520.0f, 400.0f, 0.5f); aVertex[1].Color = tbColor(1.0f, 0.8f, 0.8f); aVertex[2].vPosition = tbVector3(120.0f, 400.0f, 0.5f); aVertex[2].Color = tbColor(1.0f, 0.8f, 0.8f); D3D->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 0, aVertex, sizeof(SVertex)); // Szene beenden D3D->EndScene(); D3D->Present(NULL, NULL, NULL, NULL); return TB_OK; } // ****************************************************************** // Aufräumen tbResult CleanUp() { // Alles löschen // Direct3D herunterfahren tbDirect3D::Instance().Exit(); // Die TriBase-Engine herunterfahren tbExit(); return TB_OK; } // ****************************************************************** // Windows-Hauptfunktion int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* pcCommandLine, int iShowCommand) { // TriBase-Engine initialisieren tbInit(); // Konfiguration abfragen tbResult r; if(r = seDoConfigDialog(&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::Instance().Init(&g_Config, "Beispielprogramm", NULL, LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)))) { // Fehler! MessageBox(NULL, "Fehler bei der Direct3D-Initialisierung!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } // Nachrichtenschleife betreten if(tbDoMessageLoop(MoveProc, RenderProc)) { MessageBox(tbDirect3D::Instance().GetWindow(), "Fehler beim Zeichnen!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } // Aufräumen CleanUp(); return 0; } // ****************************************************************** |
C-/C++-Quelltext |
|
1 |
D3D->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 0, aVertex, sizeof(SVertex)); |
Zitat von »"DirectX Doku"«
PrimitiveCount
[in] Number of primitives to render
C-/C++-Quelltext |
|
1 |
D3D->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , tbColor(0.0f, 0.0f, 0.0f), 1.0f, 0); |
Zitat
C-/C++-Quelltext
1 D3D->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 0, aVertex, sizeof(SVertex));
Parameter 2 müsste doch 1 statt 0 sein? (für ein Dreieck)
C-/C++-Quelltext |
|
1 |
const DWORD SVertex::dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE; |
C-/C++-Quelltext |
|
1 |
D3D->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
aVertex[0].vPosition = D3DXVECTOR3(-1.0f, 0.0f, 1.0f); aVertex[0].Color = tbColor(1.0f, 0.0f, 0.0f); aVertex[1].vPosition = D3DXVECTOR3(0.0f, 1.0f, 1.0f); aVertex[1].Color = tbColor(0.0f, 1.0f, 0.0f); aVertex[2].vPosition = D3DXVECTOR3(1.0f, 0.0f, 1.0f); aVertex[2].Color = tbColor(0.0f, 0.0f, 1.0f); |
Zitat von »"Keydo"«
Komt man auf sowas nur durch probieren oder Erfahrung ?
Werbeanzeige