以下是基本情况:我有一个绘制2D符号的OpenGL VBO(例如多边形或线条或其他 - 本质上是简单的精灵)。我已经定义了原点周围的顶点(0,0),这样我就可以在屏幕像素中获得所需的符号大小。使用OpenGL和VBOs绘制未缩放的2D符号(精灵)
我的当前场景已被翻译和缩放并正投影显示模型的特定区域。我现在想要绘制符号,使其以特定模型位置为中心,但不与模型一起缩放(即绘制到VBO中定义的屏幕像素大小)。我宁愿这样做,而不必以编程方式重新填充符号的顶点缓冲区(即,我想使用平移和/或缩放来在屏幕像素中绘制符号,但是在所需位置 - 这是在“模型”坐标中定义)。
一个简单的例子:显示使用经度和纬度的地图,并且用户已经平移和放大到世界的特定区域。用户点击感兴趣的站点,并且我想在该点显示“明星”。明星将随地图平移,但保持与用户放大或缩小的大小相同。因此,在任何时候我都知道在哪里(经度,纬度坐标)将“恒星”“中心”,并且我有一个为所需大小的恒星(以原点为中心)定义的VBO(以像素坐标表示)。
那么,在这种情况下渲染“未缩放”符号/精灵的“最佳”方式是什么?
我想我有一个想法,应该怎么做,但(1)我不确定这个方法是否正确,(2)它看起来没有像我期望的那样工作。下面是我的总体思路的一些伪代码:
void DrawSymbol()
{
...
[Not Shown: Determine the screen coordinates of the symbol's desired model location]
gl.MatrixMode(GL_PROJECTION);
gl.PushMatrix(); // Store the current projection
gl.LoadIdentity(); // Set projection to identity (no projection)
gl.MatrixMode(GL_MODELVIEW);
gl.PushMastrix(); // Store the current model view (was scaled and translated)
gl.LoadIdentity(); // Set model view matrix to identity (1-to-1 with screen coords)
[Not Shown: Translate the model view so that the origin is at the desired screen coordinate found above]
[Not Shown: Draw the VBO for the symbol] // should draw to raw screen pixels, right?
gl.MatrixMode(GL_MODELVIEW);
gl.PopMatrix(); // Set model view matrix to previous value -- should only effect any future renders, right?
gl.MatrixMode(GL_PROJECTION);
gl.PopMatrix(); // Set projection matrix to previous value -- again, should only effect any future renders, right?
...
}
这个(实际上,我尝试了通过在需要的屏幕位置直接呈现一个简单的LineStrip而不是使用翻译VBO我试过 - 只是为了测试),它似乎没有工作。不知道为什么。这种方法听起来不错吗?
对此提出建议?
嗯......我怎么在这里做一个“没关系”的SO?我意识到我需要在绘制符号/精灵之前重新建立正投影。这似乎现在正在工作。不过,我不确定是否有更好的方法来做到这一点。我应该把问题留下吗?自己回答(呃 - 仍然觉得不对)? – FTLPhysicsGuy