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++
OpenGL is an open graphics programming library developed by Silicon Graphics. Programmers use the application programming interfaces ( APIs ) of these libraries in order to write graphics programs using a variety of different languages including C, Java, and Python.
Graphics Library In Dev C 2b 2b 2c
- 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-CppMinGW64x86_64-w64-mingw32include folder.
- Step 5:Copy the libbgi.a file into lib folder and in D:Dev-CppMinGW64x86_64-w64-mingw32lib 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
- Open DevC++. Click file ->New ->Project.
- Make sure you get the Console Graphics option. However, we are not going to click on it.
- Choose Empty Project option and Give a project name and make sure the selected language is C++.
- Copy the following code to the editor window.
- Go to 'Project' menu and choose 'Project Options' (or just press ALT+P).
- Go to the 'Parameters' tab In the 'Linker' field, enter the following text:
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32 - Click OK and Compile and run the project and you'll get this output:
Program Explanation
Graphics Library In Dev C 2b 2b 4
- 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
This article is contributed by Mudit Maheshwari. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Recommended Posts:
CONTENTSBackground
Obtaining the Software
Installing the Software
Obtaining GLUT Files
Project Settings For anGLUT OpenGL Project
Compiling and RunningYour Project
Background
OpenGL is anopen graphics programming librarydeveloped by Silicon Graphics.Programmers use the applicationprogramming interfaces (APIs) of theselibraries in order to writegraphics programs using a variety of different languages including C++,Java, and Python. The purpose of this documentis to enable you to usean open-source integrated development environment (IDE)for writingOpenGL programs using C++.
Writing a program in any programming language requires a text editor,compiler, and linker in order to generate the executable, or softwareapplication that runs on a particular operating system such as WindowsXP or Mac OS X. Tosimplify the task of writing programs, softwaredevelopers created an IDE that organized all of the tasks of writing aprogram into one application. Popular IDEs include NetBeans (Java),Eclipse (multiple languagebindings), and VisualStudio (allMicrosoft-supported languages). NetBeans and Eclipse are freelyavailable, while Visual Studio is not free. Additionally, many ofthese IDEs have more features than you will probably need to use in anintroductory programming course.
Program Explanation
Graphics Library In Dev C 2b 2b 4
- 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
This article is contributed by Mudit Maheshwari. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Recommended Posts:
CONTENTSBackground
Obtaining the Software
Installing the Software
Obtaining GLUT Files
Project Settings For anGLUT OpenGL Project
Compiling and RunningYour Project
Background
OpenGL is anopen graphics programming librarydeveloped by Silicon Graphics.Programmers use the applicationprogramming interfaces (APIs) of theselibraries in order to writegraphics programs using a variety of different languages including C++,Java, and Python. The purpose of this documentis to enable you to usean open-source integrated development environment (IDE)for writingOpenGL programs using C++.
Writing a program in any programming language requires a text editor,compiler, and linker in order to generate the executable, or softwareapplication that runs on a particular operating system such as WindowsXP or Mac OS X. Tosimplify the task of writing programs, softwaredevelopers created an IDE that organized all of the tasks of writing aprogram into one application. Popular IDEs include NetBeans (Java),Eclipse (multiple languagebindings), and VisualStudio (allMicrosoft-supported languages). NetBeans and Eclipse are freelyavailable, while Visual Studio is not free. Additionally, many ofthese IDEs have more features than you will probably need to use in anintroductory programming course.
Obtainingthe Software
In order to find the best of both worlds-- a free IDE and a fairlystraightforward IDE for C++, I recommend downloading BloodshedSoftware's Dev-C++for writing OpenGL C++ programs. The link toBloodshed Software is: http://www.bloodshed.net.The link to downloading the most recent version of Dev-C++ can be foundat: http://www.bloodshed.net/dev/devcpp.htmland select the link that says 'Dev-C++ 5.0...with Mingw/GCC'. Please beaware that this software only runs on Windowsoperating systems.
Installingthe Software
To install the software, follow these steps:
- From the section labeled 'Dev-C++ 5.0...with Mingw/GCC', selectthe SourceForge link or clickhere.
- You will be taken to the SourceForge download server. Here, youcan select the serve from which to download Dev-C++. In most cases, itwill be better to choose a mirror (or download server) somewhere in theUnited States; however, this is not required. In the Download column, click on the linkof the server of your choice.
- The page will refresh. If a download window does not appear aftera few seconds, click on the link given near the top of the page. Then,choose a location to save the file. Wait while the file downloads.
- Find the location on your computer where you downloaded the fileand double-click on the Dev-C++ installation icon. A dialog box willappear indicating the progress of preparing for the installation.
- A dialog box will appear asking what language you want for thisinstallation and then press the Ok button.
- Review the license agreement. If you are able to accept the termsof the license agreement, press the IAgree button.
- Now it is time to select the type of installation. In order tokeep things simple, choose the option Full for the option of Selectthe Type of Install. Make sure that you have sufficient space toperform the full installation.
- Select the location where you want the files installed. Becauseof some difficulties that may occur if you install to a directory namethat contains spaces, choose a directory location or make a newdirectory that does not contain spaces. Although program installationshould typically be in C:ProgramFiles, either make a new directory called C:other-programs or simply acceptthe default location of C:Dev-cpp.
- Watch the program install the files.
- After the installation program installs all of the necessaryfiles, Dev-C++ should be ready to run. If you want to run Dev-C++ now,make sure to check the item labeled RunDev-C++ 5... Then, click on the Finish button.
- Read the notice that appears with the beta software.
- Configure the software using the dialog boxes. Speicifically, youwill choose the language that you want to use and decide on the styleof the user interface.
- If you would like to have a hierarchy of the classes that you areusing and/or would like to have the ability for code to be completed bythe editor if you type in a series of unique letters, select the Yes... option; otherwise, select the No... option.
- If you selected the Yes...option, you will be presented with the option of using a cache toassist the IDE with code completion. Unless there is a good reason notto do so (such as in the case with the IDE using too much memory andCPU power), create the cache now by selecting the Yes... option and pressing the Next button.
- If everything worked as expected, you should see the followingmessage:
If you are running a Windows computer, the necessary OpenGL filesshould already be available. When in doubt, check the directory C:WINNTsystem32. In thisdirectory, there should be files like opengl32.dlland glu32.dll. If you aremissing any of these files, things will not work correctly when you tryto write OpenGL. Traditionally, the windows that are used for OpenGLprograms were dependent upon the underlying operating system windowmanagement system. This did not allow OpenGL programs to be as portableacross platforms as they should be. To solve this problem, the OpenGLUtility Toolkit, or GLUT, was created. If you have never writtenanyOpenGL programs using GLUT before, the necessary files for running GLUTwill not be avaiable. For this reason, you need to download them. Awebsite which explains how to use Dev-C++ to writeOpenGL GLUT programsalso provides information on where to download the appropriate GLUTfiles in addition to where to put them. The information about how to dothese tasks was taken from: http://www.cs.uofs.edu/~mpc3/cmps370/glutsetup.html.Download the following files from these locations:
- glut.h fromhttp://www.cs.uofs.edu/~mpc3/cmps370/glut.hand save the file to C:Dev-C++includeGL.
- glut32.def from http://www.cs.uofs.edu/~mpc3/cmps370/glut32.defand save the file to C:Dev-C++lib.
- glut32.dll from http://www.cs.uofs.edu/~mpc3/cmps370/glut32.dlland save the file to C:WINNTsystem32.
ProjectSettings For an GLUT OpenGL Project
In Dev-C++,the IDEorganizes your code files into projects. Forthis reason, you need to specify the project type whenever you beginstart writing a new application. Follow the steps below to setup anOpenGLGLUT project:
- From the Dev-C++ menu, select File-> New -> Project. A new dialog box will appear.
- Press the Basic tab andselect Console Application fromthe types of projects.
- Type the name of the project in the field named Name.
- Select the C++ Project optionfrom the box with options.
- Press the Ok button.
- It would be advisable to keep your projects organized in somehierarchy. It may be suitable to make a new directory that contains allof your Dev-C++ projects or place these Dev-C++ projects in some otherappropriate directory. In any case, choose a location and make surethat the project name is indeed what you want the project to be named.The settings for the project will be stored in a file called project-name.dev where project-name is the name you wantedto name the project.
You want to choose a console application because the program that youwrite should not contain any Win32 API code (this is code written thataccesses programming libraries specific to the Windows operatingsystem). The console application will enable you to have code that canbe run on an operating system that does not have Windows.
The next series of steps involves configuring the project options sothat files needed to make an OpenGL GLUT program can be easily found bythe Dev-C++ IDE. Instructions similar to the steps listed below appearon the website whose address is: http://www.cs.uofs.edu/~mpc3/cmps370/glutsetup.html.
- From the Dev-C++ menu, select Project-> Project Options. A new dialog box will appear
- Press the Parameters tabwhich should make the dialog box appear as seen below:
- It is necessary to add libraries that will support the operationof OpenGL and GLUT. Repeat the following steps-- press the Add Library or Object button andthen select the appropriate library file. These files begin with theletters 'lib' and ends in '.a'. It will be necessary to add thefollowing files: libglut32.a, libglu32.a, and libopengl32.a. These files will belocated in the libGL directory of your Dev-C++ installation directory.For instance, one path possibility could be: C:Dev-C++lib. When you arefinished, the dialog should look like this:
- Then press the Ok button.
Graphics Library In Dev C 2b 2b 1b
. One thing to note, if you are new toprogramming, C++ is an 'improved' version of C that supports datastructures named objects. This loosely means that C program code can becompiled by a C++ compiler.Compilingand Running Your Project
Compiling and running the code in your project is veryeasy...but...figuring out why your specific program does not compile orrun can become very difficult. This is true of anyone-- those who havespent a lot of time programming and those people who are learning howto program. Since errors are typically unique to each situation forcompiling or debugging, it is up to you to learn how to do this.Assuming that everything written correctly and the project isconfigured to use the proper libraries, do the following:
- To compile a file, make sure that this file is visible in theeditor by selecting it from the list of files in the project browserand select Execute -> Compile fromthe menu. If you have multiple files in a project, complete this taskfor each file.
- To run a file, select from the menu Execute -> Run. If your programneeds parameters in order to run properly, first select Execute -> Parameters and fillin the appropriate values in the dialog box. Then, choose this menuoption Execute -> Run.