How to install OpenGL in Ubuntu in C++?

What Is OpenGL?

OpenGL is a Graphics rendering API which is operating system independent, window system independent and has high-quality color images composed of geometric and image primitives. OpenGL APIs can use following –

GL

OpenGL …


This content originally appeared on DEV Community and was authored by Saheb Giri

What Is OpenGL?

OpenGL is a Graphics rendering API which is operating system independent, window system independent and has high-quality color images composed of geometric and image primitives. OpenGL APIs can use following -

  1. GL
  2. GLU
    • OpenGL Utility
  3. Glut
  4. FLTK
  5. GLEW

Now lets see how to install OpenGL in Ubuntu.

Now because GLUT (OpenGL Utility Toolkit) depends upon OpenGL and a number of other related libraries, if we install GLUT then OpenGL will be automatically be installed.

First update the repository using the given command

$ sudo apt-get update

Run the following command to install OpenGL.

$ sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev

Now to test if OpenGL libraries are working fine on our Linux machine, we will create a C++ program and test it.

So create a following C++ Program.

#include <GL/glut.h>

void displayMe(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
        glVertex3f(0.5, 0.0, 0.5);
        glVertex3f(0.5, 0.0, 0.0);
        glVertex3f(0.0, 0.5, 0.0);
        glVertex3f(0.0, 0.0, 0.5);
    glEnd();
    glFlush();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE);
    glutInitWindowSize(400, 300);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("Hello world!");
    glutDisplayFunc(displayMe);
    glutMainLoop();
    return 0;
}

Now give the command below to compile your code.

$ g++ main.cpp -o firstOpenGlApp -lglut -lGLU -lGL

Now run your OpenGl program with following command

$ ./firstOpenGlApp

You will see something like this on your screen if everythings went well.
OpenGl in Ubuntu using C++


This content originally appeared on DEV Community and was authored by Saheb Giri


Print Share Comment Cite Upload Translate Updates
APA

Saheb Giri | Sciencx (2021-09-28T15:05:29+00:00) How to install OpenGL in Ubuntu in C++?. Retrieved from https://www.scien.cx/2021/09/28/how-to-install-opengl-in-ubuntu-in-c/

MLA
" » How to install OpenGL in Ubuntu in C++?." Saheb Giri | Sciencx - Tuesday September 28, 2021, https://www.scien.cx/2021/09/28/how-to-install-opengl-in-ubuntu-in-c/
HARVARD
Saheb Giri | Sciencx Tuesday September 28, 2021 » How to install OpenGL in Ubuntu in C++?., viewed ,<https://www.scien.cx/2021/09/28/how-to-install-opengl-in-ubuntu-in-c/>
VANCOUVER
Saheb Giri | Sciencx - » How to install OpenGL in Ubuntu in C++?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/28/how-to-install-opengl-in-ubuntu-in-c/
CHICAGO
" » How to install OpenGL in Ubuntu in C++?." Saheb Giri | Sciencx - Accessed . https://www.scien.cx/2021/09/28/how-to-install-opengl-in-ubuntu-in-c/
IEEE
" » How to install OpenGL in Ubuntu in C++?." Saheb Giri | Sciencx [Online]. Available: https://www.scien.cx/2021/09/28/how-to-install-opengl-in-ubuntu-in-c/. [Accessed: ]
rf:citation
» How to install OpenGL in Ubuntu in C++? | Saheb Giri | Sciencx | https://www.scien.cx/2021/09/28/how-to-install-opengl-in-ubuntu-in-c/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.