Main. cpp

Source: Internet
Author: User

# Include <windows. h>
# Include <Gl/Gl. h>
# Include <Gl/Glaux. h>

Void myinit (void );
Void callback display (void );
Void callback reshape (glsizei W, glsizei H );

Void myinit (void)
{
Auxinitdisplaymode (aux_double | aux_rgba );
Auxinitposition (0, 0, 500,500 );
Auxinitwindow ("sample1 ");
Glclearcolor (0.0, 0.0, 0.0, 0.0 );
Glclear (gl_color_buffer_bit );
// Glshademodel (gl_flat );

// First define a material. The definition method is similar to the light source definition mentioned above.
Glfloat mat_ambient [] = {0.8, 0.8, 0.8, 1.0 };
// Define the purple Diffuse Reflection Feature
Glfloat mat_diffuse [] = {0.8, 0.0, 0.8, 1.0 };
// Define the bright purple mirror reflection characteristics
Glfloat mat_specular [] = {1.0, 0.0, 1.0, 1.0 };
// Define the brightness of the mirror reflection
Glfloat mat_shininess [] ={ 50.0 };
// Apply the above material definition
Glmaterialfv (gl_front, gl_ambient, mat_ambient );
Glmaterialfv (gl_front, gl_diffuse, mat_diffuse );
Glmaterialfv (gl_front, gl_specular, mat_specular );
Glmaterialfv (gl_front, gl_shininess, mat_shininess );

// Here we simplify the light source to show the material effect.
// Here, we only specify the position of the light source. Other Default values: white light source.
// You can also add the definition of the light source to see the effect of the combination of the light source and material.
// It is precisely because they can be combined to produce more results than real life, which is exactly
// The charm of 3D technology.
Glfloat light_position [] = {1.0, 1.0, 1.0, 0.0 };
Gllightfv (gl_light0, gl_position, light_position );
// Glfloat light_diffuse [] = {0.0, 0.0, 1.0, 1.0 };
// Gllightfv (gl_light0, gl_diffuse, light_diffuse );

// Apply the light source settings
Glable (gl_lighting );
Glable (gl_light0 );

// Shade
// * In fact, Bai le, this is the famous Z-BUFFER ah ************//
Gldepthfunc (gl_less );
Glenable (gl_depth_test );
}

Void callback reshape (glsizei W, glsizei H)
{
Glviewport (0, 0, W, H );
Glmatrixmode (gl_projection );
Glloadidentity ();
If (W <= H)
Glortho (-2.0, 2.0,-2.0 * (glfloat) h/(glfloat) W,
2.0 * (glfloat) h/(glfloat) W,-10.0, 10.0 );
Else
Glortho (-2.0 * (glfloat) h/(glfloat) W,
2.0 * (glfloat) h/(glfloat) W,-2.0, 2.0,-10.0, 10.0 );

Glmatrixmode (gl_modelview );
Glloadidentity ();
}

Void draw (void)
{
Auxsolidsphere (1.0 );
}

Void callback display (void)
{
Glclear (gl_color_buffer_bit | gl_depth_buffer_bit );

Glloadidentity ();
Draw ();
Glflush ();
}
Void main (void)
{
Myinit ();

Auxreshapefunc (reshape );
Auxmainloop (Display );
}

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.