Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 光点上的SDL,失去透明度并变为黑色_C++_Visual C++_Sdl - Fatal编程技术网

C++ 光点上的SDL,失去透明度并变为黑色

C++ 光点上的SDL,失去透明度并变为黑色,c++,visual-c++,sdl,C++,Visual C++,Sdl,几个星期以来,我和我的朋友都在做一个项目。确切地说,这是一场比赛。我们遇到了一个巨大的问题,这个问题破坏了游戏。玩家的透明部分应该是黑色的 MergeSurfaces函数是blit。Rect本身被写入SDL_Rect,并执行blit void MergeSurfaces(SDL_Surface *From, SDL_Surface *To, int FromX, int FromY, int FromWidth, int FromLenght, int ToX, int ToY){

几个星期以来,我和我的朋友都在做一个项目。确切地说,这是一场比赛。我们遇到了一个巨大的问题,这个问题破坏了游戏。玩家的透明部分应该是黑色的

MergeSurfaces函数是blit。Rect本身被写入SDL_Rect,并执行blit

void MergeSurfaces(SDL_Surface *From, SDL_Surface *To, int FromX, int FromY, int FromWidth, int FromLenght, int ToX, int ToY){




            SDL_Rect srcRect;    
            srcRect.x = FromX;    
            srcRect.y = FromY;
            srcRect.w = FromWidth;   
            srcRect.h = FromLenght;

            SDL_Rect dstRect;    
            dstRect.x = ToX;    
            dstRect.y = ToY;    

            SDL_BlitSurface(From, &srcRect, To, &dstRect);
        }
这是球员的形成功能

//------------------------------------------------------------------------------------------
//----MAIN LOAD FUNCTION
//------------------------------------------------------------------------------------------    

    void LoadPlayerGraphics(SDL_Surface* BodyID[], int PlayerHeight, int PlayerWidth, long EquipmentID[], int MovementAmountX, int MovementAmountY){
        SDL_Surface* Image;
        SDL_Surface* EquipmentColorization;
        std::string FileName;
        int ID;


        Clean(BodyID,MovementAmountX*MovementAmountY,PlayerWidth,PlayerHeight);


        for(int i = -1; i < 8; i++){
            ID = 0;
            //here we put a small exception to firstly load the player. And only then dress Him
            if(i == -1){
                FileName = "resource/images/Player/WhiteMaleBody.png";
                goto playerbody;
            }
            if(EquipmentID[i] != 0){
                GetFileNameByID(EquipmentID[i],FileName);
            playerbody:
                Image = IMG_Load(FileName.c_str());
                if(Image == NULL){
                    exit(1);
                }

                //Needed for equipment coloring. At this point we will put RGB masks in order to color the armor by it's type
                EquipmentColorization = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, MovementAmountX*PlayerWidth, MovementAmountY*PlayerHeight, 32, 0, 0, 0, 0);


                GraphicsFunctions.MergeSurfaces(Image,EquipmentColorization,0,0,MovementAmountX*PlayerWidth,MovementAmountY*PlayerHeight,0,0);

                for(int i = 0; i < MovementAmountY; i++){
                    for(int j = 0; j < MovementAmountX; j++){
                        ID++;   
                        //We put the graphics on and on on top. So we dress the frames. BodyID[ID] are frames by motion ID. We just fill this up.
                        GraphicsFunctions.MergeSurfaces(    EquipmentColorization,BodyID[ID],
                                                            (j * PlayerWidth),
                                                            (i * PlayerHeight),
                                                            PlayerWidth,PlayerHeight,
                                                            0,0);

                        if(BodyID[i] == NULL){
                            exit(2);
                        }
                    }
                }
            }

        }
    }
这里是主线程控件。主系统线程、光点和翻转到您在此处看到的曲面

//------------------------------------------------------------------------------------------
//----MAIN Thread Function (As Thread Repeat to infinity LOL)
//------------------------------------------------------------------------------------------
    int Player_Main(void *unused){

        GraphicsFunctions.Setrgba();
        PlayerGraphics = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, 1024, 768, 32, GraphicsFunctions.r, GraphicsFunctions.g, GraphicsFunctions.b, GraphicsFunctions.a);
        while(!EndProgram){

            PlayerMovementGraphics::Variate(PlayerGraphics);

            SDL_Delay(200);
        }
        return 0;
    }
当然,这里需要改进。但自从我几周前开始研究SDL以来。我还有很多东西要学。这就是现在图形的基本功能。因此,也许你可以发现为什么播放器本身应该是透明的,而它本身是黑色的

你写:

SDL_CreateRGBSurface( SDL_HWSURFACE | SDL_SRCALPHA,
                      PlayerWidth, PlayerHeight, 
                      32, 0, 0, 0, 0 );
从:

对RGB遮罩使用零将根据深度设置默认值。但是,对
Amask
使用零会导致
Amask
为0

如果需要alpha通道,则需要明确指定遮罩:

SDL_CreateRGBSurface( SDL_HWSURFACE | SDL_SRCALPHA,
                      PlayerWidth, PlayerHeight, 32,
                      0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF );
SDL_CreateRGBSurface( SDL_HWSURFACE | SDL_SRCALPHA,
                      PlayerWidth, PlayerHeight, 
                      32, 0, 0, 0, 0 );
SDL_CreateRGBSurface( SDL_HWSURFACE | SDL_SRCALPHA,
                      PlayerWidth, PlayerHeight, 32,
                      0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF );