1

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();
genpfault
  • 51,148
  • 11
  • 85
  • 139
Sileno Brito
  • 449
  • 1
  • 13
  • 31
  • 1
    You should consider using modern OpenGL and Shaders to solve such a task. – t.niese Sep 19 '20 at 13:01
  • If you want to draw it by a [line primitive](https://www.khronos.org/opengl/wiki/Primitive#Line_primitives) (e.g. `GL_LINE_LOOP`), then you have to stitch the round corners by many short lines. For a "modern" solution see [OpenGL Line Width](https://stackoverflow.com/questions/3484260/opengl-line-width/59688394#59688394). – Rabbid76 Sep 19 '20 at 13:33
  • Other solutions are a to draw a texture and use [Blending](https://www.khronos.org/opengl/wiki/Blending) or draw a rectangle and [`discard`](https://www.khronos.org/opengl/wiki/Fragment_Shader#Special_operations) fragments in the fragment shader. – Rabbid76 Sep 19 '20 at 13:39

0 Answers0