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

  • Home
  • SEARCH
  • 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 9256581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:58:40+00:00 2026-06-18T11:58:40+00:00

I have been working with sdl ttf, Now, I’m creating a text renderer function

  • 0

I have been working with sdl ttf, Now, I’m creating a text renderer function for multiline text rendering.

I am creating a surface for each line, blitting in in a “global” surface, and then converting that “global” surface to a texture.

Actually My problem is the following: If I let the global surface transparent, the blitting does not works (It shows an empty surface), If I set that SDL_FillRect, and then do the SDL_SetColorKey, does not works.

I tried to do that with a per-pixel method, it works, but it’s not the result expected.

What I need actually is: Blit surfaces (Text rendered surfaces with TTF_RenderText_Blended), blit them inside a SDL_Surface with a transparent background, that’s all.

SDL_Surface * surfed_texture = SDL_CreateRGBSurface(SDL_SWSURFACE,surface_width,surface_height,32,
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);

Uint32 tormv = SDL_MapRGB(surfed_texture->format,255,0,255);

int possiblecolors[] = { 255,0,255,255,255,255 };

int in_pc = 0;

if(color.r == possiblecolors[0] && color.g == possiblecolors[1] && color.b == possiblecolors[2]){
    in_pc=3;
}

/*SDL_FillRect(surfed_texture,NULL,SDL_MapRGB(surfed_texture->format,possiblecolors[in_pc],possiblecolors[in_pc+1],possiblecolors[in_pc+2]));
SDL_SetColorKey(surfed_texture, SDL_SRCCOLORKEY, SDL_MapRGB(surfed_texture->format,possiblecolors[in_pc],possiblecolors[in_pc+1],possiblecolors[in_pc+2]));
*/
SDL_Surface * temporal = NULL;
for(int i=0;i<(int)buff_split.size();i++){
    const char* c_text = buff_split.at(i).c_str();

    temporal = TTF_RenderText_Blended(font,c_text,color);

    int w_fo;
    int h_fo;
    TTF_SizeText(font,c_text,&w_fo,&h_fo);

    SDL_Rect rct;
    rct.y=i*lineSkip;

    if(txt_align==ALIGN_LEFT){
        rct.x=0;
    }else if(txt_align==ALIGN_CENTER){
        rct.x = surface_width/2 - w_fo/2;
    }else if(txt_align==ALIGN_RIGHT){
        rct.x = surface_width - w_fo;
    }

    rct.w=0;
    rct.h=0;

    // Blit surface

    SDL_BlitSurface(temporal,NULL,surfed_texture,&rct);

    SDL_FreeSurface(temporal);

}

Blitting into “surfed_texture” with transparent background = Does not shows the blitted surface.
Per-Pixel method: Does not removes all the background.

And the SDL_SetColorKey is not working! (I already tried SDL_DisplayFormatAlpha and stills not working).

Some help?

  • 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-06-18T11:58:41+00:00Added an answer on June 18, 2026 at 11:58 am

    The solution is the following:

    Use the SDL_SetAlpha NOT in the “global” surface, apply a SDL_SetAlpha to each “temporal” surface with no flags, and with a value of 0:

    SDL_SetAlpha(temporal,NULL,0);
    

    Now it’s working fine!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with Zend for a few months now and am at
I have been working on a small app and at some point while creating
I have been working on this site for a few days now and am
Have been working on a Tower Defense game for iOS for some time now.
I have been working a year now as a software developer for a at
I have been working with ASP.NET MVC for a couple of months now and
I have been working on a C++ project that uses SDL, and wonder if
I have been working with AndEngine and developing a game. I have now moved
I have been working on a widet for a while now and I have
I have been trying to get this working for a while now and am

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.