真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

glMaterialfv材質(zhì)設置用例

說明

創(chuàng)新互聯(lián)公司服務項目包括桐梓網(wǎng)站建設、桐梓網(wǎng)站制作、桐梓網(wǎng)頁制作以及桐梓網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯(lián)網(wǎng)行業(yè)的解決方案,桐梓網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到桐梓省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!

如果非常清楚的知道物體的材質(zhì),并且能夠在OpenGL的材質(zhì)表中找到合乎要求的參數(shù)設置,就可以避免指定物體的顏色值,某些情況下,指定物體的渲染顏色,使得物體的實際效果大打折扣

  {

    glPushMatrix();

    glTranslatef(1.0, 0.0, 0.0);

    //黃銅

    GLfloat mat_ambient[] = { 0.021500, 0.174500, 0.021500, 0.550000};

    GLfloat mat_diffuse[] = { 0.075680, 0.614240, 0.075680, 0.550000};

    GLfloat mat_specular[] = { 0.633000, 0.727811, 0.633000, 0.550000 };

    GLfloat mat_shininess[] = { 76.800003}; //材質(zhì)RGBA鏡面指數(shù),數(shù)值在0~128范圍內(nèi)

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);

    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    glutSolidSphere (1.0, 40, 50);    //半徑為 1,40 條緯線,50 條經(jīng)線

    glPopMatrix();

    glFlush (); 

  }

  {

    glPushMatrix();

    glTranslatef(-1.0, 0.0, 0.0);

    //翡翠綠

    GLfloat mat_ambient[] = {  0.247250, 0.199500, 0.074500, 1.000000};

    GLfloat mat_diffuse[] = { 0.751640, 0.606480, 0.226480, 1.000000};

    GLfloat mat_specular[] = { 0.628281, 0.555802, 0.366065, 1.000000 };

    GLfloat mat_shininess[] = { 51.200001}; //材質(zhì)RGBA鏡面指數(shù),數(shù)值在0~128范圍內(nèi)

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);

    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    glutSolidSphere (1.0, 40, 50);    //半徑為 1,40 條緯線,50 條經(jīng)線

    glPopMatrix();

  }

材質(zhì)表

//黃銅

    0.329412, 0.223529, 0.027451, 1.000000,

    0.780392, 0.568627, 0.113725, 1.000000,

    0.992157, 0.941176, 0.807843, 1.000000,

    27.897400,

 

    //青銅

    0.212500, 0.127500, 0.054000, 1.000000,

    0.714000, 0.428400, 0.181440, 1.000000,

    0.393548, 0.271906, 0.166721, 1.000000,

    25.600000,

 

    //亮青銅

    0.250000, 0.148000, 0.064750, 1.000000,

    0.400000, 0.236800, 0.103600, 1.000000,

    0.774597, 0.458561, 0.200621, 1.000000,

    76.800003,

 

    //鉻

    0.250000, 0.250000, 0.250000, 1.000000,

    0.400000, 0.400000, 0.400000, 1.000000,

    0.774597, 0.774597, 0.774597, 1.000000,

    76.800003,

 

//銅

    0.191250, 0.073500, 0.022500, 1.000000,

    0.703800, 0.270480, 0.082800, 1.000000,

    0.256777, 0.137622, 0.086014, 1.000000,

    12.800000,

 

 

//亮銅

    0.229500, 0.088250, 0.027500, 1.000000,

    0.550800, 0.211800, 0.066000, 1.000000,

    0.580594, 0.223257, 0.069570, 1.000000,

    51.200001,

 

//金

    0.247250, 0.199500, 0.074500, 1.000000,

    0.751640, 0.606480, 0.226480, 1.000000,

    0.628281, 0.555802, 0.366065, 1.000000,

    51.200001,

 

//亮金

    0.247250, 0.224500, 0.064500, 1.000000,

    0.346150, 0.314300, 0.090300, 1.000000,

    0.797357, 0.723991, 0.208006, 1.000000,

    83.199997,

 

