Setting up OpenGL in Windows, Linux, Mac

Setting up OpenGL in Windows, Mac and Linux is quite easy, I am going to show how to setup OpenGl in  Windows, Linux and Mac.

OpenGL is a extension to many programming language like C++, Java etc. which act as  software interface provided for graphics devices.

Individual will be taught about implementing different graphics design for eg. making a line, a circle or any other polygon. This tutorial will tell you basic prerequisities for developing openGL programs on different platforms like Windows and Linux(Ubuntu here).

Windows provides many IDE’s and open source tools for developing openGL projects like Visual Studio, DevC++, AMD CodeXL as a plugin for Visual Studio and also as standalone tools for both Windows and Linux. OpenGL tools for Linux are BuGle which is a freeware debugger for Linux and other Unix.

We will be talking mainly about installing/setting up openGL for Visual Studio in Windows and as well as in Linux and will also debug and run our application.

Setting up OpenGL in Visual Studio 2013 (Windows 7,8,8.1,10):

    1. Install Visual Studio 2013.
    2. Open installed Visual Studio 2013 and select Visual C++ and then select Empty Project and name the project as shown.

Setting_up_openGL_in_Windows_1

3. Right Click on Source Folder and Select Add and then Select New Item as shown.

setting_up_opengl_in_visual_studio

      1. A new Window will pop up as shown.

P1A (3)

      1. Select C++ File(.cpp) and name it (here Source.cpp) and finally press Add. This will add a C++ file to your Empty Project.
      2. Now you have to download some header (.h), system files (.dll) for rendering opengl in Visual Studio 2013.
      3. Link is http://www.mediafire.com/download/1nvslbmbjtf9d1h/glutfiles.rar
      4. Download the above link and unextract it.The Folder will contain as shown.

P1A (4)

      1. Now you need to configure Visual Studio 2013 for opengl programming.
      2. Go to Visual Studio New Empty Project with Source.cpp added to it. Right Click on the properties of ProjectName as shown.

P1A (5)

      1. A window will pop up then Select option C/C++>>General>>Additional Include Directories as shown.

P1A (6)

      1. Select the down arrow there will be edit option click that and select the downloaded folder and first select the freeglut folder to include its include folder to additional include directory as shown. Click Select Folder as shown.

P1A (7)

      1. Perform similar task for other folder to include that folder’s include folder to additional include directory.
      2. When both folder’s include will be included it will look like this as shown.

P1A (8)

      1. Finally click OK button.
      2. Now you have to include additional dependencies as shown

P1A (9)

For this click Linker>>Input>>Additional Dependencies then click down arrow this below shown window will popup then write two library files as shown below glew32.lib and freeglut.lib finally press OK button. You will get a window as shown

P1A (10)

      1. Now you have to include lib folder of each freeglut and glew to this project for this you have to go to Linker>>General>>Additional Library Dependencies and then click down arrow this window will pop up as shown.

P1A (11)

      1. Now add the lib folder of each glew and freeglut folder which were downloaded as shown.

P1A (12)

      1. Similarly for glew folder. Include its lib folder as done above in picture. After performing lib folders the result will look like as shown.

P1A (13)

      1. The work is almost done now finally you have to include the system .dll files to the project as shown. Copy the two files from the downloaded folder named freeglut.dll and glew32.dll .

Paste them into the project folder where the Source.cpp is present the final result should look as shown below.

      1. A opengl program is also provided in the download folder which can be used to open a normal opengl window along with the console window in the Visual Studio.

 #include <GLglew.h>
 #include <GLfreeglut.h>
 #include <iostream>
 using namespace std;
 void viewport(int width, int height)
 {
 glViewport(0, 0, width, height);
 }
 void render()
 {
 /*GLenum e = glewInit();
 if (GLEW_OK != e)
 {
 cout<< glewGetErrorString(e);
 }*/
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glutSwapBuffers();
 }
 int main(int argc, char* argv[]) {
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
 glutCreateWindow("openGL");
 glutInitWindowSize(500, 500);
 glutReshapeFunc(viewport);
 glutDisplayFunc(render);
 glutMainLoop();
 return 0;
 }
 

Understanding Program

#include <GLglew.h>

#include <GLfreeglut.h>

