Hallo,
EDIT: Das Thema hat sich erledigt. Hab in der SDL-Dokumentation endlich nach langem Suchen die Antwort gefunden (*schäm*). Warum in die Ferne schweifen, wenn die Lösung so nahe liegt. Erstaunlich aber, dass ich über Google nichts für Delphi finden konnte.
ich möchte eine leere SDL_Surface Pixel für Pixel füllen. Leider sind meine bisherigen Versuche kläglich gescheitert.
Den folgenden Code habe ich im Netz gefunden.
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:
| void DrawPixel(SDL_Surface *screen, int x, int y,Uint8 R, Uint8 G,Uint8 B) { Uint32 color = SDL_MapRGB(screen->format, R, G, B);
if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { return; } }
switch (screen->format->BytesPerPixel) { case 1: { /* vermutlich 8 Bit */ Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x; *bufp = color; } break;
case 2: { /* vermutlich 15 Bit oder 16 Bit */ Uint16 *bufp;
bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x; *bufp = color; } break;
case 3: { /* langsamer 24-Bit-Modus, selten verwendet */ Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3; if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { bufp[0] = color; bufp[1] = color >> 8; bufp[2] = color >> 16; } else { bufp[2] = color; bufp[1] = color >> 8; bufp[0] = color >> 16; } } break;
case 4: { /* vermutlich 32 Bit */ Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x; *bufp = color; } break; }
if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } |
Hier zumindest ein Ansatz von mir.
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:
| Function DrawPixel(screen:PSDL_Surface;x,y: Integer; R,G,B:Uint8):Boolean; Var Color:Uint32; Bufp:Uint32;
Begin Result:=True;
color:= SDL_MapRGB(screen.format,r,g,b);
IF ( SDL_MUSTLOCK(screen) ) then IF ( SDL_LockSurface(screen) < 0 ) then Exit;
Case screen.format.BytesPerPixel of 1: BEGIN Bufp:=Uint8(screen.pixels)+y*screen.pitch+x; Move(Pointer(Color)^,Pointer(Bufp)^,Sizeof(Color)); END; //Vermutlich 8 Bit
2: BEGIN Bufp:= Uint16(screen.pixels)+y*screen.pitch DIV 2 +x; Move(Pointer(bufp16)^,Pointer(Bufp)^,Sizeof(Bup)); END; 3: BEGIN //24 Bit Modus Setzen ??? END; 4: BEGIN Bufp32:= Uint32(screen.pixels)+y*screen.pitch DIV 4 +x; Bufp32:=Color; //??? END; End;
if ( SDL_MUSTLOCK(screen) ) then BEGIN SDL_UnlockSurface(screen); END; End; |
Ich habe keine Ahnung, ob die Verwendung von Move richtig ist? Zumindest bekomme ich als Ausgabe nur einen schwarzen Bildschirm.
Gruß
Rushifell