在openGL中绘制可变宽度的线(无glLineWidth) [英] Drawing a variable width line in openGL (No glLineWidth)

查看:109
本文介绍了在openGL中绘制可变宽度的线(无glLineWidth)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不使用glLineWidth绘制可变宽度线的最佳方法是什么? 只是画一个矩形? 各种平行线? 以上都不是吗?

What is the best way to draw a variable width line without using glLineWidth? Just draw a rectangle? Various parallel lines? None of the above?

推荐答案

假设您的原始点是(x1,y1)->(x2,y2).使用以下点(x1-width/2,y1),(x1 + width/2,y1),(x2-width/2,y2),(x2 + width/2,y2)构造一个矩形,然后使用四边形/三边形来绘制它.这是简单的天真方式.请注意,对于较大的线宽,您将获得奇怪的端点行为.然后,您真正想做的就是使用矢量数学进行一些智能的平行线计算(应该没那么糟).由于某种原因,点/叉积和矢量投影浮现在脑海.

Assume your original points are (x1,y1) -> (x2,y2). Use the following points (x1-width/2, y1), (x1+width/2,y1), (x2-width/2, y2), (x2+width/2,y2) to construct a rectangle and then use quads/tris to draw it. This the simple naive way. Note that for large line widths you'll get weird endpoint behavior. What you really want to do then is some smart parallel line calculations (which shouldn't be that bad) using vector math. For some reason dot/cross product and vector projection come to mind.

这篇关于在openGL中绘制可变宽度的线(无glLineWidth)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