OpenGL on Linux Mint: Easy Mesa Install Guide
OpenGL on Linux Mint: Easy Mesa Install Guide
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>.

Installing Mesa

Update the package index and installed packages. 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

Remove previous Mesa PPAs. 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.

Add the Kisak Mesa PPA. You can use the Kisak PPA to get a newer version of Mesa on your Linux Mint system. 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

Install Mesa Utilities. 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

Verify the installation. 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.

Install additional libraries. 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. 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

Creating an OpenGL Program

Create a directory for your program. Change into your preferred directory, then use the mkdir command to create a directory for your program. For example, mkdir Sample-OpenGL-Programs.

Create a text file with your favorite text editor. 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

Copy and paste OR type the code: #include #include 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; }

Save the file and exit.

Compile your program. To build your program and link your Open GL libraries, use this command: g++ main.c -lglut -lGL -lGLU -o OpenGLExample

Run the program. To do this, type ./OpenGLExample and press Enter.

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".

What's your reaction?

Comments

https://hapka.info/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!