Linux(Ubuntu 14.04) setting up OpenGL
1. Install c/c++ compilation package.
2. install openGL and freeGlut library
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev
3. testing: run this code (comes from openGL red book) by save it as a cpp file. Then open the terminal and navigate to the directory containing this cpp file.
g++ text.cpp -lglut -lGL
Then you will get an a.out. run it by
./a.out4. Done
1 #include "GL/freeglut.h" 2 #include "GL/gl.h" 3 4 /* display function - code from: 5 http://fly.cc.fer.hr/~unreal/theredbook/chapter01.html 6 This is the actual usage of the OpenGL library. 7 The following code is the same for any platform */ 8 void renderFunction() 9 { 10 glClearColor(0.0, 0.0, 0.0, 0.0); 11 glClear(GL_COLOR_BUFFER_BIT); 12 glColor3f(1.0, 1.0, 1.0); 13 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); 14 glBegin(GL_POLYGON); 15 glVertex2f(-0.5, -0.5); 16 glVertex2f(-0.5, 0.5); 17 glVertex2f(0.5, 0.5); 18 glVertex2f(0.5, -0.5); 19 glEnd(); 20 glFlush(); 21 } 22 23 /* Main method - main entry point of application 24 the freeglut library does the window creation work for us, 25 regardless of the platform. */ 26 int main(int argc, char** argv) 27 { 28 glutInit(&argc, argv); 29 glutInitDisplayMode(GLUT_SINGLE); 30 glutInitWindowSize(500,500); 31 glutInitWindowPosition(100,100); 32 glutCreateWindow("OpenGL - First window demo"); 33 glutDisplayFunc(renderFunction); 34 glutMainLoop(); 35 return 0; 36 }
Note: Fell free to context me.