Easily download Mesa on Linux Mint to create 3D graphics with this user-friendly guide

Mesa is an open-source implementation of the OpenGL specification - a system for rendering interactive 3D graphics. Technically, OpenGL is just a specification, implemented by your graphics driver. There's no such thing like an OpenGL SDK library. There's just libGL.so which comes with your driver. To use it, you need bindings for your programming language of choice. If that is C, the "bindings" consist of just the header files. However you'll probably also want to use OpenGL extensions, which is easy using GLEW.


A variety of device drivers allows Mesa to be used in many different environments ranging from software emulation to complete hardware acceleration for modern GPUs. Mesa ties into several other open-source projects: the Direct Rendering Infrastructure and X.org to provide OpenGL support to users of X on Linux, FreeBSD and other operating systems.

Part 1
Part 1 of 3:

Preparing Your Linux Mint Operating System for OpenGL Development

  1. 1
    Open a terminal and enter the following commands to install the necessary libraries for OpenGL development:
    • Enter sudo apt-get update
    • Enter sudo apt-get install freeglut3
    • Enter sudo apt-get install freeglut3-dev
    • Enter sudo apt-get install binutils-gold
    • Enter sudo apt-get install g++ cmake
    • Enter sudo apt-get install libglew-dev
    • Enter sudo apt-get install g++
    • Enter sudo apt-get install mesa-common-dev
    • Enter sudo apt-get install build-essential
    • Enter sudo apt-get install libglew1.5-dev libglm-dev
  2. 2
    Get information about the OpenGL and GLX implementations running on a given X display. To do this, enter glxinfo .
  3. Advertisement
Part 2
Part 2 of 3:

Creating Your First OpenGL Program

  1. 1
    Open up a terminal. Make a directory, change into the directory and use your favorite text editor such as nano or gedit to create your OpenGL source code. Enter the following commands below.
    • Enter mkdir Sample-OpenGL-Programs
      • This will create a directory to hold your OpenGL programs.
    • Enter cd Sample-OpenGL-Programs
      • This will change you into your directory.
    • Enter nano main.c OR gedit main.c
  2. 2
    Copy and paste OR type the code:
      #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. 3
    Save the file and exit.
  4. Advertisement
Part 3
Part 3 of 3:

Compiling and Running Your OpenGL Application

  1. 1
    Enter the Sample-OpenGL-Programs directory. While there, run the following command:
    • g++ main.c -lglut -lGL -lGLEW -lGLU -o OpenGLExample
      • This command will compile and link your OpenGL libraries.
  2. 2
    Run the program. To do this, type the following:
    • Enter ./OpenGLExample
  3. 3
    Wait for a result. 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".
  4. Advertisement

Community Q&A

  • Question
    Will this work for uBuntu 15.10?
    Community Answer
    Community Answer
    Yes, it will definitely work for uBuntu 15.10.
  • Question
    Will this work for Ubuntu 17.04?
    Pingu
    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
    Pingu
    Top Answerer
    Yes, you can. It's a long command and quite hard to read, but it will install all the necessary libraries.
Advertisement

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 16 people, some anonymous, worked to edit and improve it over time. This article has been viewed 319,908 times.
How helpful is this?
Co-authors: 16
Updated: August 24, 2022
Views: 319,908
Categories: Linux
Advertisement