# Drawing polygons?

• 11-03-2001
dark_fusion
Drawing polygons?
How do I draw polygons, like a triangle in dos? Can anyone help?
• 11-03-2001
Hillbillie
• 11-03-2001
dark_fusion
a libary I think, I'm trying to do it in turbo C++ using graphics.h but I cant get it right
• 11-04-2001
Hillbillie
Yeah, you're using the BGI graphics library (most likely).

Code:

```#include <graphics.h> #include <conio.h> int main() {   int gdriver = DETECT, gmode;   int triangle[8];   // Let's define a triangle with vertices at A(1, 1), B(30, 100), and C(100, 150).   triangle[0] = 1; // x of vertex A.   triangle[1] = 1; // y of vertex A.   triangle[2] = 30; // x of vertex B.   triangle[3] = 100; // y of vertex B.   triangle[4] = 100; // x of vertex C.   triangle[5] = 150; // y of vertex C.   triangle[6] = triangle[0]; // Close triangle.   triangle[7] = triangle[1];   initgraph(&gdriver, &gmode, ""); // Init the graphics mode.   setcolor(15); // Set color to white.   drawpoly(4, triangle);  // Draw the three sided figure!   getch();   closegraph(); // Exit graphics mode.   return 0; }```
• 11-04-2001
dark_fusion
Cool Thanks!:)
• 11-04-2001
Hmmm. when i compiled that with Borland 3.1 C++ it compiled and linked with out a problem but when i executed it, it said this in the DOS shell "BGI Error: Graphics not initialized (use 'initgraph')", Does anyone have any suggestions why i received that error even thought it linked fine?
• 11-04-2001
dark_fusion
U have to use a dos based compiler like Turbo C++ that uses graphics.h which is meant for BGI graphics
• 11-04-2001
Hillbillie
>Hmmm. when i compiled that with Borland 3.1 C++ it compiled and linked with out a problem but when i executed it, it said this in the DOS shell "BGI Error: Graphics not initialized (use 'initgraph')", Does anyone have any suggestions why i received that error even thought it linked fine?<

Go to your Borland C++ directory. Look for a subdirectory called BGI. In there, should be a file called egavga.bgi. Copy it to the location of the program. Now try running it.

>U have to use a dos based compiler like Turbo C++ that uses graphics.h which is meant for BGI graphics<

If I'm not mistaken, Borland C++ 3.1 is for DOS.
• 11-04-2001
Hmm.... Actually i do not have that file, could somebody please e-mail that file to fatpotatohead@hotmail.com
• 11-04-2001
Hillbillie
Your wish is my command :)
• 07-16-2002
dune911
this code works fine :)
i tried it with tc++ 2.01
do you think it also works with msvc++ 6 ?
(i can't try it, because i don't have it yet...)
• 07-18-2002
Unlimited4s
I don't have graphics.h...
can someone please paste the source of it here?