How to Install OpenGL on Ubuntu 20.04 Linux




In this post we will see how to install OpemGL on Ubuntu.In order to install OpenGlL you need to type only few commands .Here we will be looking at step by step process to install OpemGL:

1.First open your terminal and update the repository using command : $ sudo apt update

After entering your password your update will be done .

2.In this command your installation will be completed.Type the following command : $sudo apt-get install freeglut3-dev

After completion it will look like this :

.
3. To test if OpenGl libraries are working fine on our Linux, 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
 

OUTPUT:

opengl_out

If a window pops up when you run the program, then OpenGL is working on your Ubuntu OS.In this way , following these steps you will be able to install OpenGL and use it.


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*