当我缩放窗口时,SDL 只是忽略我设置的分辨率并在像素上绘制对角线。 这是 SDL2,我使用
SDL_RenderGeometry
来绘制三角形。
这是我创建窗口的方法:
static inline void canvas_init(Canvas* canvas) {
SDL_CreateWindowAndRenderer(canvas->width * canvas->scale_x, canvas->height * canvas->scale_y, 0, &(canvas->window), &(canvas->renderer));
SDL_RenderSetScale(canvas->renderer, canvas->scale_x, canvas->scale_y);
SDL_Init(SDL_INIT_VIDEO);
}
我尝试了一些创建后备缓冲区的方法,但我可能做错了,而且它无法正常工作。
谢谢你的评论,这样做就可以了
创建一个低分辨率纹理,绘制它,但在显示它之前,将其复制到窗口纹理
static inline void canvas_init(Canvas* canvas) {
SDL_CreateWindowAndRenderer(canvas->width * canvas->scale_x, canvas->height * canvas->scale_y, SDL_WINDOW_ALWAYS_ON_TOP, &(canvas->window), &(canvas->renderer));
canvas->texture = SDL_CreateTexture(canvas->renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, canvas->width, canvas->height);
SDL_Init(SDL_INIT_EVERYTHING);
}
static inline void canvas_update(Canvas canvas, uint16_t delay) {
SDL_SetRenderTarget(canvas.renderer, NULL);
SDL_RenderCopy(canvas.renderer, canvas.texture, NULL, NULL);
canvas_display(canvas);
SDL_SetRenderTarget(canvas.renderer, canvas.texture);
canvas_color(canvas, (Color) {0, 0, 0, 255});
canvas_clear(canvas);
canvas_delay(delay);
}