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

查看:30
本文介绍了在 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天全站免登陆