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.
Learn more...
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.
Steps
Preparing Your Linux Mint Operating System for OpenGL Development
-
1Open 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
-
2Get information about the OpenGL and GLX implementations running on a given X display. To do this, enter glxinfo .
Creating Your First OpenGL Program
-
1Open 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
- Enter mkdir Sample-OpenGL-Programs
-
2Copy 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; }
-
3Save the file and exit.
Compiling and Running Your OpenGL Application
-
1Enter 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.
-
g++ main.c -lglut -lGL -lGLEW -lGLU -o OpenGLExample
-
2Run the program. To do this, type the following:
- Enter ./OpenGLExample
-
3Wait 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".
Community Q&A
-
QuestionWill this work for uBuntu 15.10?Community AnswerYes, it will definitely work for uBuntu 15.10.
-
QuestionWill this work for Ubuntu 17.04?PinguTop AnswererIt 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.
-
QuestionCan 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"?PinguTop AnswererYes, you can. It's a long command and quite hard to read, but it will install all the necessary libraries.