Lately I have been searching this post on the net about graphics.h in dev c++ and found few resources about it . So I decided to write how to use graphics.h in dev-c++. I am expecting that you have already installed bloodshed dev-cpp on your machine. Graphics.h is a header file found in borlan c but because of its late development devcpp is now the mostly used IDE and compiler in programming c++.
Below are the steps on how to get graphics.h running on your machine,
- download graphics.h and save it to the include folder where you installed dev-cpp (C:\Dev-Cpp\include)
- Download libbgi.a and save it in the lib folder where you installed dev-cpp (C:\Dev-Cpp\lib)
- So when you have to create a program that needs the use of graphics.h you must instruct the linker to link in certain libraries by going to projects > project options > parameters tab > linker column copy the lines below and paste it on that column.
|
1 2 3 4 5 6 |
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32 |
By then you should be able to use graphics.h. As a sample I created this bubble sort algorithm as an example on how to use graphics.h in c++.
#define PIXEL_COUNT 1000
#define DELAY_TIME 1 /* in milliseconds */
#define CLIP_ON 1
//using namespace std;
int main () {
int temp, x, toSort[300], loop, isSwapped=1;
/* request autodetection */
int gdriver = DETECT, gmode, errorcode;
/* 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 */
}
/* Generate the numbers */
for(x=0; x<300; x++) {
toSort[x] = rand() % 300 + 1;
}
for(loop=0; (loop <= 300)&& isSwapped == 1; loop++) {
isSwapped = 0;
for(x=0; x<300; x++) { if(toSort[x] > toSort[x+1]) {
//swapping of data
temp = toSort[x];
toSort[x] = toSort[x+1];
toSort[x+1] = temp;
isSwapped = 1;
}
std::cout << loop << “=> “<< x << “,” << toSort[x] << ” “;
putpixel(x, toSort[x], 16776960);
delay(DELAY_TIME);
}
std::cout << “\n\n”;
if(isSwapped == 1) {
cleardevice();
}
//loop++;
}
//cout << endl << “\n\n\n”;
std::cout << “Loop Count: ” << loop << “\n\n\n”;
system(“pause”);
return 0;
}
The program will have scattered points on the screen and will form a line as the loop iterates and at the end it will display how many loops are needed to sort the randomly generated numbers.
If you have problems using the functions you can refer to this link. I hope this helps in solving your problem about dev c++ graphics.h with the bubble sort algorithm.


Your Codes Doesnt work
Did you follow the steps carefully? Most problem occur because the forgot to add the linker.
you’re THE BEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Nope doesnt work for me either .. It blows up a milion of errors..
I am using the latest version of devc++. make sure also that you have the linkers….
you need change in program all “\n\n” to “\n\n” and its works
I mean if you copy paste from this site you will see that all “” are wrong for compiler
thank you very much friend…I have been trying hard for this help post….Thank you once again and best wishes for future helps.
hi jjabrams, you need change in program all “\n\n” to “\n\n” doesn’t it changes anything?i mean isn’t same
I did not get what you mean. “\n\n” and “\n\n” are the same as what you have stated on your question. Which line are you referring to?
actually i’m using dev c++ 5.0.0.4 version….so the above procedure will also be applicable on my version of dev c++?????????????…and i want to do all my graphics.h programs in c language,,,but not in c++ lang.and please tell me how we can create a c project and do the graphics.h programs in it….if possible please help me step by step screenshots of procedure….plzzzzzzzzzzzz,,,,help me,,,i jus want to my graphics progrms in dev c++,,,help me out….
If you are using dev C, you should be doing the steps for you to have graphics support.
awesome…. The above program works if the above steps are followed. But my concern is the programs other than the above program given that uses graphics.h header file doesn’t work. So,please help me out to run any program that uses graphics.h header file in dev c++ software. Thank you
Thanks for helping me to execute the above program in dev c++ software. But my concern is the programs that uses graphics.h header file other than the above one is not executing. So, kindly help me out to execute any program that uses graphics.h file in dev c++
Every time you use graphics.h you need to add it in the linker column. You need to manually add it in every project.
It doesnt work for me either , i copied the entire code and pasted it in a new Wgdim project , also copied the linkers.
Its giving me a ton of errors , im using 5.0.0.4
i copied the entire code and pasted it in a new Wgdim project , also copied the linkers.
Its giving me a ton of errors , im using 5.0.0.4
download the file and put in the folder where you store the headers.