SDL2 SDL_GetWindowSurface 返回未知像素格式的表面

问题描述 投票:0回答:1

不确定为什么 SDL_GetWindowSurface 返回具有未知像素格式的表面。

Outputs: 
Window pixel format SDL_PIXELFORMAT_RGB888 
Surface pixel format SDL_PIXELFORMAT_UNKNOWN

代码如下:

char message[256]="";
SDL_Rect rc;
SDL_Window *myWindow;
SDL_Renderer *myRenderer;
SDL_Surface *mySurface;
SDL_Texture *myTexture;

rc.x=100;
rc.y=100;
rc.w=CWState->WindowSize.x;
rc.h=CWState->WindowSize.y;

 //Initialize SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0 )
{
    printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
    return false;
}

myWindow = SDL_CreateWindow("myWindow", rc.x, rc.y, rc.w, rc.h, 0);
mySurface = SDL_GetWindowSurface( myWindow );
myRenderer = SDL_CreateRenderer(myWindow, -1, SDL_RENDERER_PRESENTVSYNC);
myTexture = SDL_CreateTexture(myRenderer,SDL_PIXELFORMAT_ARGB8888,SDL_TEXTUREACCESS_STREAMING,rc.w, rc.h);
SDL_SetTextureBlendMode(myTexture,SDL_BLENDMODE_NONE);

sprintf(message, "Window pixel format %s\n", SDL_GetPixelFormatName(SDL_GetWindowPixelFormat(myWindow)));
puts(message);
sprintf(message, "Surface pixel format %s\n", SDL_GetPixelFormatName(mySurface->format));
puts(message);

另外,如果我的窗口像素格式是 RGB888,我是否应该创建具有相同格式的纹理以避免转换?

window textures sdl-2 surface
1个回答
0
投票

也许它会对某人有所帮助: 我们需要将

(surface->format)->format
放入函数中。

© www.soinside.com 2019 - 2024. All rights reserved.