使用OpenGL-ES绘制点划线 [英] Drawing Stippled Lines using OpenGL-ES

查看:126
本文介绍了使用OpenGL-ES绘制点划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序可以绘制3-d地图视图,并用标记线显示各种功能. 我正在将地图移植到OpenGL-ES架构上,但是在确定如何显示虚线时遇到了一些麻烦.

I have an application that draws 3-d map view marked up lines that show various features. I am porting the map over to an OpenGL-ES architecture, but am having a bit of trouble working out how to display dashed lines.

通过大量的谷歌搜索,我发现很多关于从OpenGL-ES中删除虚线和多边形的想法,因为可以使用纹理三角形轻松地模拟它们.很好,但是我找不到真正进行此仿真和/或对所涉及步骤进行描述的人.

Doing a lot of googling, I've found many references to the idea that drawing dashed lines and polygons were removed from OpenGL-ES as they can be easily emulated using textures triangles. That's great, but I can't find anyone that actually does this emulation and/or has a description of the steps involved.

一个例子,就是我尝试将这个概念原型化时遇到的一个问题,就是透视图将我的线条向水平方向挤压为不可见.使用LINE_STRIP不会发生这种情况,并且线在地图中保持恒定的宽度.

An example, of one problem I have encountered trying to prototype out this concept is perspective squeezes my lines to invisible as they go towards the horizon. Using LINE_STRIP, this doesn't happen, and the lines remain a constant width in the map.

对于在透视图中如何实现等宽虚线的建议,将不胜感激.

Any advice on how to achieve dashed constant width lines in a perspective view would be much appreciated.

推荐答案

我相信您可以将纹理应用于直线,而不仅仅是三角形.您需要为该行的每一端设置纹理坐标;纹理将沿着直线线性插值.

I believe you can apply a texture to a line, not just a triangle. You'll need to set texture coordinates for each end of the line; the texture will be interpolated linearly along the line.

此解决方案的有效性应取决于您使用线还是线带-线带只是创建具有较少顶点的线的一种方式.

The effectiveness of this solution should be invariant of whether you use lines or line strips - line strips are just a way to create lines with fewer vertices.

还有一个问题:随着线条远离相机,纹理图案趋于紧凑的趋势.发生这种情况是因为纹理坐标插值即使对于直线也是正确的(请参见GL规范的3.5节).

There is one other problem: the tendency of the texture pattern to become compact as a line goes away from the camera. This happens because texture coordinate interpolation is perspective-correct even for lines (see section 3.5 of the GL spec).

有两种方法可以解决此问题:

There are two ways to get around this:

  1. 如果可以为撤消透视的纹理计算"q"坐标,则可以恢复屏幕空间纹理.这种技术可能太昂贵了.

  1. If you can calculate a "q" coordinate for your texture that undoes the perspective, you can restore screen-space texturing. This technique is probably too performance-expensive.

您可以在眼睛空间中投射纹理(例如glTexGen).

You can project the texture in eye space (e.g. glTexGen).

纹理坐标生成在GLES 1.1中当然不可用,但是如果您按数组使用顶点,则可以通过以下方式进行伪造:

Texture coordinate generation is of course not available in GLES 1.1, but if you are using vertices by array, you can fake it by:

  • 将纹理坐标数组设置为顶点坐标数组,并且
  • 使用纹理矩阵转换"顶点.

此技术的缺点是纹理图案将位于固定的屏幕空间中-也就是说,纹理不会跨线分布.

The disadvantage of this technique is that the texture pattern will be in fixed screen space - that is, the texture won't run across the lines.

这篇关于使用OpenGL-ES绘制点划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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