gpt4 book ai didi

c++ - SDL_RenderSetScale 和 SDL_RenderDrawLine 如何交互?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:08:06 25 4
gpt4 key购买 nike

根据 SDL2 wiki 上 SDL_RenderSetScale() 和 SDL_RenderSetLogicalSize() 的简短描述,我的印象是这些命令独立于其内容缩放整个帧,基本上与您在图形编辑器中缩放图像的方式相同。

在我以前的程序中,我只缩放和渲染 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() 来缩放线条而不考虑角度?该函数如何决定缩放什么和忽略什么?

最佳答案

这是SDL渲染器的一个已知bug,画线功能不能缩放然后以自由角度绘制。它仍然存在于最近发布的 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;
}

我认为这不会很快得到解决,因为这是一个很少使用的功能。

关于c++ - SDL_RenderSetScale 和 SDL_RenderDrawLine 如何交互?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46474332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com