[原]OpenGL基础教程(一)多边形绘制

1、opengl开发环境搭建 参考http://brothergrup.iteye.com/blog/1602471

2、为三角形填充颜色:

填充颜色函数为glColor(3/4)*(r,g,b)  3或4 表示 rgb/rgba;* 表示rgba的数值类型(b,i..) 最终都会被映射到[0-1].

如何映射的呢 就是拿写的值/当前类型最大值 比如byte是-128~127 glColor3b(1,0,0) 等价于 glColor3f(1/127f,0,0)  小于0的 就当0处理

void renderScene(void)  

  ........

  //每个顶点赋值成红色
    glVertex3f(-0.5,-0.5,0.0);  
    glColor3b(127,0,0);

    glVertex3f(0.5,0.0,0.0);  
    glColor3b(127,0,0);

    glVertex3f(0.0,0.5,0.0);
    glColor3b(127,0,0);
    ..........

3、绘制四边形

注意 选择四边形模式时 四个顶点按照顺序来画,顺时针或者逆时针。

void renderScene(void)  

 glBegin(GL_QUADS);  //四边形模式绘制

    glVertex3f(-0.5,-0.5,0.0);  
    glColor3f(1.0,0,0);

    glVertex3f(0.5,-0.5,0.0);  
    glColor3f(1.0,0,0);

    glVertex3f(0.5,0.5,0.0);
    glColor3f(1.0,0,0);

    glVertex3f(-0.5,0.5,0.0);
    glColor3f(1.0,0,0);

    glEnd(); 

假如颠倒3,4顶点的次序 ,发生混乱 如图:

(2)绘制模式为三角形时 绘制四边形

下一篇讲述 使用索引方式绘制多边形

posted @ 2014-12-16 23:36  U_探索  阅读(1013)  评论(0编辑  收藏  举报