sudo apt-get install build-essentialsudo apt-get install libgl1-mesa-devsudo apt-get Install Libglu1-mesa-devsudo Apt-get Install Freeglut3-dev
Some tutorials on the Web The last step is sudo apt-get install Libglut-dev, but will be error unable to locate package Libglut-dev, Google error message after the search on StackOverflow someone asked this question, Http://askubuntu.com/questions/96087/how-to-install-opengl-glut-libraries, recommended installation Freeglut3-dev
header files and dynamic library files (libglu.so libgl.so libglut.so), respectively, as
I used the Youcompleteme plugin, so I copied the ycm configuration file to the root directory of the OpenGL program
CP ~/.vim/bundle/youcompleteme/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py ~/opengl/
Then open the Python configuration file and add it at the end of the flags to automatically complete the OpenGL function.
and find an OpenGL sample code on the Internet.
File Name:example.cpp #include <GL/glut.h> void Draw () { glclearcolor (1, 0, 0, 1); Glclear (gl_color_buffer_bit); Glflush ();} int main (int argc, char** argv) { glutinit (&ARGC, argv); Glutinitdisplaymode (Glut_single | GLUT_RGB); Glutinitwindowposition (+); Glutinitwindowsize (a); Glutcreatewindow ("My first OpenGL program"); Glutdisplayfunc (draw); Glutmainloop (); return 0;}
In fact, the code is very good understanding, glut is the prefix, the following function name is very intuitive, reference blog: http://www.cppblog.com/doing5552/archive/2009/01/08/71532.html
The simple code only needs to change the key draw function, so I wrote an OpenGL code template generator with bash
#!/bin/bash# File name:opengl.sh# Created time:thu 06:48:03 AM pstif [$#-lt 1]; Then echo "Usage:./opengl.sh <filename>" Exit 1fifilename=$1# if the file exists, open it without deleting the original file if [-e $FileName]; Then vim $FileName exit 1fi# generate OpenGL Frame echo "//File Name: $FileName" >> $FileNameecho "#include <gl/glut.h > >> $FileNameecho >> $FileNameecho void Draw () >> $FileNameecho "{" >> $FileNameecho-E "\ T" >> $FileNameecho "}" >> $FileNameecho "" >> $FileNameecho "int main (int argc, char** argv)" >> ; $FileNameecho "{" >> $FileNameecho-E "\tglutinit (&ARGC, argv);" >> $FileNameecho-E "\ Tglutinitdisplaymode (Glut_single | GLUT_RGB); ">> $FileNameecho-E" \tglutinitwindowposition (+); ">> $FileNameecho-E" \ Tglutinitwindowsize, ">> $FileNameecho-E" \tglutcreatewindow (\ "My first OpenGL program\"); ">> $ Filenameecho-e "\tglutdisplayfunc (draw);" >> $FileNaMeecho-e "\tglutmainloop ();" >> $FileNameecho-E "\treturn 0;" >> $FileNameecho "}" >> $FileNamevim $Fi Lename +6 # Jump directly to the draw () function when open exit 0
You can copy the code first. When writing echo, you can call the VIM command to add tab in bulk
: 28,33s/^\ (. *\) $/echo-e "\\t\1"/g
For example, I put the code in quotes with Echo-e "" in lines 28 through 33 (no spaces or tabs at the beginning of the line).
: 17,34s/\ (. *\)/\1 >> $FileName/g
17 lines to 34 end of line add >> $FileName redirect input to file, before using standard output to see if Echo is correct.
--------------------------------------------------------------------------------------------------------------- --------
Then I was sick to make this into a system command, found that there should be no program called GL, so I wrote a C + + program call opengl.sh and then put in the bin directory =. =
File name:gl.cpp#include <stdio.h> #include <stdlib.h> #include <string> int main (int argc, char** ar GV) { if (ARGC < 2) { fprintf (stderr, "Usage:gl <pathname>\n"); Exit (1); } std::string cmd = "./opengl.sh"; Cmd.append (argv[1]); System (CMD.C_STR ()); return 0;}
Command
g++ gl.cpp-o Glsudo CP GL opengl.sh/bin/
You can then use the command GL Test.cpp to create the OpenGL code template, and if you want to modify it, just modify the opengl.sh, do not need to recompile CPP
--------------------------------------------------------------------------------------------------------------- --------
Find yourself more and more like the Linux programming environment, the command line is really super awesome! I'm not used to writing code with VS recently. Although there are shortcut keys, such as Ctrl+shift+h open the Global replacement window, but it is not as good as the VIM command mode directly replace the convenience.
Ubuntu 16.04 Configuration OpenGL Tutorial