How to configure OpenGL using eclipseforc ++ in Ubuntu

Source: Internet
Author: User
Prerequisites: 1. The c ++ environment under Ubuntu is configured, and gcc and g ++ are available. 2. use eclipseforc + for OpenGL development step 1: run the following command on the ubuntu terminal to install the library file required by opengl $ sudoapt-getinstallbuild-essential $ sudoapt-getinstallfreeglut3-dev Step 2: run the opengl instance, test Configuration

Prerequisites:
1. The c ++ environment under Ubuntu has been configured, and gcc and g ++ are available.
2. Use eclipse for c + for OpenGL Development

Step 1:
Run the following command on the ubuntu terminal to install the library files required by opengl.
$ Sudo apt-get install build-essential
$ Sudo apt-get install freeglut3-dev

Step 2:

Run the opengl instance to test whether the configured environment is successfully installed.
Create a new project file under eclipse. Suppose we name it Test and create a new C ++ source code file in the project Test. Here we name it main. cpp, in main. enter the code in the cpp file.
# Include


Void init ();
Void display ();


Int main (int argc, char * argv [])
{
Gluinit (& argc, argv );
Fig );
Gluinitwindowposition (0, 0 );
Gluinitwindowsize (300,300 );


Valley createwindow ("OpenGL 3D View ");


Init ();
Gludisplayfunc (display );


Glumainloop ();
Return 0;
}


Void init ()
{
GlClearColor (0.0, 0.0, 0.0, 0.0 );
GlMatrixMode (GL_PROJECTION );
GlOrtho (-5, 5,-5, 5, 5, 15 );
GlMatrixMode (GL_MODELVIEW );
GluLookAt (0, 0, 10, 0, 0, 0, 0, 1, 0 );
}


Void display ()
{
GlClear (GL_COLOR_BUFFER_BIT );


GlColor3f (1.0, 0, 0 );
Gluwireteapot (3 );


GlFlush ();
}
Right-click the project file name
Test-> click Properties-> C/C ++ Bulid-> Settings-> gcc c ++ Linker-> Libraries,
Add several databases in this window,
These are respectively GLU, glut, GL,
Click OK.
If you want to use opencv,
Add the cv, cxcore, highgui, and other library files here,
Set as needed
Add the path/usr/include/GL to the incudepath under gcc c ++ Compiler-> nodes
If you want to use libraries in opencv, add the opencv path, which is usually/usr/include/opencv.

Running the above program will display the opengl running result in the shape of a teapot

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.