BGI (Borland Graphics Interface) is ancient as is turbo c++ IDE but nevertheless they are still used in our schools and colleges. Plus they do not work in windows environment (support for native DOS has been completely removed in windows vista/7).If you try to compile the source code with including “graphics.h” in code::blocks IDE then is show error because “graphics.h” only run in turbo.For code::blocks you have to setup winBGIm library.
There are many alternative to winBGIm ,But BGI is good for beginners because you don’t have to worry about whole new fancy functions,classes etc.
WinBGIm is BGI graphics library ported to computer by by Michael Main at the University of Colorado.
Before i start, i must tell you that this guide is written in accordance with code::blocks IDE.
Lets get started:
There are many alternative to winBGIm ,But BGI is good for beginners because you don’t have to worry about whole new fancy functions,classes etc.
WinBGIm is BGI graphics library ported to computer by by Michael Main at the University of Colorado.
Before i start, i must tell you that this guide is written in accordance with code::blocks IDE.
Lets get started:
- First download WinBGIm from http://winbgim.codecutter.org/
- Extract it.
- Copy graphics.h and winbgim.h files in include folder of your compiler directory
- Copy libbgi.a to lib folder of your compiler directory
- In code::blocks open Settings >> Compiler and debugger >>linker settings
- click Add button in link libraries part and browse and select libbgi.a file
- In right part (ie. other linker options) paste commands -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
- click Ok
Thanks for this Howto. WinBGIm is still the easiest 2D graphics library available.
ReplyDeleteThe alternative to installing it yourself is to use the current version of Code::Blocks EDU-Portable (Codeblocks-EP) from http://codeblocks.codecutter.net
It has templates for WinBGIm projects installed and all the necessary libraries pre-installed.
in Codeblocks-EP just start [File]->[New]->[Project]->[WinBGIm Project]. You'll be able to choose a graphics-only project type, or one with an extra console for standard input/output if you wish.
I get an issue with my code blocks: after i compile the code, i get the window but i doesnt draw normally. i mean, i draws the first line and then, if i resize the window with the mouse i can see the other lines. but with no delay. and i can not figure out what to do :( please help!
DeleteThanks y again. reply here so i will get notified! :D
DeleteCant get the output.... its opening the graphics.h header file
Deletefake bgi
DeleteThanks for information.Now I will install current version of code::blocks
ReplyDeletethank you very much.................
ReplyDeleteHi did this but got an error in building: "fatal error: sstream: No such file or directory||=== Build finished: 1 errors, 0 warnings ===|, will be looking this up on the internet...
ReplyDeleteMe again, now not so anonymous. sstream is there! My Hello world file has the extension c and not cpp. Does this mean that I can only use graphics.h with c++ files?
DeleteWell its not the "Hello world" example of course but this one:
Delete#include
int main()
{
int gd = DETECT, gm;
int x = 320, y = 240, radius;
initgraph(&gd, &gm, "C:\\TC\\BGI");
for ( radius = 25; radius <= 125 ; radius = radius + 20)
circle(x, y, radius);
getch();
closegraph();
return 0;
}
By the way, I don't know why but above the include does not mention graphics.h, and I'm using the mingw32-gcc.exe c compiler
DeleteMy program is terminated unexpectedly after giving a warning saying that :
DeleteDeprecated conversion from string constant to 'char*' [-Wwrite-strings]
What can i do?
I did this but it opened the graphics.h with error in it
ReplyDeleteyou may done some mistake in using graphics.h function so this error. compile this program http://codeincodeblock.blogspot.com/2011/09/analog-clock-source-code-using-c-and.html if error occurs then problem in your setup otherwise its works.
Deletein build messengers here a problem, like "sstream: no such file or directory" , how to slove it.
ReplyDeletecan you show sample code
Deletei too getting this error "sstream: no such file or directory". please help. how to solve it.thanks in advance.
DeleteWrite using a cpp file.
Deletepaste the .h file in this path : C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.7.1\include\c++
ReplyDeletebut me there is an error at line 302 of graphics.h . it says redefinition of int right and when i look in the code there are two int right and no int top at the spécified line is it an error of the new version ?
i have facing the same problem at line 302. if u could manage this problem let me know .
DeleteI tried the following steps after being suggested from
Deletehttp://stackoverflow.com/questions/20313534/how-to-use-graphics-h-in-codeblocks
1. Open the file graphics.h using either of Sublime Text Editor or Notepad++,from the include folder where you have installed Codeblocks.
2. Goto line no 302
3. Delete the line and paste
int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
in that line.
4. Save the file and start Coding.
To learn c graphics programming visit programmingcampus.
ReplyDeletei'm also getting the error "sstream: no such file or directory"
ReplyDeletegraphics.h use in source.cpp
DeleteHi Everybody,
ReplyDeletei've a problem with winbgim but i don't understand where i mistake.
i've installed following the procedure but with any kind of example code the run stop at initgraph(&gdriver, &gmode, ""). i think probably it can't reveal something. i tried also using initwindow(300,200) and always the .exe stop at this line...someone has idea?
thanks!
Paolo
I have no Idea what happen to you. You can download codeblocks-EP version from this link http://codeblocks.codecutter.org/ .In this version template for winBgim graphics is already installed so you don't have to setup winBgim. Just create the winBgim project and run the code.
DeleteThank you Dinesh, but i don't like that versione of CB...i'd prefer to setup the latest version or directly change graphics library (as OpenGL)
ReplyDeleteThanks a lot
Paolo
At me (on Code::Blocks) stop work when i want to int in graph mode
ReplyDeleteIs possible to work with graphics in c with ARM GNU GCC compiler..?? by using code blocks?? and using Winbgim library??
ReplyDeleteThank You Very Much
ReplyDeletei am getting some errors refering to missing references , such as 'settextalign@8'. Here is the source code that I am wanting to work:
ReplyDelete#include
#include "graphics.h"
#include "koolplot.h"
using namespace std;
int main()
{
initwindow(800,600);
int k;
float QT,Q1, Q2, Q3,Q4,Q5,Te,v1[200],v2[200],v3[200];
cout<<"Q1=";cin>>Q1;
cout<<"Q2=";cin>>Q2;
cout<<"Q3=";cin>>Q3;
cout<<"Q4=";cin>>Q4;
cout<<"Q5=";cin>>Q5;
cout<<"Te=";cin>>Te;
for(k=1;k<=200;k++)
{
if(k==1)
{v1[k]=1;
v2[k]=0.5;
v3[k]=1;
}
{if((v1[k]<=0.1) && (Q1=9.9)&&(Q1>Q2))
Q1=Q2;
if ((v1[k]<=0.1) && (Q3=9.9) && (Q3>Q4))
Q3=Q4;
QT=Q2+Q4;
if ((v1[k]<=0.1) && (QT=9.9) && (QT>Q5))
QT=Q5;
}v1[k+1]=v1[k]+Te*(Q1-Q2);
v2[k+1]=v2[k]+Te*(Q3-Q4);
v3[k+1]=v3[k]+Te*(Q2+Q4-Q5);}
for(k=1;k<=200;k++)
{cout<<v1[k]<<" "<<v2[k]<<" "<<v3[k];
plotdata x(0,int(v1));
plotdata y(0,int(v2));
plotdata z(0,int(v3));
plot(x, y);
plot(x,z);
plot(y,z);}}
this line: for(k=1;k<=200;k++) will access beyond the end of the v1, v2, v3 arrays. suggest: for(k=1;k<200;k++) In C, an array offset is in the range 0,,,(numberOfArrayEntries -1) so for a v1[200] the valid offsets are 0...199.
Deleteregarding this kind of line v1[k+1]=v1[k]+Te*(Q1-Q2);, v1[k+1] accesses the v1[] array beyond the end of the array, even if my prior comment is implemented. Accessing beyond the end of the upper bound of an array is undefined behaviour and can lead to a seg fault event.
Deletehey, i got everything up 'n' runnin' but it shows me an error in the graphics.h - it says:redefinition of int right
ReplyDeletethe other is:int right previously declared here
it opens graphic.h file when i built it.
ReplyDeleteThere must be some error in a function you are using.
DeletePost error properly.
for who has issues with graphic.h
ReplyDeletei.e.
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|302|error: redefinition of 'int right'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|302|error: 'int right' previously declared here|
||=== Build finished: 2 errors, 0 warnings ===|
instead of repeat all here follow up http://forums.codeblocks.org/index.php/topic,15147.msg132950.html#msg132950
PS: C:B EP has that file debugged i guess from his mantainer
Ceers,
Harry
getting error…:(
ReplyDeleteplease help…
error: sstream: No such file or directory
Change your file extension to .cpp from .c
DeleteOR Always select C++ while making new project in Code Blocks.
I hope that helps.
What should be the third parameter in initgraph() ? As it cannot be C:\\TC\\BGI for Codeblocks
ReplyDeleteDoesn't matter. Just put C:\\TC\\BGI in there and it will work.
DeleteIf it cannot find drivers in this directory, it looks up in current directory by default.
It still doesn't work for me... what should I install in order to get C:\\TC\\BGI?
Deletesame is with me please tell a solution
DeleteMy problem is different, it says: " cannot find -lole32? " and it comes from ld.exe
ReplyDeleteFile Line Message
ld.exe cannot find -lol32?
same problem of -lole32 :(
Deletei try but is show agin error
ReplyDelete----------------------------------------------------
i try basic program using graphics.h
---------------------------------------------------------
=====================================
#include
void main()
{
}
=======================================================
c:\program files (x86)\codeblocks\mingw\include\graphics.h|30|fatal error: sstream: No such file or directory|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===|
Change your file extension to .cpp if it is .c
DeleteChange it to .cpp
It worked for me.
my problem is when I click on (Build and Run) Button my program generate some errors like as..
ReplyDeletec:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\graphics.h|302|error: redefinition of 'int right'|
but when I click on (Run) Button my program executed correctly...
help me:
ReplyDeleteld.exe cannot find -lbgi|
=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
to solve graphics.h error. U can see there is two times declared 'right'. One of those need to be changed into 'top' and that is it.
ReplyDeletei have some error in DEV c++ . when i wanna complie a program i see these error
ReplyDelete$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)
above error for MAKEFile.win in the 25 line and section compiler write thise massage
[Error] id returned 1 exit statuse
plz help me
Is there a way to use initwindow() to open the window in the *center of the screen*? It is possible to specify the coords of the top-left corner of the window but how to read the size of the whole screen to be able to calculate the parameters?
ReplyDeleteuse the functions: getmaxx() and getmaxy() and divide the results by 2 to get the center of the screen.
DeleteIm using the new code blocks when i try to run my code in the graphic project i get this error : linking stage skipped (build target has no object file to link )
ReplyDeleteNothing to be done ( all items are up to date )
Im using the new code blocks when i try to run my code in the graphic project i get this error : linking stage skipped (build target has no object file to link )
ReplyDeleteNothing to be done ( all items are up to date )
All other programmes are running fine on mu codeblock 13.12 but when I runs a simple graphic programme compiler crashes giving pop up window that says "abc.exe has stopped working window is checking solution".
ReplyDeleteIt also giving a warning message on compilation
warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
How to resolve it.
Advance Thanks
I have the same problem - also using c::b 13.12.
DeleteDid you find a solution?
I do have the same problem. Could anybody help us please?!
ReplyDelete