SDL_Texture* SDL_CreateTexture(SDL_Renderer* renderer, Uint32 format, int access, int w, int h)
renderer | レンダリングコンテキスト |
format | SDL_PixelFormatEnumの1つ |
access | SDL_TextureAccessの1つ |
w | テクスチャの幅 |
h | テクスチャの高さ |
#include<stdlib.h>
#include"SDL.h"
// 四角形を動かす
int main()
{
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *Texture;
SDL_Event event;
SDL_Rect r;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLを初期化できなかった: %s", SDL_GetError());
return 3;
}
window = SDL_CreateWindow("SDL_CreateTexture",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
1024, 768,
SDL_WINDOW_RESIZABLE);
r.w = 100;
r.h = 50;
renderer = SDL_CreateRenderer(window, -1, 0);
Texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 1024, 768);
while(1)
{
SDL_PollEvent(&event);
if(event.type == SDL_QUIT)
break;
r.x=rand()%500;
r.y=rand()%500;
SDL_SetRenderTarget(renderer, Texture);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
SDL_RenderClear(renderer);
SDL_RenderDrawRect(renderer,&r);
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0x00);
SDL_RenderFillRect(renderer, &r);
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderCopy(renderer, Texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
return 0;
}
テクスチャを生成する前にSDL_HINT_RENDER_SCALE_QUALITYを設定することでテクスチャの拡大方法を設定できる.