不确定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);
如果我的Window像素格式是RGB888,我是否也应该使用相同的格式创建纹理以避免转换?