Welcome

首页 / 软件开发 / VC.NET / 《基于MFC的OpenGL编程》Part 3 Drawing Simple 2D Shapes

《基于MFC的OpenGL编程》Part 3 Drawing Simple 2D Shapes2010-05-02 博客园 Phinecos(洞庭散人)剪裁区域

In OpenGL when you create a window to draw in we must specify the coordinate system we want to use and how to map the specified coordinates into physical screen coordinates. We would be using the 2D Cartesian coordinate system with the origin 0,0 at the centre of the screen. Before we can start plotting points, lines and shapes in a window we must also specify how to translate coordinate pairs into screen coordinates, by specifying the clipping area i.e the region of Cartesian space that occupies the window.

视口

The clipping area height and width will rarely match the width and height of the window in pixels. The coordinate system must therefore be mapped from logical Cartesian coordinates to physical screen coordinates. This mapping is specified by a setting known as the viewport, which is the region within the window"s client area that is used for drawing the clipping area.

顶点和基本图元

A vertex is nothing more than a coordinate in 2D or 3D space. In both 2D and 3D, when we draw an object we compose it with several smaller shapes called primitives which as 1 or 2 dimensional entities such as points, lines, and polygons. Each corner of an object composed of primitives is a vertex

基本图形绘制程序

1,在CCY457OpenGLView.h中加入下列变量:

2,并且加入四个菜单项及其对应的事件处理程序。

void CCY457OpenGLView::OnShapesPoint()
{//画点
m_bPoint = TRUE;
m_bLine = FALSE;
m_bPolygon = FALSE;
m_bTriangle = FALSE;
InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnShapesLine()
{//画线
m_bPoint = FALSE;
m_bLine = TRUE;
m_bPolygon = FALSE;
m_bTriangle = FALSE;
InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnShapesPolygon()
{//画多边形
m_bPoint = FALSE;
m_bLine = FALSE;
m_bPolygon = TRUE;
m_bTriangle = FALSE;
InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnShapesTriangle()
{//画三角形
m_bPoint = FALSE;
m_bLine = FALSE;
m_bPolygon = FALSE;
m_bTriangle = TRUE;
InvalidateRect(NULL,FALSE);
}