Drawing polygons?

This is a discussion on Drawing polygons? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; How do I draw polygons, like a triangle in dos? Can anyone help?...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    Question Drawing polygons?

    How do I draw polygons, like a triangle in dos? Can anyone help?

  2. #2
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    Are you using a library or your own homemade code?

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    8
    a libary I think, I'm trying to do it in turbo C++ using graphics.h but I cant get it right

  4. #4
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    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;
    }

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    8
    Cool Thanks!

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    35
    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?

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    8
    U have to use a dos based compiler like Turbo C++ that uses graphics.h which is meant for BGI graphics

  8. #8
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    >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.

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    35
    Hmm.... Actually i do not have that file, could somebody please e-mail that file to fatpotatohead@hotmail.com

  10. #10
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    Your wish is my command

  11. #11
    Registered User dune911's Avatar
    Join Date
    Sep 2001
    Posts
    140
    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...)

  12. #12
    Registered User
    Join Date
    Jul 2002
    Posts
    7
    I don't have graphics.h...
    can someone please paste the source of it here?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating Scenes with many 1,000s of Polygons
    By thetinman in forum Game Programming
    Replies: 5
    Last Post: 12-25-2008, 09:14 PM
  2. Slow drawing code
    By tjpanda in forum Windows Programming
    Replies: 5
    Last Post: 05-09-2008, 05:09 PM
  3. Line Drawing Algorithm
    By Axpen in forum Game Programming
    Replies: 15
    Last Post: 08-01-2005, 06:30 PM
  4. How to do double buffing with win32 drawing?
    By Josh Kasten in forum Windows Programming
    Replies: 2
    Last Post: 03-26-2004, 11:02 PM
  5. drawing minimaps and radar screens.
    By Eber Kain in forum Game Programming
    Replies: 4
    Last Post: 03-08-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21