PDF download Download Article
Easily install the latest OpenGL libraries on Linux Mint to render 2D and 3D graphics
PDF download Download Article

Mesa is an open-source implementation of OpenGL for Linux. Installing Mesa on Linux Mint gives you access to OpenGL, Vulkan, and other graphics-related libraries needed for gaming (including with Steam ) and game development. The most up-to-date version of Mesa is not available from your system's repository, but you can get the latest hardware support and features by installing the Kisak Mesa PPA. This wikiHow guide will walk you through installing Mesa and other important OpenGL libraries on Linux Mint and show you how to create and compile your first OpenGL program.

Things You Should Know

  • To install the Kisak Mesa PPA, use this command: sudo add-apt-repository ppa:kisak/kisak-mesa
  • If you want to write games and programs, you'll also want to install other OpenGL libraries, including GLEW, freeglut, mesa-common-dev, and mesa-utils.
  • To compile a C program that uses these OpenGL libraries, use g++ <program_name.c> -lglut -lGL -lGLU -o <program_name> .
Method 1
Method 1 of 2:

Installing Mesa

PDF download Download Article
  1. Before installing the necessary libraries for OpenGL development , you'll need to make sure Linux Mint has the latest version of the package index, and that your existing packages are up to date. Run the following commands in your Terminal:
    • sudo apt update
    • sudo apt upgrade
  2. If you've already installed kisak-mesa and want to upgrade the libraries, remove the current installation first. To do so, run these commands:
    • sudo apt install ppa-purge
    • sudo ppa-purge -d jammy ppa:kisak/kisak-mesa
      • If you're using a version of Linux Mint that isn't based on Ubuntu Jammy Jellyfish, replace jammy with your version. For example, if you're using Linux Mint 20, which is built on Ubuntu Focal Fossa, you'd use sudo ppa-purge -d focal ppa:kisak/kisak-mesa .
    Advertisement
  3. You can use the Kisak PPA to get a newer version of Mesa on your Linux Mint system. [1] To do so, run these commands:
    • sudo add-apt-repository ppa:kisak/kisak-mesa
      • If you get an error that says "command not found," run sudo apt-get install software-properties-common . Then, try again.
    • sudo apt update
  4. the Kisak Mesa to Linux Mint. Now that you've added the PPA, run this command to install the Mesa utilities on Linux Mint:
    • sudo apt install mesa-utils
  5. Once Mesa is installed, run the command glxinfo | grep "OpenGL version" to check your Mesa version.
    • If you plan to upgrade Linux Mint or upgrade Mesa, remove this PPA before doing so using the command in Step 2 .
  6. To make sure you have what you'll need to be able to compile programs with GLEW (OpenGL Extension Wrangler Library), and have several other libraries installed:
    • Run this command to install GNU make and other build tools: sudo apt install build-essential libxmu-dev libxi-dev libgl-dev binutils . [2]
    • Install the GLEW packages using this command: sudo apt install glew-utils libglew2.2 libglewmx-dev libglewmx1.13
    • Install freeglut: sudo apt install freeglut3-dev freeglut3
    • Install mesa-common-dev: sudo apt install mesa-common-dev
  7. Advertisement
Method 2
Method 2 of 2:

Creating an OpenGL Program

PDF download Download Article
  1. Change into your preferred directory, then use the mkdir command to create a directory for your program. For example, mkdir Sample-OpenGL-Programs .
  2. Enter the directory you created using cd Sample-OpenGL-Programs , then use any text editor (such as vi, nano, or gedit) to create a file called main.c . For example, nano main.c
    •  #include 
       <GL/freeglut.h> 
        
       #include 
       <GL/gl.h> 
        
       void 
       renderFunction 
       () 
       { 
       glClearColor 
       ( 
       0.0 
       , 
       0.0 
       , 
       0.0 
       , 
       0.0 
       ); 
       glClear 
       ( 
       GL_COLOR_BUFFER_BIT 
       ); 
       glColor3f 
       ( 
       1.0 
       , 
       1.0 
       , 
       1.0 
       ); 
       glOrtho 
       ( 
       - 
       1.0 
       , 
       1.0 
       , 
       - 
       1.0 
       , 
       1.0 
       , 
       - 
       1.0 
       , 
       1.0 
       ); 
       glBegin 
       ( 
       GL_POLYGON 
       ); 
       glVertex2f 
       ( 
       - 
       0.5 
       , 
       - 
       0.5 
       ); 
       glVertex2f 
       ( 
       - 
       0.5 
       , 
       0.5 
       ); 
       glVertex2f 
       ( 
       0.5 
       , 
       0.5 
       ); 
       glVertex2f 
       ( 
       0.5 
       , 
       - 
       0.5 
       ); 
       glEnd 
       (); 
       glFlush 
       (); 
       } 
       int 
       main 
       ( 
       int 
       argc 
       , 
       char 
       ** 
       argv 
       ) 
       { 
       glutInit 
       ( 
       & 
       argc 
       , 
       argv 
       ); 
       glutInitDisplayMode 
       ( 
       GLUT_SINGLE 
       ); 
       glutInitWindowSize 
       ( 
       500 
       , 
       500 
       ); 
       glutInitWindowPosition 
       ( 
       100 
       , 
       100 
       ); 
       glutCreateWindow 
       ( 
       "OpenGL - First window demo" 
       ); 
       glutDisplayFunc 
       ( 
       renderFunction 
       ); 
       glutMainLoop 
       (); 
       return 
       0 
       ; 
       } 
      
  3. To build your program and link your Open GL libraries, use this command: g++ main.c -lglut -lGL -lGLU -o OpenGLExample
  4. To do this, type ./OpenGLExample and press Enter .
  5. If you did everything right, a window will open. It will show a white square on a black background. The window will be titled "OpenGL - First window demo".
  6. Advertisement

Community Q&A

Search
Add New Question
  • Question
    Will this work for uBuntu 15.10?
    Community Answer
    Yes, it will definitely work for uBuntu 15.10.
  • Question
    Will this work for Ubuntu 17.04?
    Pingu
    Top Answerer
    It should work on any platform for which these packages are available through apt (i. e. on any recent version of Ubuntu or Debian or Mint). It worked on Ubuntu 16.04 for me. The only thing different from these instructions is that the package libglew1.5-dev doesn't exist. But if you just install libglew-dev, it will still work.
  • Question
    Can I install the libraries with a single command: "sudo apt-get install build-essential freeglut3 freeglut3-dev binutils-gold g++ cmake libglew-dev mesa-common-dev libglew1.5-dev libglm-dev"?
    Pingu
    Top Answerer
    Yes, you can. It's a long command and quite hard to read, but it will install all the necessary libraries.
See more answers
Ask a Question
      Advertisement

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!

      About This Article

      Thanks to all authors for creating a page that has been read 346,130 times.

      Is this article up to date?

      Advertisement