1

What libraries does Windows provide to draw lines? I am only interested in 2D libraries, not OpenGL or DirectX. I am working in C++.

Nathanael
  • 1,782
  • 17
  • 25
mishkapp
  • 79
  • 1
  • 6

3 Answers3

9
cout << ".------------------------------------------------------------." << endl;

cout << ".\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         ." << endl;

EDIT: Forgot the dots.

EDIT 2: Diagonal:

for( int i=0; i<10; i++ )
{
    for( int j=0; j<10; j++ )
    {       
        if( i == j )
        {
            for( int k=0; k<i; k++ )
            {
                cout << " ";
            }

            if( i == 0 || i == 9 )
            {
                cout << ".\n";
            }
            else
            {
                cout << "\\\n";
            }
        }
    }       
}
Josh
  • 12,448
  • 10
  • 74
  • 118
3

Depends on your platform.

In Windows you could use GDI or GDI+.

For Mac OS I'm sure both Carbon and Cocoa provide this feature - though I confess to having little knowledge of either API.

Qt provides cross-platform drawing libraries that will work on any of Linux, Windows or Mac.

EDIT:

Direct2D is another C++ option for Windows. It's fully hardware accelerated too which is cool. As for drawing on a fullscreen window, it's no different than drawing in a regular window. You'll just need some extra code to maximize the window and set it to fullscreen mode.

Nathanael
  • 1,782
  • 17
  • 25
0

It depends. What system are you on? How would you like to draw it? In 3D or 2D? Do you want fullscreen?

Honestly, OpenGL is pretty easy to use with a library like GLUT. After you set it up, all it takes is

glBegin(GL_LINES);
    //Vertex pair
    glVertex2f(...);
    glVertex2f(...);
glEnd();

(Purists will yell at me for using a form of OpenGL that isn't around in the 3.0 standard, but I assume this isn't a major project needing forward-compatibility for a long time).

Two other quick libraries that come to mind:

  1. SDL Sounds like your library: it has quick setup, lots of tutorials, and it's plain C. Unfortunately, you'll have to use another library (i.e. SDL_Draw) to actually draw the line.
  2. Allegro I used this library a few years ago, but not since then. My recollection is that it's a lot like SDL in form and function. It works well on Windows, but is not as easy as SDL on OS X. Allegro does(!) have a built in line drawing function called line() (gotta love that brevity).
semisight
  • 914
  • 1
  • 8
  • 15