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 |
struct CUSTOMVERTEX { float x, y, z, zhw; DWORD flag; }; const int CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE); void init_graphics() { CUSTOMVERTEX t_vert[] = { { 320.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) }, { 520.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0) }, { 120.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0) }, }; d3ddev->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &t_buffer, NULL); void* pVoid; t_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, t_vert, sizeof(t_vert)); t_buffer->Unlock(); } // init_graphics() void render_frame() { d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); d3ddev->BeginScene(); /* Note: Locking video RAM is slow, but required. * You should call BeginScene() and EndScene() only once per frame * to save your valuable CPU ticks. */ d3ddev->SetFVF(CUSTOMFVF); d3ddev->SetStreamSource(0, t_buffer, 0, sizeof(CUSTOMVERTEX)); d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1); /* D3DPT_POINTLIST Shows a series of points. * D3DPT_LINELIST Shows a series of separated lines. * D3DPT_LINESTRIP Shows a series of connected lines. * D3DPT_TRIANGLELIST Shows a series of separated triangles. * D3DPT_TRIANGLESTRIP Shows a series of connected triangles. * D3DPT_TRIANGLEFAN Shows a series of triangles with one shared corner. */ d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); return; } // render_frame() |
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 |
// //////////////////////////////////////////////////// // // Class Triangle // // //////////////////////////////////////////////////// struct VERTEX { float x, y, z, zhw; DWORD flag; }; class Triangle { public: VERTEX *m_pVertices; float m_Height, m_Width; public: Triangle(const float Width, const float Height, const float xPos, const float yPos, const float zPos, const float zhw, const DWORD color) { VERTEX m_pVertices[] = { { xPos, yPos, zPos, zhw, color }, { xPos + Height, yPos + Width/2.0f, zPos, zhw, color }, { xPos + Height, yPos - Width/2.0f, zPos, zhw, color } }; m_Height = Height; m_Width = Width; } ~Triangle(void) {} VERTEX* getVerts (void) { return m_pVertices; } }; // class Traingle |
C-/C++-Quelltext |
|
1 |
triangle = new Triangle(300.0f, 200.0f, 100.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255)); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// ... VERTEX *m_pVertices; // ... public: Triangle(const float Width, const float Height, const float xPos, const float yPos, const float zPos, const float zhw, const DWORD color) { VERTEX m_pVertices[] = { { xPos, yPos, zPos, zhw, color }, { xPos + Height, yPos + Width/2.0f, zPos, zhw, color }, { xPos + Height, yPos - Width/2.0f, zPos, zhw, color } }; // das da isn andres m_pVertices als das was du meinst... // ... |
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 |
class Triangle { private: VERTEX m_pVertices[arr_size]; float m_Height, m_Width; public: Triangle(const float width, const float height, const float xPos, const float yPos, const float zPos, const float zhw, const DWORD color) { m_pVertices[0].x = xPos; m_pVertices[0].y = yPos; m_pVertices[0].z = zPos; m_pVertices[0].zhw = zhw; m_pVertices[0].flag = color; m_pVertices[1].x = xPos + height; m_pVertices[1].y = yPos + width/2; m_pVertices[1].z = zPos; m_pVertices[1].zhw = zhw; m_pVertices[1].flag = color; m_pVertices[2].x = xPos + height; m_pVertices[2].y = yPos - width/2; m_pVertices[2].z = zPos; m_pVertices[2].zhw = zhw; m_pVertices[2].flag = color; m_Height = height; m_Width = width; } // Constructor VERTEX* getVerts (void) { return m_pVertices; } } // class Triangle void init_graphics() { d3ddev->CreateVertexBuffer( 3*sizeof(VERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &t_buffer, NULL); void* pVoid; t_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, triangle.getVerts(), sizeof(VERTEX)); t_buffer->Unlock(); } // init_graphics() |
Zitat von »"$nooc"«
wie schreibe ich dann ein VERTEX array welches erst im konstruktor die werte übermittelt bekommt die das jew. struct enthalten soll?
bzw. wir kann ich das dynamisch halten? zb wenn ich stadt nur 3 vertex 4 haben will?
Werbeanzeige