Helpful Information
 
 
Category: Computer Programming
How can i draw in c++

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

Draw what?Which OS?GUI or terminal application?

the operating system is dos & the language is c++

With Unix like OS' you can use the (N)curses library,I am not sure if such a thing exisits for DOS.

There are C/C++ API's for the GTK toolkit (http://www.gtk.org) and for imagemagick (http://www.imagemagick.org)

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.

What is the N courses library & where can i find it???

firepages can u explain me more pls

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.

How can i make a GUI application???

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!

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.


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

maes, i know that i want to draw with many colors....

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).

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.


#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

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 (http://users.skynet.be/wiseguy/code/files/BGIDEMO.C)

I know all of these programs:D
but i still don't know how to draw with many colors :(

sorry then , that's all I know from DOS graphics :o

But maybe they can help you here: www.cprogramming.com

Thank u very much maes










privacy (GDPR)