What libraries does Windows provide to draw lines? I am only interested in 2D libraries, not OpenGL or DirectX. I am working in C++.
-
2On what platform? C++ does not define a function to draw lines. – Eric J. Oct 26 '11 at 05:59
-
Visual C++ 2010, or what you mean? – mishkapp Oct 26 '11 at 06:03
-
on windows, mac, a web page, (etc.)? we need more info to help you. also, if this is homework then you need to add the homework tag. – Muad'Dib Oct 26 '11 at 06:19
-
On Windows. I want it to run in fullscreen/frame using 2D graphics only. – mishkapp Oct 26 '11 at 06:29
3 Answers
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";
}
}
}
}

- 12,448
- 10
- 74
- 118
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.

- 1,782
- 17
- 25
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:
- 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.
- 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).

- 914
- 1
- 8
- 15