首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SDL创建透明曲面

SDL创建透明曲面
EN

Stack Overflow用户
提问于 2013-05-17 21:54:59
回答 3查看 4.4K关注 0票数 4

我正在搜索如何在SDL中创建透明表面,我找到了以下内容:http://samatkins.co.uk/blog/2012/04/25/sdl-blitting-to-transparent-surfaces/

基本上,它是:

代码语言:javascript
运行
复制
SDL_Surface* surface;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
surface = SDL_CreateRGBSurface(SDL_HWSURFACE,width,height,32, 0xFF000000, 0x00FF0000,        0x0000FF00, 0x000000FF);
#else
surface = SDL_CreateRGBSurface(SDL_HWSURFACE,width,height,32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
#endif

它是有效的,但对我来说它似乎非常糟糕,所以我想知道是否有更好的方法来做到这一点。

EN

回答 3

Stack Overflow用户

发布于 2013-05-17 22:22:39

这里有一个检查,看看计算机使用的是高字节优先还是低字节优先。SDL是多平台的,计算机使用不同的字节顺序。

那篇文章的作者是以一种“平台不可知论”的方式写的。如果您在PC上运行此程序,使用以下命令可能是安全的:

代码语言:javascript
运行
复制
surface = SDL_CreateRGBSurface(SDL_HWSURFACE,width,height,32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);

你不需要条件句。

也就是说,这些代码不能移植到其他使用高字节数组的平台上

票数 1
EN

Stack Overflow用户

发布于 2017-01-02 14:08:03

在我的IT课程中,我有一些使用SDL2的经验。但我一直在开发使用SDL的函数的简化版本,我加载图像的方式如下所示:

代码语言:javascript
运行
复制
ImageId LoadBmp(string FileName, int red, int green, int blue){
SDL_Surface* image = SDL_LoadBMP(FileName.c_str()); // File is loaded in the SDL_Surface* type variable

GetDisplayError(!image, string("LoadBmp:\n Couldn't load image file ") + FileName); // Check if the file is found

Images.push_back(image); // Send the file to the Images vector


SDL_SetColorKey(Images[Images.size() - 1], SDL_TRUE, // enable color key (transparency)
    SDL_MapRGB(Images[Images.size() - 1]->format, red, green, blue)); // This is the color that should be taken as being the 'transparent' part of the image

                                                                      // Create a texture from surface (image)
SDL_Texture* Texture = SDL_CreateTextureFromSurface(renderer, Images[Images.size() - 1]);
Textures.push_back(Texture);

return Images.size() - 1; // ImageId becomes the position of the file in the vector}

你可能会寻找的是

代码语言:javascript
运行
复制
SDL_SetColorKey(Images[Images.size() - 1], SDL_TRUE, // enable color key (transparency)
SDL_MapRGB(Images[Images.size() - 1]->format, red, green, blue)); // This is the color that should be taken as being the 'transparent' part of the image

通过这样做,可以将给定的RGB设置为透明。希望这能有所帮助!这是我目前正在使用的SDL模板,您应该可以使用其中的一些模板!https://github.com/maxijonson/SDL2.0.4-Ready-Functions-Template

票数 0
EN

Stack Overflow用户

发布于 2015-04-12 03:15:19

实际上我们称之为Alpha混合,你可以在这里查看它:http://lazyfoo.net/tutorials/SDL/13_alpha_blending/index.php

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16610829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档