Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:50:54+00:00 2026-05-30T08:50:54+00:00

For a few weeks me and my friends are working on a project. A

  • 0

For a few weeks me and my friends are working on a project. A game to be exact. And we came to a huge problem that ruins the game-play. The should be transparent part of player is black.

The MergeSurfaces function, is the blit. In itself the rects are written to the SDL_Rect, and blit is performed

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

This is the player forming function.

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

        }
    }

The Clean function if you wonder what it does. I don’t free the surfaces here yet. Since I do it at the end of program, and this is loaded once so far. So basically it is just for creating those surfaces in order to fill them up.

void Clean(SDL_Surface* TheSurface[], int MovementAmount, int PlayerWidth, int PlayerHeight){
        GraphicsFunctions.Setrgba();
        for(int i = 0; i <= MovementAmount; i++){
            TheSurface[i] = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, PlayerWidth, PlayerHeight, 32, 0, 0, 0, 0);
        }
    }

Next goes the Framing part, or making the character look that is moving. It is called elsewhere, so I could control the speed easily.

void Variate(SDL_Surface* Graphical_Output){
        GraphicsFunctions.MergeSurfaces(BodyID[MovementVariationID[MovementID][Variation]], Graphical_Output, 0, 0, PlayerWidth, PlayerHeight, 0, 0);
        Variation++;
        if(Variation == MovementVariationIn[MovementID]){
            Variation = 0;
        }
    }

Here is the main thread control. The Main system thread, Blits and Flips to the surface what you see here.

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

Of course there are improvements needed to be implemented here. But since I started working on SDL just a few weeks ago. I still have much to learn. That’s basically all there is with graphics right now. So maybe you could detect why the player itself has black where it should be transparent.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:50:55+00:00Added an answer on May 30, 2026 at 8:50 am

    You write:

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

    From the documentation:

    Using zeros for the RGB masks sets a default value, based on the depth. However, using zero for the Amask results in an Amask of 0.

    You’ll need to specify your masks explicitly if you want an alpha channel:

    SDL_CreateRGBSurface( SDL_HWSURFACE | SDL_SRCALPHA,
                          PlayerWidth, PlayerHeight, 32,
                          0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For the past few weeks I have been working on an app that uses
I've been a few weeks working on a web project, amd mostly thinking how
So the past few weeks I've been working on a page that pulls from
After only a few weeks of working with Drupal I've come up with a
I forked a project a few weeks ago. The main repository is on a
I've started working on a new web project with some friends... we are using
A few weeks ago I asked about Application Servers. It happens that my bosses
A few weeks ago I found somewhere a code that allows one to dump
Few weeks back only, I came to know about LESS CSS. And it is
A few weeks ago I started my first project with TDD. Up to now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.