OpenGL programming based on MFC Part 8 Colors

Source: Internet
Author: User

OpenGL supports two color modes: RGBA and color indexing mode, this article focuses on the former.

Smooth Shading and Flat shading

When Smooth shading is specified, the color values are interpolated between. If Flat Shading is specified, one vertex is selected as being to all representative, vertices the thus entire E is displayed using a single color.

A simple Demo

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

Glfloat M_xrot, m_yrot;//the angle of rotation around the x,y axis, changing over time

and initialize it in the constructor:

CCY457OpenGLView::CCY457OpenGLView()
{
  m_xRot = 0.0f;
  m_yRot = 0.0f;
}

2, in the OnTimer function, modify the angle value of the rotation around the x,y axis

void CCY457OpenGLView::OnTimer(UINT nIDEvent)
{
  m_xRot = m_xRot + 0.5f;
  m_yRot = m_yRot + 0.5f;
  InvalidateRect(NULL, FALSE);
  CView::OnTimer(nIDEvent);
}

3, add two menu items to control the rendering mode of OpenGL

void CCY457OpenGLView::OnShadingmodelSmooth()
{
  glShadeModel(GL_SMOOTH);
  InvalidateRect(NULL,FALSE);
}

void CCY457OpenGLView::OnShadingmodelFlat()
{
  glShadeModel(GL_FLAT);
  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.