- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 SDL 和 OpenGL。我使用 SDL ttf 创建带有文本的表面,然后使用该表面创建纹理。
我正在尝试将 alpha channel (不透明度)应用于文本,我正在使用这种方式:
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 );
正确应用了不透明度,但 SDL_MapRGBA 在“newSurface”中创建了黑色背景。如何在不添加背景的情况下仅对文本应用 alpha/不透明度?
最佳答案
我认为您缺少 newSurface 的 SDL_SetColorKey。
像这样:
SDL_SetColorKey( newSurface , SDL_SRCCOLORKEY, SDL_MapRGB( newSurface->format, 0, 0, 0) );
或者更简单的方法是跳过用黑色矩形填充 newSurface
删除这个:
SDL_FillRect( newSurface, &rect, alpha);
下面是我如何用透明颜色制作图片的例子:
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)
关于c++ - 没有背景的透明 SDL_Surface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14718698/
一段时间以来一直试图在网上找到它。 我有一个带有一些内容的 SDL_Surface(其中一个是文本,另一个是 Sprite 的一部分)。在游戏循环中,我可以很好地将数据显示在屏幕上。但是然后它再次循环
情况:我正在尝试在 MainMenu 类中使用 load_image 方法,因此在我的主类中我可以调用 load_image 方法,同时在主菜单中。 问题:在 load_image 方法中,我收到错误
我想将 SDL_Surface 加载到带有填充的 OpenGL 纹理中(以便 NPOT->POT),然后在表面上应用颜色键。我要么最终对所有像素进行颜色键控,不管它们的颜色如何,要么根本不对任何颜色进
所以我正在编写一个用表面表填充屏幕的代码;这是代码: main.c #ifdef __cplusplus #include #else #include #endif #include #inc
我在创建 SDL_Surface 的动态表时遇到困难。看看这段代码: SDL_Surface **testA = new SDL_Surface *[2]; for(int i=0;i<2;i++)
我可以通过这样做来释放我的 SDL_Surface* 冲浪吗: SDL_Surface* surf; for(int i = 0; i < 5; i++){ surf
有什么方法可以将 SDL 表面复制到另一个表面,例如创建备份拷贝,而无需在修改拷贝时修改原件? *surface = *original_surface 不工作。 SDL_Surface 没有任何构造
我想使用一个集合来引用一些 TileObjects(一个用户定义的类),这样我就可以遍历它们并采取相应的行动,或者找到一个特定的对象并将其删除,等等。 问题是,我想做的一件事是访问成员函数“rende
假设我有一个只有一张图片的 SDL_Surface。如果我想让 SDL_Surface 拥有该图像的三个拷贝,一个在另一个下面怎么办? 我想出了这个函数,但它没有显示任何东西: void Elemen
我一直在使用 sdl ttf,现在,我正在创建一个用于多行文本渲染的文本渲染器函数。 我正在为每条线创建一个表面,在“全局”表面中进行 blitting,然后将该“全局”表面转换为纹理。 实际上我的问
所以这是我的问题。我有一个 DrawMgr 类,我在其中调用 DrawCube 函数,我在另一个类的函数中调用 SDL_Surface。我的主要问题是,当我开始将鼠标移到我创建的窗口上时,它会出现段错
我正在使用 SDL 和 OpenGL。我使用 SDL ttf 创建带有文本的表面,然后使用该表面创建纹理。 我正在尝试将 alpha channel (不透明度)应用于文本,我正在使用这种方式:
在我的应用程序中,我需要从 SDL_Surface 返回鼠标的相对位置,问题是返回的鼠标位置是相对于 SDL 窗口而不是 SDL_Surface 的。我想我的问题是最简单/最有效的方法是什么。有任何问
源始终为 320x240,目标始终为 640x480。 void DoDoubleScaling(SDL_Surface* dest, SDL_Surface* source) { asser
我想将所有 SDL_Surface 初始化为一个函数,以便拥有最清晰的 main 可能,但它似乎不起作用。我这样做是这样的: void setImages(SDL_Surface* mur, SDL_
检查 SDL_LockSurface 函数的实现时我偶然发现了这个: /* This needs to be done here in case pixels changes value */ sur
我正在尝试使用 SDL 制作一个非常小且简单的片段。这个就像一个魅力: SDL_Window * window = SDL_CreateWindow("SDLTest", 0, 0, SCREEN_W
我正在尝试从 SDL_Surface 获取像素的 RGB/RGBA 颜色。我在互联网上找到了这段代码,但它返回了奇怪的数字(67372036 表示 0 红色、0 绿色、255 蓝色的像素) Uint3
我真的不知道哪里出了问题(主要是因为我不知道给我报错的那一行是干什么的)。 我认为我不必向您展示那么多代码。我正在做的是尝试获取像素的 RGBA 值以查看 Alpha 值有多大。我正在使用它来确定它们
运行我的小行星游戏几分钟后,代表我的飞船的 SDL_Surface 消失了。以某种方式保存船的旋转图像(rot)的表面被设置为 NULL。我不知道为什么!在我添加 if(rot != NULL &&
我是一名优秀的程序员,十分优秀!