• ubuntu freeglut


    写一个sample.c,内容如下:
    # include <GL/glut.h>
    # include <stdlib.h>
    /**//* 初始化材料属性、光源属性、光照模型,打开深度缓冲区 */
    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:
             exit ( 0 );
             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;
    }
    然后编译运行:
    $ gcc sample.c -lglut
    $ ./a.out
    出现效果就成功了

    Ubuntu-2011-10-24-13-41-25
  • 相关阅读:
    js外观模式
    微服务架构的基础框架选择:Spring Cloud还是Dubbo?
    JAVA 中BIO,NIO,AIO的理解
    Reactor和Proactor模式的讲解(关于异步,同步,阻塞与非阻塞)
    JVM(Java虚拟机)优化大全和案例实战
    php编译安装后,加扩展模块
    mysql查所有列名
    cannot get uid for user 'www'
    rabbitmq management Login Failed
    nginx 安装过程中的not found
  • 原文地址:https://www.cnblogs.com/cute/p/2222594.html
Copyright © 2020-2023  润新知