Creating a Rounded Rectangle in OpenGL

OpenGL is an extremely low level language, and is more or less only capable of drawing triangles. This means that many of the basic shapes that developers are used to having available in a drawing API are not present and must be created from scratch. The below code demonstrates how to draw a rounded rectangle in OpenGL.

static const GLfloat roundRect[] = {
    .92,0,
    .933892,.001215,
    .947362,.004825,
    .96,.010718,
    .971423,.018716,
    .981284,.028577,
    .989282,.04,
    .995175,.052638,
    .998785,.066108,
    1,.08,
    1,.92,
    .998785,.933892,
    .995175,.947362,
    .989282,.96,
    .981284,.971423,
    .971423,.981284,
    .96,.989282,
    .947362,.995175,
    .933892,.998785,
    .92,1,
    .08,1,
    .066108,.998785,
    .052638,.995175,
    .04,.989282,
    .028577,.981284,
    .018716,.971423,
    .010718,.96,
    .004825,.947362,
    .001215,.933892,
    0,.92,
    0,.08,
    .001215,.066108,
    .004825,.052638,
    .010718,.04,
    .018716,.028577,
    .028577,.018716,
    .04,.010718,
    .052638,.004825,
    .066108,.001215,
    .08,0
};

static const GLfloat vbox[] =
{
    0.0f, 0.0f,
    1.0f, 0.0f,
    0.0f, 1.0f,
    1.0f, 1.0f,
};

void render()
{
    setStale(false);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, vbox);
    glPushMatrix();
    glColor4f(0.0f,1.0f,0.0f,1.0f);
    glScalef(.75, .75, 1.0f);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, roundRect);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 40);
    glPopMatrix();
    glDisableClientState(GL_VERTEX_ARRAY);
    setStale(true);
}

Careful observation of the code (especially the line glDrawArrays(GL_TRIANGLE_FAN, 0, 40);) will point out that that technically OpenGL is once again just drawing a collection of 40 triangles in order to create the rounded rectangle shape.