Set up Dev C++ for Graphics in C++ Programming

If you’re looking to dive into the world of graphics programming using C++, Dev C++ is a fantastic choice. Dev C++ is a popular integrated development environment (IDE) that allows you to easily write, compile, and execute C++ programs, including those involving graphics. In this step-by-step guide, we will show you how to set up Dev C++ for graphics using the graphics.h library, all while optimizing your knowledge of Dev C++ for graphics, C++ programming, and graphics in C++.

Step 1: Download and Install Dev C++

To start your journey into graphics programming in C++ with Dev C++, you first need to download and install Dev C++. Follow these steps:

  • Visit the official Dev C++ website: https://www.bloodshed.net/devcpp.html.
  • Download the latest stable version of Dev C++ for your operating system (usually Windows).
  • Run the installer and follow the on-screen instructions to complete the installation.

Step 2: Download the graphics.h Library

The graphics.h library is essential for graphics programming in C++. You’ll need to download it separately, as it is not included in the standard C++ library. Here’s how to obtain it:

Step 3: Add Graphics Library Paths

To let Dev C++ know where to find the graphics.h library, you need to add the library’s include and lib directories. Here’s how to do it:

  • Open The location where your Dev C++ is installed, it is usually C:\Program Files\Dev-Cpp
  • Under the folder, find WinBGIm\Include folder and paste graphics.h and winbgim.h in that folder.
  • Then go to WinBGIm\lib and paste libbgi.a there.
  • Then go to gcc folder… and find Include folder inside that and paste graphics.h and winbgim.h there and inside gcc/…/lib paste libbgi.a

Step 4: Link the Graphics Library

To link the graphics library to your C++ programs, follow these steps:

  • Open Dev C++, go to tools-> “Compiler Options” Window.
  • in “Compiler Options” window, go to the “Linker” tab.
  • Under the “Linker Options,” add the following commands:
  • -lbgi
  • -lgdi32
  • -lcomdlg32
  • -luuid
  • -loleaut32
  • -lole32

Step 5: Create a New Graphics Project

Now that Dev C++ is configured for graphics programming, you can start creating graphics projects. Here’s how to create a simple graphics program:

  • Go to “File” and select “New” to create a new source file.
  • Write your graphics code using functions like initwindow, line, circle, etc.
  • Save your project with a .cpp extension.

Test code is given below, or you can also check “Snake game using graphics in C++”

#include<iostream>
#include<graphics.h>
#include<conio.h>
using namespace std;


int main()
{
   int gdriver = DETECT, gmode;
   initgraph(&gdriver, &gmode, "C:\\tc\\bgi");
   //circle(x,y,radius)
   circle(200,200,100);
   getch();
   closegraph();
   return 0;

}

Step 6: Compile and Run Your Graphics Program

To compile and run your graphics program, follow these steps:

  • Click the “Execute” button or press F9 to compile and run your program.
  • If everything is set up correctly, a graphics window should appear with your graphics output.

Congratulations! You’ve successfully set up Dev C++ for graphics programming in C++. You’re now ready to create stunning graphics using C++ programming.

Dev C++ for graphics, graphics in C++, C++ programming

Conclusion

In this step-by-step guide, we’ve explored how to set up Dev C++ for graphics programming using the graphics.h library. By following these instructions, you’ll be well on your way to mastering graphics in C++ and unleashing your creativity through C++ programming. Now, start experimenting, creating, and exploring the world of graphics with Dev C++. If you get any error while setting up dev C++ for graphics, feel free to reach out to us via comments or our whatsapp group Happy coding!

1 thought on “Set up Dev C++ for Graphics in C++ Programming”

Leave a Comment