os:最新的ArchLinux。
你好, 使用此代码:
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
/* SDL */
SDL_Window *fenetre = NULL;
SDL_Renderer *rendu = NULL;
SDL_Texture *texture = NULL;
/* Init SDL */
if(0 != SDL_Init(SDL_INIT_VIDEO))
{
fprintf(stderr, "Erreur SDL_Init : %s", SDL_GetError());
goto Quit;
}
fenetre = SDL_CreateWindow(" Essai texture", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_SHOWN);
if(NULL == fenetre)
{
fprintf(stderr, "Erreur SDL_CreateWindow : %s", SDL_GetError());
goto Quit;
}
rendu = SDL_CreateRenderer(fenetre, -1, SDL_RENDERER_ACCELERATED);
if(NULL == rendu)
{
fprintf(stderr, "Erreur SDL_CreateRenderer : %s", SDL_GetError());
goto Quit;
}
/* Color */
if(0 != SDL_SetRenderDrawColor(rendu, 242, 243, 244, 255))
{
fprintf(stderr, "Erreur SDL_SetRenderDrawColor : %s", SDL_GetError());
goto Quit;
}
/* renderClear */
if(0 != SDL_RenderClear(rendu))
{
fprintf(stderr, "Erreur SDL_RenderClear : %s", SDL_GetError());
goto Quit;
}
/* Create la texture */
texture = SDL_CreateTexture(rendu, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET, 400, 400);
if(NULL == texture)
{
fprintf(stderr, "Erreur SDL_CreateTexture : %s", SDL_GetError());
goto Quit;
}
/* Colore la texture */
SDL_SetRenderTarget(rendu, texture);
SDL_SetRenderDrawColor(rendu, 242, 110, 160, 255);
SDL_RenderFillRect(rendu, NULL);
SDL_SetRenderTarget(rendu, NULL);
/* Show texture in bottom */
SDL_Rect dst = {50, 250, 400, 200};
SDL_RenderCopy(rendu, texture, NULL, &dst);
SDL_RenderPresent(rendu);
SDL_Delay(3000); //
/* And show texture in top */
dst.y = 50;
SDL_RenderCopy(rendu, texture, NULL, &dst);
SDL_RenderPresent(rendu);
SDL_Delay(3000);
Quit:
if(NULL != texture)
SDL_DestroyTexture(texture);
if(NULL != rendu)
SDL_DestroyRenderer(rendu);
if(NULL != fenetre)
SDL_DestroyWindow(fenetre);
SDL_Quit();
return 0;
}
在第二个SDL_RenderPresent中,纹理显示效果很好,但是背景中的窗口为黑色。 在CreateRenderer中使用标志SDL_RENDERER_SOFTWARE,效果很好。
我尝试使用debian,即使使用标志SDL_RENDERER_ACCELERATED也可以正常工作。
有人对Archlinux有点不便,也可能是解决方案。
先谢谢您