What are the ways to draw simple two-dimensional shapes (circle, square, etc.) in C ++?

Closed due to the fact that the question is too common for participants Vladimir Martyanov , aleksandr barakin , zRrr , Grundy , D-side 14 Apr '16 at 9:20 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Details are needed: on which device to draw, in which OS, and so on. Otherwise, an essay on 100 pages can be written ... - Vladimir Martyanov
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

3 answers 3

There are no graphic tools in the standard language.

Depending on the operating system, library used, etc. methods can be very different, but they all go beyond the standard C ++.

  • Well, in the same builder you can like that - ivanvae
  • one
    @ivanvae You can use almost any compiler. But - NOT by means of C ++, but by means of the operating system. There are more or less portable FLTK type GUI libraries, but this is not a standard C ++ tool. - Harry
  • And what is the easiest library for windows? - ivanvae
  • no matter how crazy it sounds but I liked the built-in borland c, but for it you need to put a video driver sometimes. - pavel
  • @ivanvae Stroustrup in his book "Programming. Principles and practice using C ++" recommends FLTK, it is described there, why I remembered it ... - Harry

Take the SDL2 . Do not look that there are screenshots of toys, the library itself for basic purposes is very simple (display a window, draw a line, a rectangle, and so on). Here is full of references to books, books, manuals.

Here are a few links to get comfortable:

There are no standard language tools for this. Exactly like (yet?) Standard tools for working with a network or file system (will be with C ++ 17).

By the way, the samples for the sake of ported a simple toy for KolibriOS to the SDL: https://github.com/h4tr3d/laser-tank . The main work with SDL is concentrated here .

Another option that I once used was CImg . Plus the library in its phenomenal ease of installation: it consists of a single header file. Works on a sufficient number of platforms and compilers, providing a unified interface to system functions. You can start dating with this simple tutorial. A complete example of drawing a line, a circle and a rectangle will be:

#include "CImg.h" using namespace cimg_library; int main() { CImg<unsigned char> visu(500,400,1,3,0); const unsigned char red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 }; CImgDisplay draw_disp(visu, "Drawing sample"); while (!draw_disp.is_closed()) { visu.draw_line(40, 40, 80, 70, red); visu.draw_circle(150, 150, 50, green); visu.draw_rectangle(210, 120, 300, 240, blue); visu.display(draw_disp); draw_disp.wait(); } return 0; } 

On Linux compile like this:

 g++ -std=c++11 main.cpp -lX11 -pthread 

In general, here's another, you can say official, list of libraries, choose:

    You can use other graphic libraries for this task. For example, SDL2 or SFML. These graphic libraries are quite capable of performing your task. There is also the option of using glut, or another other library compatible with OpenGL.