1. Installhowto: sudoapt-getinstallmesa-common-devmesa-utilsmesa-utils-extralibgl1-mesa-devlibglu1-mesa-devfreeglut3-dev2.ATEST:/* test. c * This program exploits
1. Install howto:
Sudo apt-get install mesa-common-dev mesa-utils-extra libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev
2. a test:
/* Test. c
* This program uses GLUT to draw an OpenGL window and display a ball for illumination.
* Because the header file glut. h contains the gl. h and glu. h, you only need to include this file.
*/
# Include
# Include
/* Initialize the material attributes, light source attributes, and illumination model, and open the depth buffer */
Void init (void)
{
GLfloat mat_specular [] = {1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess [] ={ 50.0 };
GLfloat light_position [] = {1.0, 1.0, 1.0, 0.0 };
GlClearColor (0.0, 0.0, 0.0, 0.0 );
GlShadeModel (GL_SMOOTH );
GlMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular );
GlMaterialfv (GL_FRONT, GL_SHININESS, mat_shininess );
GlLightfv (GL_LIGHT0, GL_POSITION, light_position );
Glable (GL_LIGHTING );
Glable (GL_LIGHT0 );
GlEnable (GL_DEPTH_TEST );
}
/* Call the GLUT function to draw a ball */
Void display (void)
{
GlClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
Glusolidsphere (1.0, 40, 50 );
GlFlush ();
}
/* Defines the reshape function of GLUT. w and h indicate the width and height of the current window respectively */
Void reshape (int w, int h)
{
GlViewport (0, 0, (GLsizei) w, (GLsizei) h );
GlMatrixMode (GL_PROJECTION );
GlLoadIdentity ();
If (w <= h)
GlOrtho (-1.5, 1.5,-1.5 * (GLfloat) h/(GLfloat) w, 1.5 * (GLfloat) h/(GLfloat) w,-10.0, 10.0 );
Else
GlOrtho (-1.5 * (GLfloat) w/(GLfloat) h, 1.5 * (GLfloat) w/(GLfloat) h,-1.5, 1.5,-10.0, 10.0 );
GlMatrixMode (GL_MODELVIEW );
GlLoadIdentity ();
}
/* Define the keyboard response function */
Void keyboard (unsigned char key, int x, int y)
{
/* Press Esc to exit */
Switch (key)
{
Case 27:
Exit (0 );
Break;
}
}
Int main (int argc, char ** argv)
{
/* Initialize the GLUT environment */
Gluinit (& argc, argv );
/* Display Mode Initialization */
Fig );
/* Define the window size */
Gluinitwindowsize (300,300 );
/* Define the window position */
Gluinitwindowposition (100,100 );
/* Display window with the title of execution function */
Ngcreatewindow (argv [0]);
/* Call the OpenGL initialization function */
Init ();
/* Register the OpenGL plot function */
Gludisplayfunc (display );
/* Response function when the size of the registration window changes */
Glureshapefunc (reshape );
/* Register the keyboard response function */
Glukeyboardfunc (keyboard );
/* Enter the GLUT message loop and start executing the Program */
Glumainloop ();
Return 0;
}
G ++ test. c-lglut