如何在OpenGL中绘制一个点的轮廓?

时间:2018-05-07 08:14:16

标签: ios objective-c opengl-es render point

现在可以使用以下代码绘制点:

    // 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);

点用红色渲染,我想在点之外添加白色轮廓。我怎样才能勾勒出这一点?

更好地展示的问题

按照@BDL的说明在红点下添加更大的点作为轮廓,它们看起来很好。

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;

但是当一个点与另一个点重叠时,它的轮廓被红点覆盖,因为轮廓点在所有红点之前呈现。

enter image description here

我认为正确的解决方案是逐个渲染一个轮廓点和红点。怎么做?

1 个答案:

答案 0 :(得分:1)

如果您想分别渲染每个点的轮廓,那么您可以先简单地渲染一个稍大的白点,然后在其上渲染红点。启用深度测试后,您可能必须在渲染红点时调整多边形偏移,以防止它们隐藏在白色背后。