Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Coder
    Join Date
    Sep 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can i draw in c++

    How can i draw in c++ using many colors not only 16 color???

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Draw what?Which OS?GUI or terminal application?

  • #3
    New Coder
    Join Date
    Sep 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the operating system is dos & the language is c++

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    With Unix like OS' you can use the (N)curses library,I am not sure if such a thing exisits for DOS.

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    There are C/C++ API's for the GTK toolkit and for imagemagick

    though whether they let you use more than 16 colours I dont know , though the GIMP (PS for Linux) is GTK based so I can only assume yes.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    New Coder
    Join Date
    Sep 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What is the N courses library & where can i find it???

  • #7
    New Coder
    Join Date
    Sep 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    firepages can u explain me more pls

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by aimenkawaz
    What is the N courses library & where can i find it???
    You need to learn how to read and how to ask questions,it's called Ncurses and as far as know only available for Unices,so since you are using DOS I dont know how you can draw colors.You can always make a GUI app.

  • #9
    New Coder
    Join Date
    Sep 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How can i make a GUI application???

  • #10
    New Coder
    Join Date
    Oct 2002
    Location
    middle of nowhere
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're gonna need to learn some Windows API. You can set up a DOS like shell in a win32 app with
    #define WIN32_LEAN_AND_MEAN
    and then link with the libraries for whatever you decide to draw with (DirectX, OpenGL, etc) but first of all you need to be able to write a windows shell to handle the windows messages.

    Good Luck!

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is some code that i used about 7 years ago, on a TC compiler (I have no idea what version it was)
    So it is possble that it won't work. it isn't standard C so I doubt it will work with other compilers then TC.
    But if I were you, I wouldn't waste my time learning graphics for DOS. Go with Directx (or OpenGL). DOS is dead (my opinion) Programming for the console or DOS is only good for learning. People these days want a nice GUI to work with. And if you want to make a presentation or a game, use a recent graphics library

    If you're interested, here's the code. But like I said, it isn't going to work I think. it should draw a circle.
    BTW, straal means radious.
    Code:
    #include <graphics.h> //Compiler dependant code
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h> //Compiler dependant code
    
    
    int main(void)
    {
    /* request auto detection */
       int gdriver = DETECT, gmode, errorcode;
       int x,y,straal;
    
       /* initialize graphics and local variables */
       initgraph(&gdriver, &gmode, "");
    
       /* read result of initialization */
       errorcode = graphresult();
       /* an error occurred */
       if (errorcode != grOk)
       {
          printf("Graphics error: %s\n",
                 grapherrormsg(errorcode));
          printf("Press any key to halt:");
          getch();
          exit(1);
       }
    
    
    clrscr(); //Also Compiler dependant 
    printf("\nX-coord : ");
    scanf("%i",&x);
    printf("Y-coord : ");
    scanf("%i",&y);
    printf("straal : ");
    scanf("%i",&straal);
    
    circle(x,y,straal);
    }

  • #12
    New Coder
    Join Date
    Sep 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maes, i know that i want to draw with many colors....

  • #13
    New Coder
    Join Date
    Oct 2002
    Location
    middle of nowhere
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, like I said you need to learn OpenGL or DirectX. Don't waste your time with anything else. In fact, if you dont know either of these, learn OpenGL first. It's platform-independant; you can use it on a Windows, Linux, or Mac box with only small modifications(to the GUI shell).

  • #14
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by aimenkawaz
    maes, i know that i want to draw with many colors....
    Then you have to set your pallete collors. If I remember correctly, you can only have a few ( I think it is 16) colors on your screen at the same time. but you can choose any of the rgb values.
    Code:
    #include <graphics.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    
    int main(void)
    {
       /* select a driver and mode that supports the use */
       /* of the setrgbpalette function.                 */
       int gdriver = VGA, gmode = VGAHI, errorcode;
       struct palettetype pal;
       int i, ht, y, xmax;
    
       /* initialize graphics and local variables */
       initgraph(&gdriver, &gmode, "");
    
       /* read result of initialization */
       errorcode = graphresult();
       if (errorcode != grOk)  /* an error occurred */
       {
          printf("Graphics error: %s\n", grapherrormsg(errorcode));
          printf("Press any key to halt:");
          getch();
          exit(1); /* terminate with an error code */
       }
    
       /* grab a copy of the palette */
       getpalette(&pal);
    
       /* create gray scale */
       for (i=0; i<pal.size; i++)
          setrgbpalette(pal.colors[i], i*4, i*4, i*4);
    
       /* display the gray scale */
       ht = getmaxy() / 16;
       xmax = getmaxx();
       y = 0;
       for (i=0; i<pal.size; i++)
       {
          setfillstyle(SOLID_FILL, i);
          bar(0, y, xmax, y+ht);
          y += ht;
       }
    
       /* clean up */
       getch();
       closegraph();
       return 0;
    }
    if you mess around with the "i*4, i*4, i*4" you can get different collors. for example: "i*1, i*1, i*3" will give you different shades of blue

    I hope this is what you're looking for

  • #15
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is an example that came with the TC compiler. Perhaps you've seen, if not, here it is
    I learned alot from it.


    edit:
    Notepad messed up the code.
    try here
    Attached Files Attached Files
    Last edited by maes; 10-14-2002 at 04:20 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •