My first linuxOpenGL Program (ubuntu)

Source: Internet
Author: User
My first linuxOpenGL Program (ubuntu) -- Linux general technology-Linux programming and kernel information. The following is a detailed description. [Configuration is slightly troublesome]
Although it is expected to be a little more difficult in ubuntu than in windows, there are still insufficient preparation. At first, a package was installed less, and then the compilation parameters were mistakenly added ...... In order to prevent future forgetting and adding blog content by the way, I recorded my wall hitting this hour.

[Preparations]
To compile a cpp-based OpenGL program, we must first prepare a text editor, C ++ compiler, and OpenGL & GLut library file.

The ubuntu system comes with some text editors: vim used by veterans and gedit used by beginners. Since both linux and openGL/Glut are new to the first-class production model (all words are incoherent-_-B), it is necessary to use gedit.

The gcc compiler (SET) in linux is quite famous, but ubuntu does not come with it and needs to be installed on its own. On the command line, enter:

Sudo apt-get install build-essential

In fact, build-essential is not a compiler, but a dependency between a bunch of software packages. After it is installed, the general compiler problem is basically solved.

The problem is solved by the OpenGL/Glut library. Similarly, enter:

Sudo apt-get install freeglut3 freeglut3-dev libglu3 libglut3-dev libgl1-mesa libgl1-mesa-dev

I am the miserable man who has lost me ~~ In the future, it will be better to flip through the Forum and then start T_T.

[Similar code]
# Include
# Include

Void RenderScene (void)
{
GlClear (GL_COLOR_BUFFER_BIT );
GlFlush ();
}

Void SetupRC (void)
{
GlClearColor (1.0f, 0.0f, 0.0f, 1.0f );
}

Int main (int argc, char ** argv)
{
Gluinit (& argc, argv );
Fig );
Valley createwindow ("Simple ");
Gludisplayfunc (RenderScene );

SetupRC ();

Glumainloop ();
Return 0;
}

[The Key to compilation is parameter]
Using gcc is different from using vs.net. IDE has done a lot of things for you. Here, we need to input the compilation parameters ourselves:

G ++ opgl. cc-o out. o-lglut-lGL-lGLU-lm-L/usr/X11R6/lib

Then, it becomes!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.