Getting smooth, big points in OpenGL

53,639

Mads' answer provides everything you need if you go for the fixed function pipeline. However, if you have a system that does not provide the ARB_point_sprite extension or with a broken implementation (some ATI drivers), you can solve this part also with geometry shaders. The ARB_geometry_shader4 extension allows you to convert a point primitive to two triangles, which can be used as the quad created by the ARB_point_sprite extension. On OpenGL 3.2, geometry shaders are already supported in core, no extension needed. The OpenGL wiki has two examples.

Share:
53,639
Tamás Szelei
Author by

Tamás Szelei

http://szelei.me

Updated on April 28, 2020

Comments

  • Tamás Szelei
    Tamás Szelei about 4 years

    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: Result of the above code

    The points show up where expected, only their shape is wrong.