How to draw a rectangle with rounded corners in OpenGL?

5.8k Views Asked by At

I'm trying to draw a rectangle using OpenGL with rounded corners (like when using border-radius in css), something like the example below, using OpenGL.

enter image description here

The initilization

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInit(&argc, argv);
    glutCreateWindow("Test1");
 // The callback draw function here
    glClearColor(0, 0, 0, 0);
    glutMainLoop();

The callback draw function

glClear(GL_COLOR_BUFFER_BIT);
    int x = 0 ;
    int y = 0;
    glBegin(GL_POLYGON);
    glVertex2d(x, y);
    glVertex2d(x, y + 50);
    glVertex2d(x + 100, y + 50);
    glVertex2d(x + 100, y);
    glVertex2d(x, y);
    glEnd();
 glFlush();
0

There are 0 best solutions below