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 9255231
In Process

The Archive Base Latest Questions

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

I’m working with SDL and OpenGL. I’m using SDL ttf for create a surface

  • 0

I’m working with SDL and OpenGL.
I’m using SDL ttf for create a surface with the text, then create a texture with that surface.

I’m trying to apply an alpha channel (opacity) to the text, I’m using this way:

    SDL_Surface * fontsurf = TTF_RenderUTF8_Blended(font,buff_split.at(i).c_str(),color);
SDL_PixelFormat *format = fontsurf->format;
SDL_Surface* newSurface = SDL_CreateRGBSurface( SDL_SRCALPHA,
   fontsurf->w, fontsurf->h, 32,
   0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 );


    Uint32 alpha = 0;
    alpha = SDL_MapRGBA( newSurface->format, 0,0,0, color.unused);

    SDL_Rect rect;
    rect.x = 0;
    rect.y = 0;
    rect.h = fontsurf->h;
    rect.w = fontsurf->w;
    int ret = SDL_FillRect( newSurface, &rect, alpha);

    SDL_SetAlpha(newSurface,SDL_SRCALPHA,SDL_ALPHA_TRANSPARENT);

    ret = SDL_BlitSurface( fontsurf, 0, newSurface, 0 );

The opacity is applied correctly, but the SDL_MapRGBA creates a black background in the “newSurface”.
How can I apply alpha/opacity to the text, without adding a background, only the text?

  • 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:40:13+00:00Added an answer on June 18, 2026 at 11:40 am

    I think you are missing SDL_SetColorKey for newSurface.

    Something like this:

    SDL_SetColorKey( newSurface , SDL_SRCCOLORKEY, SDL_MapRGB( newSurface->format, 0, 0, 0) );
    

    or even easier would be to skip filling newSurface with a black rectangle

    remove this:

    SDL_FillRect( newSurface, &rect, alpha);
    

    Here is an example how I make a picture with transparent color:

    testImage = IMG_Load( "trans.png" );
    // This picture contains color 255,0,255 which will be set as transparent
    
    SDL_SetColorKey( testImage , SDL_SRCCOLORKEY, SDL_MapRGB( screen->format, 255, 0, 255) );
    // I set the color 255,0,255 as transparent for that surface
    
    SDL_BlitSurface( testImage , NULL , screen , NULL );
    // and I draw it on the main surface (screen)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.