centos安装openGL并且运行首个test

为了顺便重温一下linux下各种包的安装以及解决依赖,我在安装opengl时没有用yum,也没有用rpm,直接在官网下载tar包,编译,make install,出现了各种问题,汇总如下:

 

glew-1.10.0.tgz

glu-9.0.0.tar.gz

glut-3.7.tar.gz

glw-8.0.0.tar.gz

MesaLib-10.0.0-rc1.tar.gz

expat-2.1.0.tar.gz

inputproto-2.3.tar.gz

libdrm-2.4.50.tar.gz

libICE-1.0.8.tar.gz

libpciaccess-0.13.1.tar.bz2

libSM-1.2.2.tar.gz

libtool-2.4.tar.gz

libX11-1.6.2.tar.gz

libxdamage_1.1.4.orig.tar.gz

libXext-1.3.2.tar.gz

libXfixes-5.0.1.tar.gz

libXi-1.7.2.tar.gz

libXmu-1.1.2.tar.gz

libXt-1.1.4.tar.gz

llvm-3.3.src.tar.gz

macros-master.tar.gz

xtrans-1.2.7.tar.bz2

以上是我遇到的依赖,还有最后一个安装glut-3.7.tar.gz遇到比较头疼的问题,make之后总是没有libglut.so, 我是安装linux目录下的README的方式去做的,可依然不行,最后就用笨方法手动创建的,链接的时候用的静态库没有用动态库,

以下是测试代码:

gcc  main.c -Bdynamic -lGL    -Bstatic  -L. -lglut  -Bstatic -L/usr/lib -lGLU   -lXmu

 

在动态库前加上-Bdynamic
在静态库前加上-Bstatic

 

 

/* light.c
   此程序利用GLUT绘制一个OpenGL窗口,并显示一个加以光照的球。
   */
/* 由于头文件glut.h中已经包含了头文件gl.h和glu.h,所以只需要include 此文件*/
#include
#include

/* 初始化材料属性、光源属性、光照模型,打开深度缓冲区 */
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);

        glEnable (GL_LIGHTING);
        glEnable (GL_LIGHT0);
        glEnable (GL_DEPTH_TEST);
}

/*调用GLUT函数,绘制一个球*/
void display ( void )
{
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glutSolidSphere (1.0, 40, 50);
        glFlush ();
}


/* 定义GLUT的reshape函数,w、h分别是当前窗口的宽和高*/
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 ( ) ;
}


/* 定义对键盘的响应函数 */
void keyboard ( unsigned char key, int x, int y)
{
        /*按Esc键退出*/
        switch (key)
        {
                case 27:

                        return ;
                        break;
        }
}


int main(int argc, char** argv)
{
        /* GLUT环境初始化*/
        glutInit (&argc, argv);
        /* 显示模式初始化 */
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
        /* 定义窗口大小 */
        glutInitWindowSize (300, 300);
        /* 定义窗口位置 */
        glutInitWindowPosition (100, 100);
        /* 显示窗口,窗口标题为执行函数名 */
        glutCreateWindow ( argv [ 0 ] );
        /* 调用OpenGL初始化函数 */
        init ( );
        /* 注册OpenGL绘图函数 */
        glutDisplayFunc ( display );
        /* 注册窗口大小改变时的响应函数 */
        glutReshapeFunc ( reshape );
        /* 注册键盘响应函数 */
        glutKeyboardFunc ( keyboard );
        /* 进入GLUT消息循环,开始执行程序 */
        glutMainLoop( );
        return 0;
}


~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
~                      

 

你可能感兴趣的:(视频)