Previously, I’ve discussed installation & configuration of Winbgim with Dev-C++ here. As devpaks for Winbgim are released, things are now much better than before. This article is designed to help you create graphics programs using WINBGIm and DEV-C++.
Getting Started
Before we start, click here to download the WINBGIm devpak. If possible try and download the latest release from devpaks.org. After downloading the devpak, all you have to do is double click on it and let it install itself in package manager of Dev-C++. Once it installs successfully you can see the devpak inside the package manager. See image below.
Devpak allows you to use the pre-made code template for the WINBGIm graphics. To use this pre-made template, follow these steps.
1. From File >New > Project > WINBGIm tab.
2. Choose any template file from these three: WINBGIm (Console), WINBGIm (Without console),and WINBGIm.
3. Choosing WINBGIm will open .cpp source file where you find ready to execute code for the WINBGIm graphics. You can modify the source code as per your choice or let it stay with your own source code. Try adding more graphics functions like circle, rectangle or ellipse to see how things work. Copy the source code below and paste it in your source file.
#include"stdio"
#include "iostream"
#include "graphics"
using namespace std;
int main( )
{
initwindow( 640 , 480 , "WinBGIm Demo" );
circle(100,200,30);
line (60, 60, 100, 200);
ellipse (200, 300, 90, 150, 200,300);while( !kbhit() );
closegraph( );
return( 0 );
}
After copying the code to the source file. Now you are ready to execute it. Press Compile & Run or (F9) to build & execute the code. You’ll see something like the image shown below.
If you see console window along with your graphics program then to avoid this you’ve to select the WINBGIm with no console during project template selection at start in WINBGIm tab.
Now, I’m going to explain the code for you, so you can understand what the code is doing.
initwindow( 640 , 480 , "WINBGIm Demo" );
This created window of size 640×480 size with window caption as WinBGIm demo. You can change the caption to any text of your choice.
circle (100,200,30);
This function will create the circle at co-ordinates x=100,y=200,with radius of about 30.
Line (60, 60, 100, 200);
Ellipse (200, 300, 90, 150, 200,300);
Similar to the circle function, values passed to the above functions (line & ellipse) will draw the respective geometric shape.
while( !kbhit() );
closegraph( );
return( 0 );
This will close the window when user presses some key on the keyboard.
You have just finished creating your own graphics with WINBGIm without using Turbo C++. I’ve given you enough information to experiment, so start cutting some code. You can experiment with more graphical functions mentioned in this page.
I hope the above information helped. If you have any questions or comments, please don’t hesitate to post them.