ubuntu下安裝OpenGL

來源:互聯網
上載者:User

之前我去http://mesa3d.sourceforge.net/下載來安裝,./configure都不會過,沒有找到原因,在網上搜尋了一下,在UBUNTU上有直接安裝的,先試試跑跑效果!

sudo apt-get install mesa-common-dev mesademos libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev

我是在新得利裡面把上面那些一個個找出來裝的,效果一樣的,然後
建立個檔案sample.cpp/**//* light.c
 此程式利用GLUT繪製一個OpenGL視窗,並顯示一個加以光照的球。
 */
 /**//* 由於標頭檔glut.h中已經包含了標頭檔gl.h和glu.h,所以只需要include 此檔案*/
 # 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;
 }

然後 
g++ sample.cpp -o sample -lglut
./sample

沒錯的話就ok 啦

本文轉自:http://blog.csdn.net/nauty_li/article/details/2217625

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.