SDL_Surface* surf = IMG_Load("Image.PNG");
int width = surf->w;
int height = surf->h;
int clipPerRow = 16;
int clipPerColumn = 16;
SDL_Texture* texture = SDL_CreateTextureFromSurface(RENDERER,surf);
SDL_FreeSurface(surf);
SDL_Texture* clip[clipPerRow][clipPerColumn];
for(int i=0; i<clipPerRow; i++)
{
for(int j=0;j<clipPerColumn;j++)
{
clip[i][j] = SDL_CreateTexture(RENDERER, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width/clipPerRow, height/clipPerColumn);
SDL_SetTextureBlendMode(clip[i][j], SDL_BLENDMODE_BLEND);
SDL_Rect rect = {i*width/clipPerRow,j*height/clipPerColumn, width/clipPerRow, height/clipPerColumn};
SDL_SetRenderTarget(RENDERER, clip[i][j]);
SDL_RenderCopy(RENDERER, texture, &rect, NULL);
}
}
SDL_SetRenderTarget(RENDERER, NULL);
int x= 100;
int y =100;
while(!quit){
while(SDL_PollEvent(&e)) if(e.type == SDL_QUIT) quit = 1;
SDL_SetRenderDrawColor(RENDERER, 0x00, 0x00,0x00,0x00);
SDL_RenderClear(RENDERER);
for(int i=0; i<clipPerRow; i++)
{
for(int j=0;j<clipPerColumn;j++)
{
SDL_Rect rect = {x+i*width/clipPerRow,y+j*height/clipPerColumn, width/clipPerRow, height/clipPerColumn};
SDL_RenderCopy(RENDERER,clip[i][j],NULL,&rect);
}
}
SDL_RenderPresent(RENDERER);
}
당신은 크기 16 × 16의 텍스처의 배열을 생성하고 난 위키 [여기] (HTTPS에보고했다 – Elvisjames
@Elvisjames SDL_SetRenderTarget' 기능을'사용하여 작은 16 × 16 텍스처에 큰 질감에서 부분을 렌더링 할 수 있습니다 : //wiki.libsdl.org/SDL_SetRenderTarget)하지만 프로그램에서이를 사용하는 방법에 대한 예는 없습니다. 이것을 가장 효과적으로 사용하는 방법에 대한 예를 들려 주시겠습니까? – user2862660