Original Post
Hello, I wanted to share some code that I wrote that draws rectangles with rounded corners. It works pretty well but I though I'd put it up here and see if someone could give me some pointers on making it more efficient.
void draw()
{
float size_x = 100;
float size_y = 100;
float radius = size_x/2.f * sliderObj2.percent;
float factor = sqrt(5.f);
GLfloat topleft[4][3] = {
{0.f, radius, 0.f},
{0.f, radius/factor, 0.f},
{radius/factor, 0.f, 0.f},
{radius, 0.f, 0.f}
};
GLfloat topright[4][3] = {
{size_x - radius, 0.f, 0.f},
{size_x - radius/factor,0.f, 0.f},
{size_x, radius/factor, 0.f},
{size_x, radius, 0.f}
};
GLfloat bottomright[4][3] = {
{size_x, size_y - radius, 0.f},
{size_x, size_y - radius/factor, 0.f},
{size_x - radius/factor, size_y, 0.f},
{size_x - radius, size_y, 0.f},
};
GLfloat bottomleft[4][3] = {
{radius, size_y, 0.f},
{radius/factor, size_y, 0.f},
{0.f, size_y - radius/factor, 0.f},
{0.f, size_y - radius, 0.f}
};
GLfloat filler[8][3] = {
{0.f, radius, 0.f},
{radius, 0.f, 0.f},
{size_x - radius, 0.f, 0.f},
{size_x, radius, 0.f},
{size_x, size_y - radius, 0.f},
{size_x - radius, size_y, 0.f},
{radius, size_y, 0.f},
{0.f, size_y - radius, 0.f}
};
glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,4,& topleft[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glBegin(GL_POLYGON);
for (int i=0;i<=30;i++)
glEvalCoord1f((GLfloat) i/30.0);
glEnd();
glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,4,& topright[0][0]);
glBegin(GL_POLYGON);
for (int i=0;i<=30;i++)
glEvalCoord1f((GLfloat) i/30.0);
glEnd();
glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,4,& bottomright[0][0]);
glBegin(GL_POLYGON);
for (int i=0;i<=30;i++)
glEvalCoord1f((GLfloat) i/30.0);
glEnd();
glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,4,& bottomleft[0][0]);
glBegin(GL_POLYGON);
for (int i=0;i<=30;i++)
glEvalCoord1f((GLfloat) i/30.0);
glEnd();
glBegin(GL_POLYGON);
for (int i=0;i<8;i++)
glVertex3f( filler[0], filler[1], filler[2] );
glEnd();
}