This header files are primarily used for the programming of opengl programs. Withous these header files opengl program will not run.

      1. First is glew.h is OpenGL Extension Wrangler Library which loads opengl extension functions from the opengl implementation and it also provides a function glewInit() to initialize extension entry point.                                                 If this glewInit() functions returns GLEW_OK as shown in the program then we can use the extensions provided by the glew.h and also core opengl functionality.
      1. Second is freeglut.h header file, this library provides us various functions like we already used so much function in the above program like glutCreateWindow(“opengl”) which creates a window with title as given, glutInitWindowSize(a,b) which set the size of initial window, glutReshapeFunc(function) is a callback function which is called whenever anyone tries to change the size of the window or it is reshaped.
      2.  The width and height of the callback specify the widht and height of the window that is displayed. These parameters are used to set new viewport.
      3. glutDisplayFunc(dispfunction) similar to the reshape function this is display callback for the window. Whenever the window is reshaped GLUT see it need to be redisplayed and this display callback for the window is called.
      4. glutMainLoop() it calls the different callbacks like display, reshape over and over again so that it can maintain a particular display frame rate. The main function that is required is glutDisplayFunc(df) this function is required so that it can display whatever your application is going to do.

 

Installing OpenGL in Ubuntu (Linux)

      1. You can either have Ubuntu installed as primary operating system in your computer or you can have it installed as a Virtual Machine in VMWare Workstation.
      2. You can download Ubuntu from the Ubuntu Official Website. Make it run in VMWare if you are using VMWare or Start Ubuntu if it is as a primary OS booted.
      3. This project contains steps for installing openGL in Ubuntu.
      4. Open Terminal in Ubuntu by Clicking Application at the Top Left Corner or press Ctrl+Alt+T as shortcut as shown.

P1B (1)

      1. Type the command sudo apt-get install freeglut3 freeglut3-dev

This command with the super user permission will install freeglut3 and freeglut3-dev libraries on your computer.

      1. After pressing Enter the screen will look like as shown.

P1B (2)

      1. So you have successfully installed the libraries. Now you need to install the packages. You need to go to the link for downloading the package file for your computer.

https://ftp.iitm.ac.in/debian/pool/main/g/glui/

The page looks like

P1B (3)

Here you have to look for files according to your computer requirements. Select either amd64 or 1386 and download both libglui-dev and libglui2c2.

These will be downloaded to your local Downloads folder in Ubuntu.

      1. Now again open Terminal by pressing shortcut Ctrl+Alt+T.
      2. Type the command as shown.

P1B (4)

      1. First type cd Downloads/ to go to the Downloads directory if you type ls it will list all the files and folder in the current directory here it is Downloads.
      2. Now the main command type sudo dpkg –i libglui2c2_2.36-4_amd64.deb which will depackage that we just downloaded. If this does not work then download the other package that was there in the link. 36-4_i386.deb and then run the same command.
      3. Now you have installed the package libglui. Now next step is to install libglui-dev
      4. For that type the same command sudo dpkg –i libglui-dev_2.36-4_amd64.deb that will also produce the above snap that we discussed if there is any problem then download the other link libglui-dev_2.36-4_i386.deb and try the same command

sudo dpkg –i libglui2c2_2.36-4_amd64.deb this will work fine.

      1. Now you are good to go.
      2. Now type this basic code in any .cpp file and place it in a folder. Make that folder in Desktop you can make it anywhere as shown. Opening that folder will look like as shown.

P1B (5)

      1. The code to write in this work.cpp is
 #include <iostream>
 #include <stdlib.h>
 #include<GL/glut.h>
 #include<GL/glui.h>
 #include<GL/glu.h>
 using namespace std;
 void viewport(int width, int height)
 {
 glViewport(0, 0, width, height);
 }
 void render()
 {
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glutSwapBuffers();
 }
 int main(int argc, char* argv[]) {
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
 glutCreateWindow("openGL in Ubuntu");
 glutInitWindowSize(500, 500);
 glutReshapeFunc(viewport);
 glutDisplayFunc(render);
 glutMainLoop();
 return 0;
 }
 
      1. Now you have to compile this work.cpp file. For that open Terminal by pressing Ctrl+Alt+T.
      2. And type command to reach the GLUT folder on the desktop for this you will type

cd Desktop press Enter

cd GLUT press Enter

      1. Now type g++ work.cpp –lglut –lGL – lglui –o work.
      2. Now the file work.cpp have been compiled. Now type ./work to open the opengl window of our basic application.
      3. The following compiling and opening command will look as shown.

P1B (6)

      1. After pressing Enter the window which will pop up will look like as shown.

