PDA

View Full Version : Drawing polygons?



dark_fusion
11-03-2001, 10:22 PM
How do I draw polygons, like a triangle in dos? Can anyone help?

Hillbillie
11-03-2001, 10:38 PM
Are you using a library or your own homemade code?

dark_fusion
11-03-2001, 11:14 PM
a libary I think, I'm trying to do it in turbo C++ using graphics.h but I cant get it right

Hillbillie
11-04-2001, 12:17 AM
Yeah, you're using the BGI graphics library (most likely).



#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;
}

dark_fusion
11-04-2001, 01:04 AM
Cool Thanks!:)

fatpotatohead
11-04-2001, 02:12 AM
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?

dark_fusion
11-04-2001, 05:47 AM
U have to use a dos based compiler like Turbo C++ that uses graphics.h which is meant for BGI graphics

Hillbillie
11-04-2001, 01:11 PM
>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.

fatpotatohead
11-04-2001, 09:49 PM
Hmm.... Actually i do not have that file, could somebody please e-mail that file to fatpotatohead@hotmail.com

Hillbillie
11-04-2001, 11:37 PM
Your wish is my command :)

dune911
07-16-2002, 10:49 AM
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...)

Unlimited4s
07-18-2002, 05:59 AM
I don't have graphics.h...
can someone please paste the source of it here?