1、本文所以内容来自 著名高校课件和学生笔记(校园里面经常见到有人高价买笔记)
2、任课教师不会提供参考文献,所以只能对作者表示感谢,如果引用了您的作品,可以用回复方式补充参考文献。
3、我不对文章无关问题进行解答,文章内容也比较难,我也很难解答您遇到的问题,如果发现BUG可以用回复方式帮我修正。
4、本课 属于Computer Graphics
,适用于计算机图形学课程,教材为电子工业出版社Computer Graphics(计算机图形学,中文版和英文版)
本课其他部分的导航条见页面底部
Chapter 6 2D Viewing
2D Viewing Pipeline
The mapping of a 2D, world-coordinate scene description to device coordinate is called a 2D viewing transformation .
Sometimes this transformation is simplified as the window-to-viewport transformation.
§6.2 The Clipping Window
We could define our clipping window with any shape, size and direction.
But graphics library commonly allow rectangle clipping windows aligned with the x and y axes.
Rectangular clipping windows in standard positions are easily defined by giving the coordinates of two opposite corners.
Viewing-Coordinate Clipping Window
When the clipping window is any rectangle in world coordinate, we use Translation and Rotate transformation to convert it.
§6.3 Normalization and View-Port Transformations
We first consider a view-port defined with normalized coordinate values between 0 and 1.
§6.4 OpenGL 2D Viewing Functions
Actually the basic OpenGL library has no functions specifically for 2D viewing.
But we can adapt the 3D viewing routines to a 2D scene.
In addiction, the GLU library does provide a 2D function for specifying the clipping window, and we have GLUT function for handling display windows.
OpenGL Projection Mode(投影模式)
For 2D viewing, we first select the projection mode.
glMatrixMode (GL_PROJECTION);
// designate the projection matrix as the current matrix
If we are going to loop back through this statement for other views of a scene, we can also set the initialization as:
glLoadIndentity ( );
// designate the identity as the current matrix
GLU Clipping-Window Function
To define a 2D clipping window,
gluOrtho2D (Xwmin, Xwmax, Ywmin, Ywmax);
The parameters are double numbers.
If this function is not invoked, the default coordinates are:
OpenGL View-Port Function
We specify the view-port parameters with the OpenGL function:
glViewport (Xvmin, Yvmin, vpWidth, vpHeight);
Where all parameters values are given in integer screen coordinates relative to the display window.
If this function is not invoked, the default viewport size and position are the same as the size and position of the display window.
Get View-Port Parameters
Multiple view-ports can be created in OpenGL for a variety of applications.
We can obtain the parameters for the currently active view-port:
glGetInterv ( GL_VIEWPORT, vpArray);
Where vpArray is a single-subscript, 4-element array.
This Get function returns the parameters for the current view-port to vpArray with the order Xvmin, Yvmin, vpWidth, vpHeight.
Creating a GLUT Window
glutInit (&argc, argv); // initialize GLUT
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
//single frame and RGB color mode
glutInitWindowPosition ( 50, 100);
// position of the window
glutInitWindowSize ( 400, 300); // size of the window
glutCreateWindow(“Hello");
// create the window named “Hello”
glClearColor ( Red, Green, Blue, Alpha );
// set the background color
GLUT Display-Window Identifier
Multiple display windows can be created for an application, and each is assigned a positive-integer display-window identifier, starting with 1 for the first window.
We can get its identifier with the statement:
windowID = glutCreateWindow ( “Hello” );
Once we have saved the ID of a display window, we can change the window through the ID.
Deleting a GLUT Display-Window
We can delete a display window using
glDestroyWindow ( windowID );
Current GLUT Display-Window
All display-window operations are applied to the current display window .
The current window is defaulted as the last created window.
Or we can select with:
glSetWindow ( windowID );
We can query the current window:
currentWindowID = glGetWindow ( );
Relocating and Resizing a GLUT Display-Window
glutPositionWindow ( xNewTopLeft, yNewTopLeft); // Relocating the current window
glutReshapeWindow ( dwNewWidth, dwNewHeight);
// Resizing the current window
glutReshapeFunc ( winReshapeFcn);
// Reshaping the current window when it is resized // by the interactive input
// There winReshapeFcn is a callback function
Managing Multiple GLUT Windows
glutInIconifyWindow ( );
// Convert the current window to an icon
glutSetIconTitle ( “Icon Name”); // Rename the icon
glutSetWindow ( WindowID ); glutPopWindow ( );
// put a window in front of any other windows
glutSetWindow ( WindowID ); glutPushWindow ( );
// put a window back of any other windows
glutHideWindow ( );
// take the current window off the screen
glutShowWindow ( ); // Re-display a window
GLUT Subwindows
glutCreateSubWindow ( windowID, xBottomLeft, yBottomLeft, width, height );
// where windowID identify the display window
in which we want to set up the subwindow.
we reshape, reposition, push, pop, hide and show subwindows, but we can NOT convert a subwindow to an icon.
Selecting a Display-Window Cursor
glutSelectCursor ( shape );
// where shape is a constant which identify the shape of cursor
GLUT_CURSOR_UP_DOWN: an up-down, bi-direction arrow
GLUT_CURSOR_CYCLE: a rotating arrow
GLUT_CURSOR_WAIT: a wrist watch
GLUT_CURSOR_DESTROY: a skull and crossing bones
Executing the Application Program
glutMainLoop ( );
// The last command.
// After this command, display window and their graphics contents are sent to the screen.
// The program also enters the GLUT processing loop.
Viewing Graphics Objects in a GLUT Display Window
glutDisplayFUnc ( pictureDescription );
// where pictureDescription is a callback function which describe the object
§6.5 Clipping Algorithms
Generally, any procedure that eliminates those portions of a picture that are either inside or outside of a specified region is referred to as a clipping algorithm , or simplify clipping.
Point Clipping
Line Clipping ( straight-line segments )
Fill-Area Clipping ( polygons )
Curve Clipping
Text Clipping
§6.6 2D Point Clipping
For a clipping rectangle in standard position, we save a 2D point for display if the following inequalities(不等式) are satisfied:
Point clipping can be used in particular models, such as clouds, sea foam(泡沫), smoke etc.
§6.7 2D Line Clipping
The following figure illustrates possible positions for straight-line segments in relationship to a standard clipping window:
2D Line Clipping Algorithm
A line clipping algorithm processes each line to determine whether the line or any part of it is to be saved,
through a series of test and intersection(交点) calculations.
The expensive part of a line-clipping algorithm is in calculating the intersections.
Therefore, a major goal for many line-clipping algorithm is to minimize the calculations of intersections.
2D Line Clipping Algorithm
We first test a line to determine whether it is completely inside or outside of the clipping window.
Shown in the figure, since the points and are all in the clipping widow, the line is completely inside of the window.