P1B (7)

      1. There will be lots of tutorial on making various objects, animation, transformation, texturing, interaction with peripheral devices (Keyboard and Mouse), various algorithms etc.

 

Setting up OpenGL in DevC++

      1. First of all install the Dev C++ while downloading it from the official website the latest version http://orwelldevcpp.blogspot.co.at/
      2. After downloading it install with the normal configuration. When the installation is done. Open Dev C++.
      3. Go to File->New->SourceFile  you can directly hit the keyboard shorcut Ctrl+N.
      4. Now you have to download the glut files(Library, Header and System files) which can be obtained directly from the link described here.
      5. http://www.mediafire.com/download/fwn0j0n123hn6e1/glutming.rar
      6. Now Unzip the downloaded which will contain three files as shown.

P1 Dev glutmingfolder

      1. Now you have to put these files to their appropriate places so let do it.
      2. Take glut.h from the downloaded folder and copy it into the path  C:\Program Files (x86)\Dev-Cpp\MinGW32\include\GL  as shown.

P1 Dev glut.hfilecopying

      1. Take libglut32.a file from the downloaded folder and put it in the path C:\Program Files (x86)\Dev-Cpp\MinGW32\lib as shown.

P1 Dev libglut32.a

      1. Now finally the system file take glut32.dll and copy to the path C:\Windows\System32 as shown.

P1 Dev Systemfile

      1. Now you are done. Finally open Dev C++ and type this openGL code.

 #include <GL\glut.h>
 using namespace std;
 void viewport(int width, int height)
 {
 glViewport(0, 0, width, height);
 }
 void render()
 {
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glutSwapBuffers();
 }
 int main(int argc, char* argv[]) {
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
 glutCreateWindow("openGL");
 glutInitWindowSize(500, 500);
 glutReshapeFunc(viewport);
 glutDisplayFunc(render);
 glutMainLoop();
 return 0;
 }
      1. Before compiling the program follow this last step.
      2. Go to Tools->Compiler->General Tick the following as shown and write this line in the textarea -lglu32 -lglut32 -lopengl32 as shown

P1 Dev compileroption

Finally compile and run the file you will get the following output as shown.

P1 Dev Finalimage

Setting up OpenGL in CodeBlock

      1. First of all download and install the CodeBlock on your computer from the official website http://sourceforge.net/projects/codeblocks/files/Binaries/13.12/Windows/codeblocks-13.12mingw-setup-TDM-GCC-481.exe/download
      2. After downloading this setup install it on the computer.
      3. Now you have to configure it for the opengl development.
      4. First of all download the freeglut libraries,headers,and system files from the link given below

http://www.mediafire.com/download/b4s0y548eobb5a0/codeblock_freeglut.rar

      1. After downloading this folder it should contain three folders like as shown

 P1Ccfolderdes

      1. Now you have to copy these all three folders and paste it to the given path C:\Program Files (x86)\CodeBlocks\MinGW as shown

P1CCcopyfolderstomingw

      1. It will ask for the either replacing the existing files or not you have to select ok for merging the files with the same name.
      2. Now 50% work here is done Now copy the dll file from the downloaded folder in the bin folder as shown

 P1Ccfreeglut.dll

      1. Paste the above dll file to the following path C:\Windows as shown

 P1CCwindowsfreeglut.dll

      1. Now you have to change the configuration files because first they are set for the glut32 and now we have to change them to freeglut libraries
      2. Open notepad with administrator previledges as shown

 P1CCnotepad

      1. Go to File->Open and select the path as given C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\templates\wizard\glut as shown P1CCwizardglut
      • Click on the script and press OK for changing the content inside the file and change the content glut32 to freeglut as shown. Find once more if glut32 is present or not if present then change that also to freeglut.

 p1CCglut32tofreeglut

      1. Again open an another file in the notepad open with administrator previledges.Go to the path Go to File->Open and select the path as given C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\templates and open the filenamed cbp and find the term “glut32” and replace it with “freeglut” after the final changes it should look like as shown

 P1CCtemplatechange

      • Now everything is done. Open CodeBlock and open a new Project and select GlutProject after giving it a project name press next now you have to give its path name as C:\Program Files (x86)\CodeBlocks\MinGW as shown

 P1CCpath

      1. You will get a default opengl code now just press compile and run button that will give you following window as shown

P1CCfinal

 

 

Setting up an OpenGL project using Apple Xcode

 

 

 

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *