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
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 |
long DrawPrimitiveUP (::D3DPRIMITIVETYPE type, unsigned long count, const void *data, unsigned long stride, ::IDirect3DDevice9* device) { // Rückgabewert long result = D3D_OK; // Device muß vorhanden sein! if (!device) return (E_FAIL); // Vertexbuffer ::IDirect3DVertexBuffer9 *vertexbuffer = NULL; // Vertexbuffer erstellen if ((result = device->CreateVertexBuffer (stride*count, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &vertexbuffer, NULL)) != D3D_OK) return (result); // Pointer auf Datenbereich void *vertices = NULL; // Verriegeln ist angesagt! if ((result = vertexbuffer->Lock (0, 0, &vertices, 0)) != D3D_OK) return (result); // Vertices kopieren (Secure Rocks!) if (::memcpy_s (vertices, stride*count, data, stride*count) != 0) return (E_FAIL); // Entriegeln if ((result = vertexbuffer->Unlock ()) != D3D_OK) return (result); // Verbindung zwischen Vertexbuffer und Renderingstream herstellen if ((result = device->SetStreamSource (0, vertexbuffer, 0, stride)) != D3D_OK) return (result); // Rendern if ((result = device->DrawPrimitive (type, 0, count)) != D3D_OK) return (result); // VertexBuffer freigeben NIEMALS vergessen! if (vertexbuffer != NULL) { vertexbuffer->Release (); vertexbuffer = NULL; } // Alles roger! return (result); } |
Sheddex
unregistriert
Anonymous
unregistriert
Anonymous
unregistriert
Anonymous
unregistriert
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 |
void triangle (const vertex &v1, const vertex &v2, const vertex &v3) { // Y-Positionen der Dreiecke merken const float x1 = v1.x; const float x2 = v2.x; const float x3 = v3.x; // X-Positionen der Dreiecke merken const float y1 = v1.y; const float y2 = v2.y; const float y3 = v3.y; // Bounding Rechteck Dimensionen bestimmen const long minx = static_cast<long>(min(x1, x2, x3)); const long maxx = static_cast<long>(max(x1, x2, x3)); const long miny = static_cast<long>(min(y1, y2, y3)); const long maxy = static_cast<long>(max(y1, y2, y3)); // Startpunkt setzen reinterpret_cast<char*>(&backbuffer) += miny * pitch; // Das Bounding Rechteck durchlaufen for (long y=miny; y<maxy; ++y) { for (long x=minx; x<maxx; ++x) { // Prüfen ob Pixel _im_ Dreieck liegt if ((x1 - x2) * (y - y1) - (y1 - y2) * (x - x1) > 0 && << (x2 - x3) * (y - y2) - (y2 - y3) * (x - x2) > 0 && << (x3 - x1) * (y - y3) - (y3 - y1) * (x - x3) > 0) { // Weißen Pixel malen backbuffer[x] = 0xFFFFFFFF; } } // Startpunkt neu setzen reinterpret_cast<char*>(&backbuffer) += pitch; } } |
Administrator
Anonymous
unregistriert
Werbeanzeige