Download presentation
Presentation is loading. Please wait.
1
第四章 图元的属性 曾智勇 软件学院
2
颜色和灰度 OpenGL几何图元和属性 Point Line polygon Character Antialiasing Glut函数
3
颜色和灰度 颜色空间: RGB HSV HLS Lab
4
灰度:当RGB函数中指定相同量的红色,绿色和蓝色时,结果是某种程度的灰色.
5
其它的颜色参数 强度(Intensity) :物理学术语,用来量化一个时间段中在特定方向的光能辐射.
光亮度( Luminance ): 心理学术语,用来描述感觉光亮的特征.
6
颜色存储 RGB Index (color lookup table ;color map)
7
OpenGL颜色函数 设定颜色显示模型 glutInitDisplayMode(modeparameters);
帧缓存模式: GLUT_SINGLE ,GLUT_DOUBLE 颜色模式: GLUT_RGB(defualt), GLUT_RGBA , GLUT_INDEX
8
指定当前颜色分量 glColor*(colorcomponents); glColor3f(0.0,1.0,0.0);
glColor3fv(colorArray); glColor3i(0,255,255); glIndex(colorIndex);
9
Set_current_color(red);
Draw_object(A); Draw_object(B); Set_current_color(blue); Set_current_color(green); Draw_object(c)
10
显示窗口RGB颜色分量的设置 显示场景的当前刷新缓存的设置 glClearColor(red,green,blue,alpha);
glClear(buffer-name); GL_COLOR_BUFFER_BIT;GL_DPTH_BUFFER_BIT;GL_ACCUM_BUFFER_BIT;GL_STENCIL_BUFFER_BIT
11
图元的绘制 在函数glBegin()和glEnd()之间是顶点函数的集合.glBegin()的参数决定了顶点构造的图元的种类.
12
顶点 glVertex{234}{sifd}[v](DataType coords);
13
点 glBegin(GL_POINTS); glVertex*(point-coordinate); …. glEnd();
14
属性: Color Size glPointSize(GLfloat size-float);
15
线 GL_LINES GL_LINE_STRIP GL_LINE_LOOP
16
线 p1 p3 glBegin(GL_LINES); glVertex*(point1-coordinate);
glEnd();
17
p1 p3 p2 p4 glBegin(GL_LINE_STRIP); glVertex*(point1-coordinate); glVertex*(point2-coordinate); glVertex*(point3-coordinate); glVertex*(point4-coordinate); glVertex*(point5-coordinate); glEnd(); p5
18
p1 p3 p2 p4 glBegin(GL_LINE_LOOP); glVertex*(point1-coordinate); glVertex*(point2-coordinate); glVertex*(point3-coordinate); glVertex*(point4-coordinate); glVertex*(point5-coordinate); glEnd(); p5
19
属性 Color Width style
20
Width glLineWidth(GLfloat width); style glLineStripple(Glint repeatFactor,GLushort pattern); 参数 pattern是一个描述如何显示线段的一个16位整数,值为1的位对应一个“开”象素,值为0的位对应一个“关”象素.改模式从低位开始应用于线路径,默认模式为0xFFFF(每一位的值为1 ),它生成实线.整数参数repeatFactor说明模式中每一位重复应用多少次才轮到下一位.默认的重复值是1. glEnable(GL_LINE_STIPPLE); glDisable(GL_LINE_STIPPLE);
21
Dotted: 0x Dashed: 0x00FF 1 Dash/dot/dash: 0x1C47 1
22
多边形 多边形的限制 多边形的边不能相交. OpenGL多边形必须是凸多边形.
23
glBegin(GL_POLYGON);
glVertex2i(180,15); glVertex2i(10,145); glVertex2i(100,145); glVertex2i(10,15); glEnd(); glBegin(GL_POLYGON); glVertex2i(180,15); glVertex2i(10,145); glVertex2i(180,145); glVertex2i(170,140); glEnd();
24
多边形的绘制 填充 实填充 某种样式填充. 轮廓线 顶点上的点
25
设置前向面 glFrontFace(GLenum mode);
如果mode的值是GL_CCW, 窗口坐标系投影多边形的顶点顺序是逆时针方向. 如果mode的值为GL_CW,窗口坐标系投影多边形的顶点顺序是顺时针方向.
26
设置多边形模式 glPolygonMode(GLenum face, GLenum mode); 控制多边形前向面或后向面的绘制方式.
参数face的值可为:GL_FRONT_AND_BACK, GL_FRONT, 或GL_BACK; 参数mode 可以取GL_POINT, GL_LINE, GL_FILL 以表示多边形被绘制的样式.
27
glBegin(GL_POLYGON); glVertex2i(150,15); glVertex2i(180,50);
glPolygonMode(GL_FRONT,GL_POINT); glPointSize(5); glBegin(GL_POLYGON); glVertex2i(150,15); glVertex2i(180,50); glVertex2i(150,100); glVertex2i(100,100); glVertex2i(50,50); glVertex2i(100,15); glEnd();
28
glPolygonMode(GL_FRONT,GL_LINE);
glBegin(GL_POLYGON); glVertex2i(150,15); glVertex2i(180,50); glVertex2i(150,100); glVertex2i(100,100); glVertex2i(50,50); glVertex2i(100,15); glEnd();
29
//glPolygonMode(GL_FRONT,GL_FILL);
glBegin(GL_POLYGON); glVertex2i(150,15); glVertex2i(180,50); glVertex2i(150,100); glVertex2i(100,100); glVertex2i(50,50); glVertex2i(100,15); glEnd();
30
设置多边形的填充图案 glPolygonStipple(const GLubyte *mask);
- glEnable(GL_POLYGON_STIPPLE); - glDisable(GL_POLYGON_STIPPLE);
31
字符 glutBitmapCharacter(font,character);
glutStrokeCharacter(font,character);
32
反走样 glEnable(PrimitiveType); PrimitiveType: GL_POINT_SMOOTH
GL_LINE_SMOOTH GL_POLYGON_SMOOTH
33
Glut函数 glutDisplayFunc(void (*func)(void))
glutReshapeFunc(void(*func)(int w,int h)) glutKeyboardFunc(void(*func)(unsigned char key,int x,int y)) glutMouseFunc(void(*func)(int button,int state,int x,int y))
Similar presentations