[英]Can't create SDL2 texture using SDL_PIXELFORMAT_NV12 pixel format
I'm using SDL 2.0.5 and Windows 10 to create a window and display a texture. 我正在使用SDL 2.0.5和Windows 10创建一个窗口并显示纹理。
Everything works fine when the texture has been initialized with SDL_PIXELFORMAT_YV12 pixel format, but when I set the format to SDL_PIXELFORMAT_NV12, SDL_CreateTexture function returns null. 使用SDL_PIXELFORMAT_YV12像素格式初始化纹理后,一切工作正常,但是当我将格式设置为SDL_PIXELFORMAT_NV12时,SDL_CreateTexture函数返回null。
Here's the code: 这是代码:
SDL_Window* window = SDL_CreateWindow(
"Test",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
width,
height,
SDL_WINDOW_FULLSCREEN_DESKTOP
);
SDL_Renderer* renderer = SDL_CreateRenderer(window , -1, SDL_RENDERER_SOFTWARE);
SDL_Texture* texture = SDL_CreateTexture(
renderer,
SDL_PIXELFORMAT_NV12,
SDL_TEXTUREACCESS_STREAMING,
width,
height
);
Am I missing something? 我想念什么吗?
According to keltar's comment, SDL_PIXELFORMAT_NV12 requires an hardware acceleration. 根据keltar的评论,SDL_PIXELFORMAT_NV12需要硬件加速。
One solution is to use the OpenGL renderer which supports NV12 pixel format. 一种解决方案是使用支持NV12像素格式的OpenGL渲染器。
So, setting hint as follow: SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); 因此,设置提示如下:SDL_SetHint(SDL_HINT_RENDER_DRIVER,“ opengl”); and setting SDL_RENDERER_ACCELERATED flag to SDL_CreateRenderer function does the trick. 然后将SDL_RENDERER_ACCELERATED标志设置为SDL_CreateRenderer函数就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.