c++ - SDL_CreateTextureFromSurface 然后 SDL_UpdateTexture 弄乱颜色
问题描述
我将 png 文件加载到表面并从中创建纹理
后来我修改了表面然后使用 SDL_UpdateTexture
问题:
SDL_CreateTextureFromSurface 尊重从表面到纹理的颜色格式
而 SDL_UpdateTexture 没有(交换红色和蓝色)
SDL_UpdateTexture(texture, NULL, (Uint8*)surface->pixels, surface->w * sizeof(Uint32));
这是加载文件的代码,没什么特别的
void MyClass::loadFromFile( std::string path)
{
surface = IMG_Load( path.c_str() );
//SDL_SetColorKey( surface, SDL_TRUE, SDL_MapRGB( surface->format, 0, 0xFF, 0xFF ) );
texture = SDL_CreateTextureFromSurface( core->getRenderer(), surface );
}
我试过了 :
- 评论 SDL_SetColorKey
- 注释修改表面像素的代码(只需调用 SDL_UpdateTexture )
这看起来真的像一个 SDL 错误,因为我无法将任何格式传递给 SDL_UpdateTexture
我错过了什么吗?
解决方案
SDL_UpdateTexture 可能有问题,所以我只是复制像素
gStreamingTexture.lockTexture();
gStreamingTexture.copyPixels( gDataStream.getBuffer() );
gStreamingTexture.unlockTexture();
copyPixels 就是这样做的
memcpy( mPixels, pixels, mPitch * mHeight );
详细信息:https ://lazyfoo.net/tutorials/SDL/42_texture_streaming/index.php
推荐阅读
- ios - 在 uitableview 部分中组织日期
- java - Spock - 模拟存储库方法 save() 给出 NullPointerException
- python - smtplib 无法连接到 mailgun
- ionic-framework - Filter results with ion-select
- java - AUTO IT & Selenium 无法将密钥发送到 JAVA Applet(Oracle Flexcube 应用程序)
- node.js - 使用 NodeJ 进行压缩
- python - 从不同层次结构中导入 Python 模块
- spring - 覆盖托管版本 json maven 依赖项
- excel - excel SUMIFS,两行有 3 个条件
- php - 显示自定义会话的 SweetAlert?