OpenGL programming based on MFC Part 3 Drawing simple 2D Shapes

Source: Internet
Author: User

Trim area

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

View Port

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

Vertices and basic entities

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

Basic Graphics Drawing Program

1, add the following variables to the CCY457OpenGLView.h:

2, and add four menu items and their corresponding event handlers.

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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.