OpenGL programming based on MFC Part 4 Drawing Simple 3D objects

Source: Internet
Author: User
Tags bool

Sight Body

Viewing Volume is nothing but the region of 3D Cartesian spaces in that'll occupy the window. It is nothing but the minimum and maximum x, Y and Z values that are inside the window. So if a vertex are outside this range of x, Y and Z values then they are clipped by OpenGL before rendering can occur.

Z Buffer

The new term we have to deal with in addition to width and height of the ' an object ' in 3D graphics is depth. The depth of an object was its distance from the viewpoint. The viewpoint is the location from which we are looking at this point. This is depth value goes into the depth or z-buffer. If we are drawing 2 objects that have some pixels that overlap, the ' I ' after it's rendered have its depth value in the depth buffer. When the next object is rendered, OpenGL'll check to whether the pixel it's about to draw are in front of (with Respe CT to the "viewpoint" any pixel from the already drawn. It does this by checking the "Z" value of the "current pixel" with the "value" is already in the buffer. If the new pixel is closer to the viewpoint, OpenGL places it depth value in the depth buffer. This is how the Z-buffer works.

Orthogonal projection and perspective projection

One term we need to understand very down to learn 3D Graphics-is projection. So, computer graphics at its simplest are all about setting a color to a pixel on screen. And a pixel on a screens can have only two dimensions. So 3D graphics are merely an illusion. The 3D coordinates that we specify'll have to is projected onto a 2D surface to create this illusion for us. And we have to specify how this projection works. By specifying a projection we specify the clipping or viewing volume.

Basic 3D Graphics Drawing

1, add the following variables to the CCY457OpenGLView.h

BOOL m_bPoint;    //Status of Point
BOOL m_bLine;    //Status of Line
BOOL m_bPolygon;  //Status of Polygon
BOOL m_bTriangle;  //Status of Triangle

and initialized in the constructor.

CCY457OpenGLView::CCY457OpenGLView()
{
  m_bPoint  = FALSE;
  m_bLine    = FALSE;
  m_bPolygon  = FALSE;
  m_bTriangle = FALSE;
  m_bCube      = FALSE;
  m_bTorus    = FALSE;
  m_bTeapot    = FALSE;
  m_bIcosahedron = FALSE;
  m_bSimpleCube = FALSE;
}

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

void Ccy457openglview::onobjectsteapot ()
{//Draw a teapot
M_bcube = FALSE;
M_btorus = FALSE;
M_bteapot = TRUE;
M_bicosahedron = FALSE;
M_bsimplecube = FALSE;
InvalidateRect (Null,false);
}
void Ccy457openglview::onobjectscube ()
{//Draw cubes
M_bcube = TRUE;
M_btorus = FALSE;
M_bteapot = FALSE;
M_bicosahedron = FALSE;
M_bsimplecube = FALSE;
InvalidateRect (Null,false);
}
void Ccy457openglview::onobjectsicosahedron ()
{//Draw 20 face body
M_bcube = FALSE;
M_btorus = FALSE;
M_bteapot = FALSE;
M_bicosahedron = TRUE;
M_bsimplecube = FALSE;
InvalidateRect (Null,false);
}
void Ccy457openglview::onobjectstorus ()
{//Picture ring surface
M_bcube = FALSE;
M_btorus = TRUE;
M_bteapot = FALSE;
M_bicosahedron = FALSE;
M_bsimplecube = FALSE;
InvalidateRect (Null,false);
}

void Ccy457openglview::onobjectssimplecube ()
{//Draw a simple cube
M_bcube = FALSE;
M_btorus = FALSE;
M_bteapot = FALSE;
M_bicosahedron = FALSE;
M_bsimplecube = 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.