#include <windows.h>
#include <GL/GLAUX.h>
#include <GL/glut.h>
#include <math.h>
Glfloat Ctrlpoints[5][5][3] = {{ -2,0,0},{-1,1,0},{0,0,0},{1,-1,0},{2,0,0}},
{{ -2,0,-1},{-1,1,-1},{0,0,-1},{1,-1,-1},{2,0,-1}},
{{ -2,0,-2},{-1,1,-2},{0,0,-2},{1,-1,-2},{2,0,-2}},
{{ -2,0,-3},{-1,1,-3},{0,0,-3},{1,-1,-3},{2,0,-3}},
{{ -2,0,-4},{-1,1,-4},{0,0,-4},{1,-1,-4},{2,0,-4}}};
Glfloat mat_ambient[] = {0.1,0.1,0.1,1.0};
Glfloat mat_diffuse[] = {1.0,0.6,0.0,1.0};
Glfloat mat_specular[] = {1.0,1.0,1.0,1.0};
Glfloat light_ambient[] = {0.1,0.1,0.1,1.0};
Glfloat light_diffuse[] = {1.0,1.0,1.0,0.0};
Glfloat light_specular[] = {1.0,1.0,1.0,0.0};
Glfloat light_position[] = {2.0,23.0,-4.0,1.0};
void Myinit (void)
{
Glclearcolor (0.0,0.0,0.0,0.0);/Set Background color
/* Specify material parameters for the illumination model * *
GLMATERIALFV (gl_front,gl_ambient,mat_ambient);
GLMATERIALFV (Gl_front,gl_diffuse,mat_diffuse);
GLMATERIALFV (Gl_front,gl_specular,mat_specular);
Glmaterialf (gl_front,gl_shininess,60.0);
/* Set the light parameters/*
GLLIGHTFV (gl_light0,gl_ambient,light_ambient);
GLLIGHTFV (Gl_light0,gl_diffuse,light_diffuse);
GLLIGHTFV (Gl_light0,gl_specular,light_specular);
GLLIGHTFV (gl_light0,gl_position,light_position);
Glenable (gl_lighting);
Glenable (GL_LIGHT0);
/*enable depth Comparisons and update the depth buffer*/
Glenable (gl_depth_test);
/* Set SPECIAL effects * *
Glblendfunc (Gl_src_alpha,gl_one_minus_src_alpha);
Glhint (Gl_line_smooth_hint,gl_dont_care);
Glenable (Gl_blend);
Glenable (Gl_auto_normal);
Glenable (gl_normalize);
Glfrontface (GL_CW);
Glshademodel (Gl_smooth);
Glenable (Gl_line_smooth);
}
void Mydisplay (void)
{
Glclear (Gl_color_buffer_bit|gl_depth_buffer_bit);
glcolor3f (0.0,0.0,0.0);
Gltranslatef (0.0,-1.0,0.0);
Glrotatef (50.0,1.0,0.0,0.0);
Glpushmatrix ();
/* Draw Surface * *
Glenable (Gl_map2_vertex_3);
GLMAP2F (Gl_map2_vertex_3,0,1,3,5,0,1,15,5,&ctrlpoints[0][0][0]);
GLMAPGRID2F (10.0,0.0,1.0,10.0,0.0,1.0);
GLEVALMESH2 (gl_fill,0,10.0,0,10.0);
Glpopmatrix ();
Glutswapbuffers ();
}
void Myreshape (Glsizei w,glsizei h)
{
Glviewport (0,0,W,H);
Glmatrixmode (gl_projection);
Glloadidentity ();
Gluperspective (60.0, (glfloat) w/(glfloat) h,1.0,100.0);
Glmatrixmode (Gl_modelview);
Glloadidentity ();
Gltranslatef (0.0,0.0,-5.0);
}
int main (int argc,char * * argv)
{
/* Initialize * *
Glutinit (&ARGC,ARGV);
Glutinitdisplaymode (glut_double| glut_rgb| Glut_depth);
Glutinitwindowsize (400,400);
Glutinitwindowposition (200,200);
/* Create window * *
Glutcreatewindow ("Lighted bézier surface");
/* Draw and display * *
Myinit ();
Glutreshapefunc (Myreshape);
Glutdisplayfunc (Mydisplay);
/* Enter GLUT event handling cycle * *
Glutmainloop ();
return (0);
} |