点缀0001

点缀0001

0个粉丝

5

问答

0

专栏

0

资料

点缀0001  发布于  2019-04-23 11:47:53
采纳率 0%
5个问答
3149

请教,使用 SDL_TTF 如何设置 OSD 背景色

 
本帖最后由 点缀0001 于 2019-4-23 11:50 编辑

按照社区的帖子,使用 freetype, sdl, sdl_ttf 来制作 osd
但是现在遇到问题,不知如何设置 osd  的背景色
尝试使用 TTF_RenderUTF8_Shaded 这个 api 设置背景色,但是无法把背景色设置透明
请教社区的前辈,对于 argb1555 和 argb8888 如何设置背景色呢?还有透明背景色如何处理

以下是使用 argb1555 测试的部分代码
        if (TTF_Init() < 0)
        {
                printf("Couldn't initialize TTF:%s\n", SDL_GetError());
                SDL_Quit();
                return -1;
        }
       
        font = TTF_OpenFont("./simsunb.ttf", 48);        // 24 32 48 64 96
        if (NULL == font)
        {
                printf("Couldn't load %d pt font from %s:%s\n", 18, "ptsize", SDL_GetError());
                return -1;
        }

        fmt = (SDL_PixelFormat *)malloc(sizeof(SDL_PixelFormat));
        memset(fmt, 0, sizeof(SDL_PixelFormat));

        fmt->format = SDL_PIXELFORMAT_ARGB1555;

        fmt->Amask = 0x01 << 15;
        fmt->Rmask = 0x1f << 10;
        fmt->Gmask = 0x1f << 5;
        fmt->Bmask = 0x1f << 0;

        fmt->Ashift = 15;
        fmt->Rshift = 10;
        fmt->Gshift = 5;
        fmt->Bshift = 0;

        stBitmap->enPixelFormat = PIXEL_FORMAT_RGB_1555;       

        //  alpha 0 % = 00, 透明。 100%=FF 不透明。
        SDL_Color forecol[ ] =
        {
                { 0xff, 0x00, 0x00, 0xff },                // red
                { 0xff, 0xff, 0x00, 0xff },                // yellow
                { 0x00, 0x00, 0xff, 0xff },         // blue
                { 0x00, 0xff, 0x00, 0xff },         // green
                { 0xff, 0xff, 0xff, 0xff },         // white
                { 0x00, 0x00, 0x00, 0xff },         // black               
                { 0x00, 0x00, 0x00, 0x00 },         // transparent
        };
               
#if 0
        text = TTF_RenderUTF8_Solid(font, osdContent, forecol[fg_index]);
#else
        text = TTF_RenderUTF8_Shaded(font, osdContent, forecol[fg_index], forecol[bg_index]);
#endif

        temp = SDL_ConvertSurface(text, fmt, 0);       
我来回答
回答3个
时间排序
认可量排序

qn1540561804

0个粉丝

12

问答

0

专栏

1

资料

qn1540561804 2019-04-23 19:34:07
认可0
https://blog.csdn.net/weixin_43549602/article/details/84945036

点缀0001

0个粉丝

5

问答

0

专栏

0

资料

点缀0001 2019-04-23 20:30:38
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=142509&ptid=74398]qn1540561804 发表于 2019-4-23 19:34[/url]
https://blog.csdn.net/weixin_43549602/article/details/84945036[/quote]

感谢大神,刚刚看了下,感觉您的方法比较复杂哈,生成位图过程要处理太多

qn1597046879

0个粉丝

3

问答

0

专栏

0

资料

qn1597046879 2020-09-25 14:35:42
认可0
请问最后解决了吗
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区