According to Wikipedia,
Code::Blocks is a free, open-source cross-platform IDE that supports multiple compilers including GCC, Clang and Visual C++. It is developed in C++ using wxWidgets as the GUI toolkit. Using a plugin architecture, its capabilities and features are defined by the provided plugins.
Graphics application cannot be executed by default on CodeBlocks. In this tutorial, there is a complete step-wise description of executing a graphics program in CodeBlocks. Graphics using c language involves understanding a library containing functions to draw shapes, changing colors or manipulating with images. There are many available such as OpenGL, SDL and many others but for a beginner Turbo c compiler contains a header file graphics.h.
The display mode of standard output device is classified as text mode and graphics mode. Text Mode is a computer display mode in which content is internally represented on a computer screen in terms of characters rather than individual pixels. In this mode, display screen is normally set up to display 25 lines of text with 80 characters per line. We can’t change the shape and size of the characters displayed on the screen. This mode is also known as character mode. The character-based programs runs in character mode.
Graphics Mode is the computer-display mode that generates image using pixels, also known as graphics mode. In this mode, tiny dots(pixels), are used to draw image. The graphics mode provides the ability to manipulate the individual pixels. C has various library functions which are defined within header file “graphics.h”.
Download the WinBGIm_GCC47
Step #1. Copy the files graphics.h and winbgim.h in “C:\Program Files (x86)\CodeBlocks\MinGW\include” folder.
Step # 2 Copy the “libbgi.a” file in “C:\Program Files (x86)\CodeBlocks\MinGW\lib” folder.
Step #3 Now Launch the CodeBlocks, go to “Settings->Compiler->Linker Settings->Link Libraries” section and add the path to “libbgi.a”. You can use the icon on right to browse to the local directories.
Step #4 In “Other Linker Options” section, paste the following, “-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32” as it is.
Do not need to understand, for the time being.
Step #4 Finally, Click on “OK”.
Step #5 Write a graphics source code (sample)
/// main implementation
/// necessary variables
int gd = DETECT, gm;int x, y,x1, y1, x2, y2;
/// initialize the graphics mode
initgraph(&gd, &gm, "C:\\TC\\BIN");
/// to get the reference point at the center of the view port.
x = getmaxx()/2;
y = getmaxy()/2;
/// assume the width to be 200, and height to be 100
x2 = x + 100;
y2 = y+50;
x1 = x-100;
y1 = y-50;/// use the rectangle function to draw the rectangle
rectangle(x1, y1, x2, y2);
Now, save the file, “rectangle.cpp”.
Make sure the file extension is “.cpp” not “.c”.
Step #6. Now compile and run the program.
Hopefully, if every thing is fine, the program should execute.
Happy Coding! Share this post so that anyone from your contacts can benefit.