根据SDL2维基上的SDL_RenderSetScale()和SDL_RenderSetLogicalSize()的简短描述,我认为这些命令可以独立于其内容缩放整个帧,基本上就是在图形编辑器中缩放图像的方式。 / p>
在我以前只使用SDL_Rects和SDL_Textures进行缩放和渲染的程序中,似乎就是这种情况。但是,使用RenderDrawLine()绘制线条只是部分情况。
如果线与x轴或y轴平行,则线会正确缩放,但在任何其他情况下,线都不会缩放。
SDL_RenderSetScale( gRenderer, gScaler, gScaler );
SDL_SetRenderDrawColor( gRenderer, 0x00, 0x00, 0x00, 0xFF );
SDL_RenderClear( gRenderer );
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
SDL_RenderDrawLine( gRenderer, x1, y1, x2, y2 );
SDL_RenderPresent( gRenderer );
有没有办法使用SDL_RenderSetScale()无论角度如何缩放线?该函数如何决定缩放什么以及忽略什么?
答案 0 :(得分:1)
这是SDL渲染器的已知错误,线条绘制功能不会缩放,然后以自由角度绘制。它最近发布的SDL-2.0.6仍然存在(见/* FIXME: We can't use a rect for this line... */
):
static int
RenderDrawLinesWithRects(SDL_Renderer * renderer,
const SDL_Point * points, int count)
{
SDL_FRect *frect;
SDL_FRect *frects;
SDL_FPoint fpoints[2];
int i, nrects;
int status;
frects = SDL_stack_alloc(SDL_FRect, count-1);
if (!frects) {
return SDL_OutOfMemory();
}
status = 0;
nrects = 0;
for (i = 0; i < count-1; ++i) {
if (points[i].x == points[i+1].x) {
int minY = SDL_min(points[i].y, points[i+1].y);
int maxY = SDL_max(points[i].y, points[i+1].y);
frect = &frects[nrects++];
frect->x = points[i].x * renderer->scale.x;
frect->y = minY * renderer->scale.y;
frect->w = renderer->scale.x;
frect->h = (maxY - minY + 1) * renderer->scale.y;
} else if (points[i].y == points[i+1].y) {
int minX = SDL_min(points[i].x, points[i+1].x);
int maxX = SDL_max(points[i].x, points[i+1].x);
frect = &frects[nrects++];
frect->x = minX * renderer->scale.x;
frect->y = points[i].y * renderer->scale.y;
frect->w = (maxX - minX + 1) * renderer->scale.x;
frect->h = renderer->scale.y;
} else {
/* FIXME: We can't use a rect for this line... */
fpoints[0].x = points[i].x * renderer->scale.x;
fpoints[0].y = points[i].y * renderer->scale.y;
fpoints[1].x = points[i+1].x * renderer->scale.x;
fpoints[1].y = points[i+1].y * renderer->scale.y;
status += renderer->RenderDrawLines(renderer, fpoints, 2);
}
}
status += renderer->RenderFillRects(renderer, frects, nrects);
SDL_stack_free(frects);
if (status < 0) {
status = -1;
}
return status;
}
我认为这很快就会被修复,因为这是一个很少使用的功能。