SDL2 修改像素
SDL2 modifying pixels
我想用 SDL2 修改单个像素,但我不想用表面修改。
这是我代码的相关部分:
// Create a texture for drawing
SDL_Texture *m_pDrawing = SDL_CreateTexture(m_pRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, 1024, 768);
// Create a pixelbuffer
Uint32 *m_pPixels = (Uint32 *) malloc(1024*768*sizeof(Uint32));
// Set a single pixel to red
m_pPixels[1600] = 0xFF0000FF;
// Update the texture with created pixelbuffer
SDL_UpdateTexture(m_pDrawing, NULL, m_pPixels, 1024*sizeof(Uint32));
// Copy texture to render target
SDL_RenderCopy(m_pRenderer, m_pDrawing, NULL, NULL);
如果渲染,则使用 SDL_RenderPresent(m_pRenderer) 时屏幕上不会显示任何内容。 在这里,他们解释说,你可以使用"surface->pixels,或者malloc()'d缓冲区"。那么,出了什么问题呢?
编辑: 最后,这只是我的m_pRenderer,这是在SDL_CreateTexture电话之后定义的。 现在一切正常,我修复了缓冲区分配中的小错误,所以这段代码应该可以工作了。
我不确定这是否是您的问题,但这是一个错误:
Uint32 *m_pPixels = (Uint32 *) malloc(1024*768);
如果要分配足够的数据来表示曲面中的像素,则需要在其中* sizeof(Uint32)
:
Uint32 *m_pPixels = (Uint32 *) malloc(1024*768*sizeof(Uint32));
(如果这是C,则不需要演员表。
相关文章:
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 如何将CMSampleBufferRef/CIImage/UIImage转换为像素,例如uint8_t[]
- 在C++中查找像素 RGB 数据的最快方法是什么?
- 是否可以从 OpenGL 缓冲区获取原始大小的像素?
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 如何使用 sdl2 快速绘制像素网格?
- 如何在C++中进行像素操作? - Linux
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 访问随机图像像素的快速方法,最多一次
- OpenCV 像素访问点与 at() - 不同的值
- 如何使用 freetype2 访问单色位图中的像素状态
- 我想知道像素/片段的原始模板值.零还是一个?如果可能的话,以获取哪些特定操作会修改模板值
- ImageMagick C 版本7在空白图像中修改像素值
- SDL2 修改像素
- 如何在 openCV 中修改 cv::Mat 的像素数据
- 如何使用Imebra库修改DICOM文件中的图像像素
- 在多帧图像中插入修改过的像素数据