SDL中文论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 4334|回复: 0
打印 上一主题 下一主题

[Discuss] 操作矩形

[复制链接]

149

主题

331

帖子

2445

积分

版主

Rank: 7Rank: 7Rank: 7

积分
2445
跳转到指定楼层
楼主
发表于 2017-3-16 21:40:23 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 ancientcc 于 2017-3-16 21:41 编辑


生成一个clip_rect和(dstrect->x, dstrect->y, srcw, srch)的交叉矩形
  1. SDL_Rect calculate_screen_clip_rect(int srcw, int srch, const SDL_Rect& clip_rect, SDL_Rect* dstrect)
复制代码


参数
srcw、srch贴图宽度、高度。dstrect表标贴图,但那里只表示左上角。对应图中A、B、C的宽度、高度。
clip_rect背景矩形。
dstrect贴图左上角坐标。它和clip_rect属于同一个坐标系。未使用dstrect的w、h,原因是此函数代码抄自SDL_UpperBlit,后者未使用w、h。


返回值
一个clip_rect和(dstrect->x, dstrect->y, srcw, srch)的交叉矩形

范例
  1. void tcanvas::blit(const tcontrol& widget, texture& surf, SDL_Rect rect, ...)
  2. {
  3.         SDL_Rect r = rect;
  4.         SDL_RenderGetClipRect(get_renderer(), &clip_rect);
  5.         clip_rect = calculate_screen_clip_rect(w_, h_, clip_rect, &r);
  6.         ......
  7. }
复制代码
Rose使用的裁剪是逐片断操作中的Scissor,为减少片断着色器执行次数,给它的矩形要尽可能准确。代码中clip_rect、r都是窗口坐标系中的坐标。

注释
函数生成一个矩形,该矩形的宽度、高度来自clip_rect和贴图交叉部分,见图中划线部分。左上角是偏移(不是dstrect的左上角+偏移),像图中A是(dx, dy)。对贴图C,它不须要偏移,因而生成的左上角就(0, 0)。

此函数一般用块移,而且假设块移过程不会发生缩放。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|丽谷软件|libsdl.cn

GMT+8, 2025-5-2 05:25 , Processed in 0.045122 second(s), 22 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表