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