Skip to content

Instantly share code, notes, and snippets.

@shamiul94
Last active November 15, 2024 21:28
Show Gist options
  • Save shamiul94/a632f7ab94cf389e08efd7174335df1c to your computer and use it in GitHub Desktop.
Save shamiul94/a632f7ab94cf389e08efd7174335df1c to your computer and use it in GitHub Desktop.
How to install opengl in ubuntu
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 API implementation (http://www.opengl.org)
Glu
OpenGL Utility
Glut – GLUT (OpenGL Utility Toolkit) – Glut is portable windowing API and it is not officially part of OpenGL.
OpenGL Utility Toolkit (http://www.opengl.org/resources/libraries/glut/)
FLTK
FlashLight ToolKit (http://www.fltk.org/)
GLEW…
Now lets see How to install OpenGL on out Ubuntu OS.
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.
Run the following commands to install OpenGL.
$ sudo apt-get update
$ sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev
Now 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
@bhavik-knight
Copy link

Thank man, you're a life-saver. It helped me running on WSL-Ubuntu running within Mobaxterm with VSC on windows.

@shamiul94
Copy link
Author

@bhabik-knight Happy to be of help. Kindly share if you had to make any modifications to these commands to make it work on your OS configuration so that the next user doesn't have to reinvent the wheel.

@bhavik-knight
Copy link

I didn't have to modify any command. I just use Makefile to automate the building task. So that linkers are linked properly. Thank you so much!

@ominusliticus
Copy link

ominusliticus commented Mar 28, 2021

I seem to be having the issue:

In file included from /usr/include/GL/glut.h:17:0,
                 from test.cpp:1:
/usr/include/GL/freeglut_std.h:128:13: fatal error: GL/gl.h: No such file or directory
 #   include <GL/gl.h>
             ^~~~~~~~~
compilation terminated.

I called the file test.cpp instead of main.cpp

@bhavik-knight
Copy link

#include <GL/glut.h>
is the correct header to include @ominusliticus

@LinuxRocks2000
Copy link

LinuxRocks2000 commented May 4, 2021

Installed everything following this tutorial, when I compile a glew/GLFW project it works but upon running it gives Assertion `tls->posix.allocated == GLFW_TRUE' failed and aborts. Is this a quirk of my operating system (Kubuntu 20.04), or do I need to install compatibility libraries?

@GithungoIan
Copy link

Thanks a lot this was very much helpful I was able to create my first window and draw a Polygon. I am running Ubuntu 20.04

@Yvn919
Copy link

Yvn919 commented Jun 22, 2021

I have a hello world windows and that is black and a white triangle .... is this normal ?

@EvanNibbe
Copy link

Dude, you are a lifesaver, this is the first time I have ever made C++ code create a pop-up graphical item!

@Murnomous24
Copy link

thx bro. so clean and impressive!

@Lucas-Masaba
Copy link

Easier than the other articles and videos I walked through and it works. Thank you

@valFortD
Copy link

The instruction was very easy to understand for a newbie like me. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment