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
Zitat
Das ist bei der SFML deutlich bequemer, da die einfach den Alpha-Kanal deiner Grafik anwendet.
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Architekt« (21.02.2011, 16:30)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Uint32 RMask, GMask, BMask, AMask; #if SDL_BYTEORDER == SDL_BIG_ENDIAN RMask = 0xff000000; GMask = 0x00ff0000; BMask = 0x0000ff00; AMask = 0x000000ff; #else RMask = 0x000000ff; GMask = 0x0000ff00; BMask = 0x00ff0000; AMask = 0xff000000; #endif m_pImage = SDL_CreateRGBSurface(SDL_SWSURFACE , Width, Height, m_pScreen->format->BitsPerPixel, RMask, GMask, BMask, AMask); |
Zitat
Ich vermute du musst http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy mit http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode kombinieren.
Zitat
Wie sieht denn dein Image aus?
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 |
// GetPixel // // Aufgabe: Gibt den Farbwert eines Pixels zurück, der auf der angegebenen Position des Surface ist. // SDL_Color GetPixel(SDL_Surface *pSurface, int XPos, int YPos) { SDL_Color Color; int BytesPerPixel = pSurface->format->BytesPerPixel; Uint8 *pPixel = reinterpret_cast<Uint8 *>(pSurface->pixels) + YPos * pSurface->pitch + XPos * BytesPerPixel; switch(BytesPerPixel) { // 8 Bit case 1: SDL_GetRGBA(*pPixel, pSurface->format, &Color.r, &Color.g, &Color.b, &Color.unused); break; // 15 oder 16 Bit case 2: SDL_GetRGBA(*reinterpret_cast<Uint16 *>(pPixel),pSurface->format, &Color.r, &Color.g, &Color.b, &Color.unused); break; // 24 Bit case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { SDL_GetRGBA(static_cast<Uint32>(pPixel[0] << 16 | pPixel[1] << 8 | pPixel[2]), pSurface->format, &Color.r, &Color.g, &Color.b, &Color.unused); } else { SDL_GetRGBA(static_cast<Uint32>(pPixel[0] | pPixel[1] << 8 | pPixel[2] << 16), pSurface->format, &Color.r, &Color.g, &Color.b, &Color.unused); } break; // 32 Bit case 4: SDL_GetRGBA(*reinterpret_cast<Uint32 *>(pPixel),pSurface->format, &Color.r, &Color.g, &Color.b, &Color.unused); break; default: std::cout << "Fehler in GetPixel" << std::endl; Color.r = 0; Color.g = 0; Color.b = 0; Color.unused = 0; } return Color; } // GetPixel |
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 |
// Pixel // // Aufgabe: Einen Pixel in ein Surface kopieren // void Pixel(SDL_Surface *pSurface, int XPos, int YPos, Uint8 R, Uint8 G, Uint8 B, Uint8 A) { if (!pSurface) { std::cout << "Auf das Surface konnte nicht gezeichnet werden!" << std::endl; return; } if (XPos < 0 || YPos < 0 || XPos >= pSurface->w || YPos >= pSurface->h) { return; } Uint32 Color = SDL_MapRGBA(pSurface->format, R, G, B, A); if ( SDL_MUSTLOCK(pSurface)) { if ( SDL_LockSurface(pSurface) < 0 ) { return; } } switch (pSurface->format->BytesPerPixel) { // 8 Bit case 1: { Uint8 *pPixel; pPixel = reinterpret_cast<Uint8*>(pSurface->pixels) + YPos * pSurface->pitch + XPos; *pPixel = Color; } break; // 15 oder 16 Bit case 2: { Uint16 *pPixel; pPixel = reinterpret_cast<Uint16*>(pSurface->pixels) + YPos * pSurface->pitch / 2 + XPos; *pPixel = Color; } break; // 24-Bit case 3: { Uint8 *pPixel; pPixel = reinterpret_cast<Uint8*>(pSurface->pixels) + YPos * pSurface->pitch + XPos * 3; if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { pPixel[0] = Color; pPixel[1] = Color >> 8; pPixel[2] = Color >> 16; } else { pPixel[2] = Color; pPixel[1] = Color >> 8; pPixel[0] = Color >> 16; } } break; // 32 Bit case 4: { Uint32 *pPixel; pPixel = reinterpret_cast<Uint32*>(pSurface->pixels) + YPos * pSurface->pitch / 4 + XPos; *pPixel = Color; } break; default: std::cout << "Fehler in Pixel" << std::endl; } if ( SDL_MUSTLOCK(pSurface)) { SDL_UnlockSurface(pSurface); } } // Pixel |
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 |
// CopySurface // // Aufgabe: Kopiert ein Surface oder ein Auschnitt davon in ein anderes Surface // void CopySurface(SDL_Surface *pSurface, SDL_Rect *pRect, SDL_Surface *pToSurface, SDL_Rect *pToRect) { // Farbe und Alphawert des Pixels SDL_Color PixelColor; // Ausschnitt des Surface wo kopiert werden soll int XPos, YPos, Width, Height; // Position wo der Ausschnitt in das andere Surface kopiert werden soll int ToXPos, ToYPos; if (pRect) { XPos = pRect->x; YPos = pRect->y; Width = pRect->w; Height = pRect->h; } else { XPos = 0; YPos = 0; Width = pSurface->w; Height = pSurface->h; } if (pToRect) { ToXPos = pToRect->x; ToYPos = pToRect->y; } else { ToXPos = 0; ToYPos = 0; } for (int y = YPos; y < Height + YPos; ++y) { for (int x = XPos; x < Width + XPos; ++x) { // Farbwert des Pixels aus pSurface ermitteln PixelColor = GetPixel(pSurface, x, y); // Pixel in das pToSurface kopieren Pixel(pToSurface, x - XPos + ToXPos, y - YPos + ToYPos, PixelColor.r, PixelColor.g, PixelColor.b, PixelColor.unused); } } } |
Werbeanzeige