How to draw outline of a point in OpenGL?

2019-08-03 11:01发布

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?

Question for better displaying

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.

enter image description here

I think the right solution is to render one outline point and red point one by one. How to do that?

1条回答
\"骚年 ilove
2楼-- · 2019-08-03 11:25

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.

查看更多
登录 后发表回答