//白蠟

    0.105882, 0.058824, 0.113725, 1.000000,

    0.427451, 0.470588, 0.541176, 1.000000,

    0.333333, 0.333333, 0.521569, 1.000000,

    9.846150,

 

//銀

    0.192250, 0.192250, 0.192250, 1.000000,

    0.507540, 0.507540, 0.507540, 1.000000,

    0.508273, 0.508273, 0.508273, 1.000000,

    51.200001,

 

//亮銀色

    0.231250, 0.231250, 0.231250, 1.000000,

    0.277500, 0.277500, 0.277500, 1.000000,

    0.773911, 0.773911, 0.773911, 1.000000,

    89.599998,

 

//翡翠、祖母綠

    0.021500, 0.174500, 0.021500, 0.550000,

    0.075680, 0.614240, 0.075680, 0.550000,

    0.633000, 0.727811, 0.633000, 0.550000,

    76.800003,

 

//碧玉

    0.135000, 0.222500, 0.157500, 0.950000,

    0.540000, 0.890000, 0.630000, 0.950000,

    0.316228, 0.316228, 0.316228, 0.950000,

    12.800000,

 

//黑曜石

    0.053750, 0.050000, 0.066250, 0.820000,

    0.182750, 0.170000, 0.225250, 0.820000,

    0.332741, 0.328634, 0.346435, 0.820000,

    38.400002,

 

//珍珠

    0.250000, 0.207250, 0.207250, 0.922000,

    1.000000, 0.829000, 0.829000, 0.922000,

    0.296648, 0.296648, 0.296648, 0.922000,

    11.264000,

 

//紅寶石

    0.174500, 0.011750, 0.011750, 0.550000,

    0.614240, 0.041360, 0.041360, 0.550000,

    0.727811, 0.626959, 0.626959, 0.550000,

    76.800003,

 

//綠寶石、綠松石

    0.100000, 0.187250, 0.174500, 0.800000,

    0.396000, 0.741510, 0.691020, 0.800000,

    0.297254, 0.308290, 0.306678, 0.800000,

    12.800000,

 

//黑塑料

    0.000000, 0.000000, 0.000000, 1.000000,

    0.010000, 0.010000, 0.010000, 1.000000,

    0.500000, 0.500000, 0.500000, 1.000000,

    32.000000,

 

 

//黑橡膠

    0.020000, 0.020000, 0.020000, 1.000000,

    0.010000, 0.010000, 0.010000, 1.000000,

    0.400000, 0.400000, 0.400000, 1.000000,

    10.000000,

 

//紫羅蘭

    0.110000, 0.060000, 0.090000, 1.000000,

    0.430000, 0.470000, 0.540000, 1.000000,

    0.330000, 0.330000, 0.520000, 1.000000,

    22.000000

代碼

# include < GL/glut.h > 

/* 初始化材料屬性、光源屬性、光照模型,打開深度緩沖區(qū)等 */ 

void init(void) 

  GLfloat light_position [ ] = { 0., 1.5, 1.5, 0.0 }; 

  glClearColor ( 0.0, 0.0, 1.0, 0.0 ); //設置背景色為藍色

  glShadeModel ( GL_SMOOTH ); 

  glLightfv ( GL_LIGHT0, GL_POSITION, light_position); 

  glEnable (GL_LIGHTING); 

  glEnable (GL_LIGHT0); 

  glEnable (GL_DEPTH_TEST); 

/*調(diào)用 GLUT 函數(shù),繪制一個球*/ 

