Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14519598
  • 博文数量: 5645
  • 博客积分: 9880
  • 博客等级: 中将
  • 技术积分: 68081
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-28 13:35
文章分类

全部博文(5645)

文章存档

2008年(5645)

我的朋友

分类:

2008-04-28 21:29:48

下载本文示例代码
  友情推荐:编程教程专区   通过上一节的例子我们已经知道一些简单的使用颜色的方法。这一节我们进一步讲讲颜色的使用。  例2:本例子使用颜色引索模式绘制8个不同颜色的球体,如图二所示。阅读此例时,请主要关注函数palette和DrawColotFans。glIndex设置当前颜色索引。参数为当前颜色索引。本例中glIndexd 函数的参数j 1对应palette中auxSetOneColor函数中的i 1,auxSetOneColor函数的后三个函数制定对应的颜色,颜色值由变量rgb[8][3]定义。 #include #include void init(void){ glClearColor(1.0,1.0,1.0,1.0); glClear(GL_COLOR_BUFFER_BIT); glShadeModel(GL_SMOOTH);}void palette(void){ GLint i; static GLfloat rgb[8][3]={{1,0,0},{1,0,0.5},{1,0,1},{0,0,1},{0,1,1},{0,1,0},{1,1,0},{1,0.5,0}}; for(i = 0;i<8;i ) {  auxSetOneColor(i 1,rgb[i][0],rgb[i][1],rgb[i][2]);//设置颜色 }}void DrawColorFans(void){ GLint j; glTranslatef(-15,-15,0); for(j = 0;j<8;j ) {  glIndexd(j 1);//设置当前颜色索引  /*在不同位置绘制球体*/  glTranslatef(j,j-1,0);  glutSolidSphere(1,20,20); }}void CALLBACK display(void){ palette(); DrawColorFans(); glFlush();}void CALLBACK reshape(GLsizei w,GLsizei h){ glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(100,1,1,20); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0,0,-15);}void main(){ auxInitDisplayMode(AUX_SINGLE|AUX_INDEX); auxInitPosition(100,100,500,500); auxInitWindow("draw the color sphere"); init(); auxReshapeFunc(reshape); auxMainLoop(display);} 图二:8个不同颜色的球体   友情推荐:编程教程专区   通过上一节的例子我们已经知道一些简单的使用颜色的方法。这一节我们进一步讲讲颜色的使用。  例2:本例子使用颜色引索模式绘制8个不同颜色的球体,如图二所示。阅读此例时,请主要关注函数palette和DrawColotFans。glIndex设置当前颜色索引。参数为当前颜色索引。本例中glIndexd 函数的参数j 1对应palette中auxSetOneColor函数中的i 1,auxSetOneColor函数的后三个函数制定对应的颜色,颜色值由变量rgb[8][3]定义。 #include #include void init(void){ glClearColor(1.0,1.0,1.0,1.0); glClear(GL_COLOR_BUFFER_BIT); glShadeModel(GL_SMOOTH);}void palette(void){ GLint i; static GLfloat rgb[8][3]={{1,0,0},{1,0,0.5},{1,0,1},{0,0,1},{0,1,1},{0,1,0},{1,1,0},{1,0.5,0}}; for(i = 0;i<8;i ) {  auxSetOneColor(i 1,rgb[i][0],rgb[i][1],rgb[i][2]);//设置颜色 }}void DrawColorFans(void){ GLint j; glTranslatef(-15,-15,0); for(j = 0;j<8;j ) {  glIndexd(j 1);//设置当前颜色索引  /*在不同位置绘制球体*/  glTranslatef(j,j-1,0);  glutSolidSphere(1,20,20); }}void CALLBACK display(void){ palette(); DrawColorFans(); glFlush();}void CALLBACK reshape(GLsizei w,GLsizei h){ glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(100,1,1,20); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0,0,-15);}void main(){ auxInitDisplayMode(AUX_SINGLE|AUX_INDEX); auxInitPosition(100,100,500,500); auxInitWindow("draw the color sphere"); init(); auxReshapeFunc(reshape); auxMainLoop(display);} 图二:8个不同颜色的球体 下载本文示例代码


OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色OpenGL编程轻松入门之使用颜色
阅读(127) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~