1、本文所以内容来自 著名高校课件和学生笔记(校园里面经常见到有人高价买笔记)
2、任课教师不会提供参考文献,所以只能对作者表示感谢,如果引用了您的作品,可以用回复方式补充参考文献。
3、我不对文章无关问题进行解答,文章内容也比较难,我也很难解答您遇到的问题,如果发现BUG可以用回复方式帮我修正。
4、本课 属于Computer Graphics
,适用于计算机图形学课程,教材为电子工业出版社Computer Graphics(计算机图形学,中文版和英文版)
本课其他部分的导航条见页面底部
Chapter 4
Attributes of Graphics Primitives
State System and State Variables
A graphics system that maintain a list for the current values of attributes and parameters is called state system, or state machine.
Attributes of output primitives and some other parameters are called state variables or state parameters.
§4.1 OpenGL State Variables
OpenGL State Variables include:
Color and other primitives attributes
The current matrix mode
The elements of the model-view matrix
The current position for the frame buffer
The parameters for the lighting effects
Etc.
§4.2 Color and Grayscale
RGB color components
R, G, B components are mixed to display a particular color
Described with float numbers, the components ranged from 0.0 to 1.0
Described with integers, the components ranged from 0 to 255
Grayscale: only lighteness, without color
Described with float numbers, the lighteness ranged from 0.0 to 1.0
Described with integers, the lighteness ranged from 0 to 255
§4.3 OpenGL Color Functions
Set the color display mode:
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA);
Select the current color:
glColor3f (0.0, 1.0, 1.0);
glColor3i (255, 255, 0);
glColor3fv (colorArray);
RGBA Color Model
In RGBA color model, A is alpha coefficient.
The alpha coefficient controls color blending(颜色调和) for overlapping primitives.
Color blending is used in the simulation of transparency(透明) .
OpenGL Color Blending
To enable and disable color blending:
glEnable (GL_BLEND);
glDisable (GL_BLEND);
§4.4 Point Attributes in OpenGL
In OpenGL, a point has two attributes:
Size and color
To set the size of a point in OpenGL:
glPointSize(size);
To set the color of a point in OpenGL:
glColor3f (1.0, 0.0, 0.0);
glBegin (GL_POINTS);
glVertex2i (50,100);
glPointSize (2.0);
glEnd ( );
§4.5 Line Attributes in OpenGL
In OpenGL, a line has three attributes in general:
Width, style and color
To set the width of a line in OpenGL:
glLineWidth(width);
To set the color of a line in OpenGL, like to set the color of other primitives.
glColor3f (1.0, 0.0, 0.0);
glBegin (GL_LINES);
glVertex2iv (p1);
……
glEnd ( );
To Set Line-Style in OpenGL
To enable and disable line-style function:
glEnable (GL_LINE_STIPPLE);
glDisable (GL_LINE_STIPPLE);
To set the line-style:
glLineStipple (repeatFactor, pattern);
pattern is a 16-bit integer to describe the line-style:
§4.6 Curve Attributes
Parameters of curve attributes are the same as those for straight-line segments.
§4.9 Fill-Area Attributes
Scan-line approach:
Usually used in simple shapes
General graphics packages use this method
Use a starting interior point:
Usually used in complex shapes or interactive systems
Fill Styles
A basic fill-area attribute provided by a general graphics library is the display style of the interior.
We can display a region with
a hollow style
a single color
a specified fill pattern
§4.14 OpenGL Fill-Area Functions
We generate displays of filled convex polygons(凸多边形) in 4 steps:
Define a fill pattern;
Invoke the polygon-fill routine;
Activate the polygon-fill feature of OpenGL;
Describe the polygons to be filled.
GLubyte fillPattern []= {0xff, 0x00, ……};
glPolygonStripple (fillPattern);
glEnable(GL_POLYGON_STIPPLE);
OpenGL Interpolation(插值) Patterns
glShapeModel(GL_SMOOTH);
// GL_SMOOTH means smooth transition(过渡) effect
glBegin(GL_TRANGLES)
glColor(1.0, 0.0, 0.0);
glVertex2i(50,50);
glColor(0.0, 0.0, 1.0);
glVertex2i(0, 0);
glVertex2i(75, 0);
glEnd();
OpenGL Wire-Frame Methods
When the edges and interior area of a same polygon have different colors, we can:
glPolygonModel(GL_FRONT, GL_FILL);
glColor3f(1.0, 0.0, 0.0);
// Invoke polygon-generating routines
glPolygonModel(GL_FRONT, GL_LINE);
glColor3f(0.0, 1.0, 0.0);
// Invoke polygon-generating routines
§4.17 Anti-aliasing (反走样)
Graphics primitives have a jagged(锯齿状) appearance because of the low-frequent sampling(低频采样).
This is called aliasing (走样).
Methods that can eliminate aliasing is called anti-aliasing (反走样).
One is super-sample(过采样).
§4.18 OpenGL Anti-aliasing (反走样) Functions
glEnable (primitiveType);
// primitiveType can be GL_POINT_SMOOTH,
// GL_LINE_SMOOTH, GL_POLYGON_SMOOTH
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Color blending
§4.19 OpenGL Query Functions
Using OpenGL Query Functions, we can get current values for any state parameters.
glGet functions:
Each function needs two parameters:
glGetBooleanv(...);
glGetFloatv(...);
glGetIntegerv(...);
glGetFloatv(GL_CURRENT_COLOR, colorValues);
// The first parameter means what to be queried;
// The second parameter store the queried result.