The Wayback Machine - https://web.archive.org/web/20240604040810/https://www.geeksforgeeks.org/basic-graphic-programming-in-c/
Open In App

Basic Graphic Programming in C++

Last Updated : 06 Jan, 2017
Improve
Improve
Like Article
Like
Save
Share
Report

Introduction
So far we have been using C language for simple console output only.  Most of us are unaware that using C++, low level graphics program can also be made. This means we can incorporate shapes,colors and designer fonts in our program. This article deals with the steps to enable the DevC++ compiler to generate graphics .
Configuring DevC++

  • Step 1: Download the DevC++ version 5.11 from here.
  • Step 2: Download the Graphics header files, and etc stuff needed from the given dropbox link.
  • Step 3: Extract the contents of the rar file.
  • Step 4: Go to the location where DevC++ is installed. For me its D drive. Go inside the MinGW64 folder. Copy the graphics.h and winbgim.h in the include folder and D:\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include folder.
  • Step 5:Copy the libbgi.a file into lib folder and in D:\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib folder.
  • Step 6: Copy the ConsoleAppGraphics.template, ConsoleApp_cpp_graph.txt files and paste them inside the template folder of the devc++ installer location.

Now we are done with configuring of the DevC++ to support graphics programming. We shall write our very first graphics program now.
Running the first graphics program

  1. Open DevC++. Click file ->New ->Project.
  2. Make sure you get the Console Graphics option. However, we are not going to click on it.
  3. Choose Empty Project option and Give a project name and make sure the selected language is C++.
  4. Copy the following code to the editor window.
    #include<graphics.h>
    #include <conio.h>
    int main()
    {
        int gd = DETECT, gm;
        initgraph(&gd,&gm, "C:\\tc\\bgi");
        circle(300,300,50);
        closegraph();
        getch();
    }
    
    
  5. Go to “Project” menu and choose “Project Options” (or just press ALT+P).
  6. Go to the “Parameters” tab In the “Linker” field, enter the following text:
    -lbgi
    -lgdi32
    -lcomdlg32
    -luuid
    -loleaut32
    -lole32
    Basic Graphic Programming in C++
  7. Click OK and Compile and run the project and you’ll get this output:

Basic Graphic Programming in C++ 1

Program Explanation

  • The initgraph function- ?Initializes the graphics system.
  • In C Program execution starts with main() similarly Graphics Environment Starts with this function.
  • initgraph() initializes the graphics system by loading a graphics driver from disk (or validating a registered driver) then putting the system into graphics mode


Previous Article
Next Article

Similar Reads

Generating RGBA portable graphic images through C++
PNG images are capable of supporting multiple image properties such as multiple colors, degree of transparency, Gamma correction, Lossless compression, etc. PNG images are widely used and preferred for numerous types of images. For working with PNG files we will be using the PNGwriter platform-independent, wrapper open-source C++ library for libpng
3 min read
Graphic Accelerator Card
Graphic accelerator cards usually come to us as add-on cards that plug into a PCI bus or AGP slot, or the circuitry is integrated into the motherboard and attached to one of these buses. A typical 2D/3D graphic accelerator card has the following major components as follows. Graphic accelerator chipset or co-processor Expansion Bus interface Video m
3 min read
List of basic AutoCAD Terminology
AutoCAD is Computer-Aided Design, which is used to design variety of drawings. It provides various kinds of tools with the help of which different kinds of drawings can be made and viewed easily. Basic AutoCAD Terminology : As, we know meaning of terminology is specific term used in any field. Here we are discussing about AutoCAD, so we are talking
4 min read
Build a basic Text Editor using Tkinter in Python
Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but this is the only framework that’s built into the Python standard library. It has several strengths; it’s cross-platform, so the same code works on Windows, macOS, and Linux. It is lightweight and relatively painless to use compared to other frameworks
4 min read
Basic Attributes of an Image
Image : Most of the multimedia applications have to handle the various types of images. Digital image is the integral part of almost all multimedia applications. The digital image is sampled and mapped as a grid of dots or pictures elements. Each pixel is assigned a tonal value(black, white, shades of gray or color) which is represented by binary c
4 min read
Build a Basic Form GUI using CustomTkinter module in Python
In this article, we are going to learn how to build a simple form GUI using CustomTkinter in Python. CustomTkinter: It is an extension of the Tkinter module in python. It provides additional UI elements compared to Tkinter and they can be customized in various possible ways. For example, we can customize a button using CustomTkinter, we can make cu
7 min read
Building a Basic Chrome Extension
Want to add extra functionality to your Chrome browser or create a useful tool? Developing a Chrome extension is a great starting point! In this tutorial, we'll break down the essential steps of building your first basic (yet functional) extension. So there’s some basic stuff that is required, it’s just like making a website, with a manifest! HTML:
4 min read
Basic Illumination Models
Illumination model, also known as Shading model or Lighting model, is used to calculate the intensity of light that is reflected at a given point on surface. There are three factors on which lighting effect depends on: Light Source : Light source is the light emitting source. There are three types of light sources: Their position, electromagnetic s
2 min read
Basic Quiz App In Flutter API
Flutter API is an open-source software development kit for building beautiful UI which is natively compiled. Currently, it is available as a stable version for iOS and Android OS. In this app we are going to have the features or modules mentioned below: Five multiple-choice questions ( more questions can be added ).Four selectable options for each
8 min read
Draw a moving car using computer graphics programming in C
In computer graphics, use graphics.h which provide direct functions to draw different coordinate shapes (like circle, rectangle etc). By using these functions we can draw different objects like car, hut, trees, etc. In this program, we will draw a moving car using line and circles. Functions used in program: delay(n): This function is used for hold
4 min read
Article Tags :