OpenGL programming based on MFC part Reflection

Source: Internet
Author: User
Tags reflection

Reflections

Adding reflections to a too can improve it realism to a great extent. Here we'll look at a simple method to create reflection where we simply redraw the object with a appropriate Transformati On and make the surface in between translucent. This is creates an effective illusion of reflection!!

1, set the light source code to modify the following:

void Ccy457openglview::setuplighting ()
{
Material Properties
Glfloat matspecular[] = {1.0f, 0.0f, 0.0f, 0.7f};
Glfloat matshininess[] = {50.0f};
Glfloat matambient[] = {0.25f, 0.25f, 0.25f, 0.7f};
Glfloat matdiffuse[] = {0.5f, 0.5f, 0.5f, 0.7f};
GLMATERIALFV (Gl_front, Gl_specular, matspecular);
GLMATERIALFV (Gl_front, gl_shininess, matshininess);
GLMATERIALFV (Gl_front, Gl_diffuse, Matdiffuse);
GLMATERIALFV (Gl_front, gl_ambient, matambient);
Lighting Parameters
Enable Lighting
Glenable (gl_lighting);
Specify a single directional light
Glfloat ambient1[] = {0.5f,0.5f,0.5f};
Glfloat diffuse1[] = {0.5f,0.5f,0.5f};
Glfloat specular1[] = {1.0f,0.0f,0.0f};
Glfloat position1[] = {0.0f,0.0f,5.0f,0.0};
GLLIGHTFV (Gl_light0, gl_ambient, ambient1);
GLLIGHTFV (Gl_light0, Gl_diffuse, diffuse1);
GLLIGHTFV (Gl_light0, Gl_specular, specular1);
GLLIGHTFV (Gl_light0, gl_position, Position1);
Glenable (GL_LIGHT0);
Specify a single positional spotlight
Glfloat ambient2[] = {1.0f,1.0f,0.0f};
Glfloat diffuse2[] = {1.0f,0.0f,0.0f};
Glfloat position2[] = {1.0f,0.0f,5.0f,1.0};
Glfloat direction2[] = {0.0f,0.0f,-5.0f};
GLLIGHTFV (gl_light1, gl_ambient, Ambient2);
GLLIGHTFV (gl_light1, Gl_diffuse, DIFFUSE2);
GLLIGHTFV (gl_light1, gl_position, Position2);
GLLIGHTFV (gl_light1, gl_spot_direction, Direction2);
GLLIGHTF (gl_light1, Gl_spot_cutoff, 15.0f);
Glenable (GL_LIGHT1);
}

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.