Du bist nicht angemeldet.

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

Architekt

Community-Fossil

  • »Architekt« ist der Autor dieses Themas

Beiträge: 2 481

Wohnort: Hamburg

Beruf: Student

  • Private Nachricht senden

11

21.02.2011, 16:23

Die SFML kommt leider nicht in Frage.
Das Porting ist unter D für die SDL am besten. Zudem baut mein gesamtes Projekt bereits auf der SDL auf.
Ich werd' dann mal meinen Grafiker fragen, was er meint, ansonsten muss halt ein harter Rand her. :)

Nochmal edit:

Zitat

Das ist bei der SFML deutlich bequemer, da die einfach den Alpha-Kanal deiner Grafik anwendet.

Wie? Kann man das bei der SDL nicht ebenso, mit SDL_DisplayFormatAlpha oder SDL_SetAlpha? Beides jedenfalls probiert und brachte beides nichts.
Der einfachste Weg eine Kopie zu entfernen ist sie zu löschen.
- Stephan Schmidt -

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Architekt« (21.02.2011, 16:30)


Quin

Frischling

Beiträge: 23

Wohnort: Engelthal

  • Private Nachricht senden

12

22.02.2011, 16:34

Ich hab leider das selbe Problem mit SDL_CreateRGBSurface.

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);



Am besten ist es das Bild in eine Surface laden und in einzelne Animationsphasen einteilen und renderst dann nur eine Phase.
Wenn ichs doch mal mit SDL_CreateRGBSurface hinbekomme werd ichs dir schreiben. :rolleyes:

Architekt

Community-Fossil

  • »Architekt« ist der Autor dieses Themas

Beiträge: 2 481

Wohnort: Hamburg

Beruf: Student

  • Private Nachricht senden

13

22.02.2011, 17:08

Würd' ich mich drüber freuen (;
Wie sieht denn dein Image aus?
Der einfachste Weg eine Kopie zu entfernen ist sie zu löschen.
- Stephan Schmidt -

DerMark

Treue Seele

Beiträge: 324

Wohnort: Emsdetten

Beruf: Softwareentwickler

  • Private Nachricht senden

14

22.02.2011, 17:18

Wie genau renderst du das Surface eigenbtlich? Durch diese Blit Funktion? Das kopiert afaik nur alle Pixel der Sourcesurface auf das Ziel, es sei denn der Pixel entspricht der angegebenen Keyfarbe.

Edit:

Ich vermute du musst http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy mit http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode kombinieren.

Quin

Frischling

Beiträge: 23

Wohnort: Engelthal

  • Private Nachricht senden

15

23.02.2011, 12:18

Zitat


Glaub SDL_RenderCopy ist SDL 1.3 ich hab aber nur 1.2, deshalb geht es bei mir auf jeden Fall nicht, aber danke für die Info ;)

Zitat

Wie sieht denn dein Image aus?

Es hatte leider nur einen schwarzen Hintergrund.

So nach langen Überlegen und vielen Versuchen hab ich was, denke aber es gibt bessere Lösungen aber besser als nichts. :D

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);
            }
        }

    }


Man muss nur noch mit SDL_CreateRGBSurface ein neues Surface erstellen und kann das Image mit Alphawerten mit CopySurface reinkopieren.
Normal muss es auch mit deinen Bild gehen, hab es zum testen gehabt. Ich hoffe der Code erschlägt dich nicht. :whistling:

Werbeanzeige