void display ( void ) 

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

  {

    glPushMatrix();

    glTranslatef(1.0, 0.0, 0.0);

    GLfloat mat_ambient[] = { 0.021500, 0.174500, 0.021500, 0.550000};

    GLfloat mat_diffuse[] = { 0.075680, 0.614240, 0.075680, 0.550000};

    GLfloat mat_specular[] = { 0.633000, 0.727811, 0.633000, 0.550000 };

    GLfloat mat_shininess[] = { 76.800003}; //材質(zhì)RGBA鏡面指數(shù),數(shù)值在0~128范圍內(nèi)

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);

    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    glutSolidSphere (1.0, 40, 50);    //半徑為 1,40 條緯線,50 條經(jīng)線

    glPopMatrix();

    glFlush (); 

  }

  {

    glPushMatrix();

    glTranslatef(-1.0, 0.0, 0.0);

    GLfloat mat_ambient[] = {  0.247250, 0.199500, 0.074500, 1.000000};

    GLfloat mat_diffuse[] = { 0.751640, 0.606480, 0.226480, 1.000000};

    GLfloat mat_specular[] = { 0.628281, 0.555802, 0.366065, 1.000000 };

    GLfloat mat_shininess[] = { 51.200001}; //材質(zhì)RGBA鏡面指數(shù),數(shù)值在0~128范圍內(nèi)

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);

    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    glutSolidSphere (1.0, 40, 50);    //半徑為 1,40 條緯線,50 條經(jīng)線

    glPopMatrix();

  }

  glFlush (); 

/* 定義 GLUT 的 reshape 函數(shù),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 ); //創(chuàng)建平行視景體

  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 ( ) ; 

int main(int argc, char** argv) 

  glutInit (&argc, argv);     // GLUT 環(huán)境初始化

  glutInitDisplayMode (GLUT_SINGLE |GLUT_RGB |GLUT_DEPTH); // 顯示模式初始化

  glutInitWindowSize (300, 300);       // 定義窗口大小

  glutInitWindowPosition (100, 100);   // 定義窗口位置  

  glutCreateWindow ( argv [ 0 ] );   // 顯示窗口,窗口標題為執(zhí)行函數(shù)名

  init( );

  glutDisplayFunc ( display ); // 注冊 OpenGL 繪圖函數(shù)(一種特殊的調(diào)用方式,下同) 

  glutReshapeFunc ( reshape );   // 注冊窗口大小改變時的響應函數(shù)

  glutMainLoop( );      // 進入 GLUT 消息循環(huán),開始執(zhí)行程序

  return 0; 

注意

    值得一提的是glutSolidSphere 必須在指定變換矩陣和設置好材料屬性之后,才應該被調(diào)用,否則在設置各種屬性之前調(diào)用glutSolidSphere ,會出現(xiàn)其他的異常

例如

  {

    glPushMatrix();

    glTranslatef(1.0, 0.0, 0.0);

    glutSolidSphere (1.0, 40, 50);    //半徑為 1,40 條緯線,50 條經(jīng)線

    GLfloat mat_ambient[] = { 0.021500, 0.174500, 0.021500, 0.550000};

    GLfloat mat_diffuse[] = { 0.075680, 0.614240, 0.075680, 0.550000};

    GLfloat mat_specular[] = { 0.633000, 0.727811, 0.633000, 0.550000 };

    GLfloat mat_shininess[] = { 76.800003}; //材質(zhì)RGBA鏡面指數(shù),數(shù)值在0~128范圍內(nèi)

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);

    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    glPopMatrix();

    glFlush (); 

  }

  {

    glPushMatrix();

    glTranslatef(-1.0, 0.0, 0.0);

    glutSolidSphere (1.0, 40, 50);    //半徑為 1,40 條緯線,50 條經(jīng)線

    GLfloat mat_ambient[] = {  0.247250, 0.199500, 0.074500, 1.000000};

    GLfloat mat_diffuse[] = { 0.751640, 0.606480, 0.226480, 1.000000};

    GLfloat mat_specular[] = { 0.628281, 0.555802, 0.366065, 1.000000 };

    GLfloat mat_shininess[] = { 51.200001}; //材質(zhì)RGBA鏡面指數(shù),數(shù)值在0~128范圍內(nèi)

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);

    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    glPopMatrix();

  }

左右兩個球的顏色剛好換掉


當前題目:glMaterialfv材質(zhì)設置用例
文章起源:http://weahome.cn/article/jseiod.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部