I started playing around with OpenGL and GLUT. I would like to draw some points, but the problem is that they turn out to be squares, and I would like them to be round dots (filled circles).
This is what I do:
void onInitialization( )
{
glEnable( GL_POINT_SMOOTH );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glPointSize( 6.0 );
}
void onDisplay()
{
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glBegin( GL_POINTS );
glColor3f( 0.95f, 0.207, 0.031f );
for ( int i = 0; i < g_numPoints; ++i )
{
glVertex2f( g_points[i].X, g_points[i].Y );
}
glEnd();
glFinish();
glutSwapBuffers();
}
This is the result:

The points show up where expected, only their shape is wrong.
Unlike what was said previously, this is possible with the fixed-function pipeline, even with the
GL_POINTSprimitive type, as long as you have support for OpenGL 1.4 or theGL_ARB_point_spriteextension. Consult this document, or the OpenGL core specification of your choice : http://www.opengl.org/registry/specs/ARB/point_sprite.txtGL_ARB_point_spriteconverts points into “quads”, i.e a polygon with the form of a plane. The exact primitive type it gets converted to is not defined by the specification, though it is not important. What is important is thatGL_COORD_REPLACEauto-generates texture coordinates for the surface when enabled, so you can texture-map them with a sphere-shaped RGBA-texture.EDIT: It seems like you (the poster) is right. Anti-aliased points get rounded with respect to their radius. (I’ve used OpenGL since 2003, and I didn’t know this. [/shame])
So enabling
GL_POINT_SMOOTHwhile you have amultisample-ablevisual/pixelformat, you get rounded points. Still, multisampling can be slow, so I’d implement both. Textured quads are cheap.To request a visual with multisampling with XLib, use these two attributes in the list to glXChooseFBConfig():
GLX_SAMPLE_BUFFERS– its value should beTrue. This is an on/off toggle.GLX_SAMPLES– the number of samples.To request a pixelformat with Win32, use these two attributes in the list to ChoosePixelFormat() or wglChoosePixelFormatARB():
WGL_SAMPLE_BUFFERS_ARBSame as above, a toggle.WGL_SAMPLES_ARBSame as above, the number of samples.It seem that you can OR in the flag
GLUT_MULTISAMPLEtoglutInitDisplayModeto get multisampling in GLUT, but you can’t request the number of sample buffers.Here is how alpha-blended quads could be implemented using your test case.
Image of rounded points using per-fragment alpha blending + textures:

(source: mechcore.net)
Image of rounded points by using
GL_POINT_SMOOTHand multisampling:(source: mechcore.net)
A little sample I made which shows both techniques. Requires libSDL and libGLEW to compile: