如何在OpenGL中绘制点的轮廓? [英] How to draw outline of a point in OpenGL?
问题描述
现在可以使用以下代码绘制点:
By now points can be drawn with the following code:
// SETUP FOR VERTICES
GLfloat points[graph->vertexCount * 6];
for (int i = 0 ; i < graph->vertexCount; i++)
{
points[i*6] = (graph->vertices[i].x / (backingWidth/2) ) - 1;
points[i*6+1] = -(graph->vertices[i].y / (backingHeight/2) ) + 1;
points[i*6+2] = 1.0;
points[i*6+3] = 0.0;
points[i*6+4] = 0.0;
points[i*6+5] = 1.0;
}
glEnable(GL_POINT_SMOOTH);
glPointSize(DOT_SIZE*scale);
glVertexPointer(2, GL_FLOAT, 24, points);
glColorPointer(4, GL_FLOAT, 24, &points[2]);
glDrawArrays(GL_POINTS, 0, graph->vertexCount);
这些点用红色渲染,我想在这些点之外添加白色轮廓.如何绘制该点的轮廓?
The points are rendered with red color, and I want to add a white outline outside the points. How can I draw outline of the point?
问题,以更好地显示
按照@BDL的说明在红色点下方添加较大的点作为轮廓,它们看起来不错.
Follow @BDL 's instruction adding bigger points under the red points as outline, they look good.
outlinePoints[i*6] = (graph->vertices[i].x / (backingWidth/2) ) - 1;
outlinePoints[i*6+1] = -(graph->vertices[i].y / (backingHeight/2) ) + 1;
outlinePoints[i*6+2] = 0.9;
outlinePoints[i*6+3] = 0.9;
outlinePoints[i*6+4] = 0.9;
outlinePoints[i*6+5] = 1.0;
但是当一个点与另一点重叠时,其轮廓被红色点覆盖,因为轮廓点在所有红色点之前绘制.
But when one point overlaps another point, it's outline is covered by the red point, since the outline points are rendered before all the red points.
我认为正确的解决方案是逐个渲染一个轮廓点和一个红色点.该怎么做?
I think the right solution is to render one outline point and red point one by one. How to do that?
推荐答案
如果要分别绘制每个点的轮廓,则可以先简单地渲染一个稍大的白点,然后在其上渲染红色点.启用深度测试后,您可能需要在渲染红点时调整多边形的偏移量,以防止它们隐藏在白点之后.
If you want to render outlines for each point separately, then you can simply render a slightly larger white point first and then render the red point over it. With depth-testing enabled, you might have to adjust the polygon offset when rendering the red point to prevent them from getting hidden behind the white ones.
这篇关于如何在OpenGL中绘制点的轮廓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!