#include <windows.h>
#include <GL/glut.h>
Glunurbsobj *THENURB1;
Glunurbsobj *thenurb2;
Glfloat Ctrlpoints[5][5][3] = {{ -3,0.5,0},{-1,1.5,0},{-2,2,0},{1,-1,0},{-5,0,0}},
{{ -3,0.5,-1},{-1,1.5,-1},{-2,2,-1},{1,-1,-1},{-5,0,-1}},
{{ -3,0.5,-2},{-1,1.5,-2},{-2,2,-2},{1,-1,-2},{-5,0,-2}},
{{ -3,0.5,-3},{-1,1.5,-3},{-2,2,-3},{1,-1,-3},{-5,0,-3}},
{{ -3,0.5,-4},{-1,1.5,-4},{-2,2,-4},{1,-1,-4},{-5,0,-4}}};//control point
Glfloat mat_diffuse[] = {1.0,0.5,0.1,1.0};
Glfloat mat_specular[] = {1.0,1.0,1.0,1.0};
Glfloat mat_shininess[] = {100.0};
Glfloat light_position[] = {0.0,-10.0,0.0,1.0};
void Myinit (void)
{
Glclearcolor (1.0,1.0,1.0,0.0);/Set Background color
/* Specify material parameters for the illumination model * *
GLMATERIALFV (Gl_front,gl_diffuse,mat_diffuse);
GLMATERIALFV (Gl_front,gl_specular,mat_specular);
GLMATERIALFV (gl_front,gl_shininess,mat_shininess);
GLLIGHTFV (gl_front,gl_position,light_position)//Set Lighting parameters
Gllightmodeli (gl_light_model_two_side,gl_true)//Set Lighting model parameters
/* Activate the light * *
Glenable (gl_lighting);
Glenable (GL_LIGHT0);
Gldepthfunc (gl_lequal);
Glenable (gl_depth_test);
Glenable (gl_lequal);
Glenable (Gl_auto_normal);
Glenable (gl_normalize);
/* Set SPECIAL effects * *
Glblendfunc (Gl_src_alpha,gl_one_minus_src_alpha);
Glhint (Gl_line_smooth_hint,gl_dont_care);
Glenable (Gl_blend);
Glfrontface (GL_CW);
Glshademodel (Gl_smooth);
Glenable (Gl_line_smooth);
THENURB1 = Glunewnurbsrenderer ();//Create a NURBs object TheNurb1
Glunurbsproperty (thenurb1,glu_sampling_tolerance,25.0);
Glunurbsproperty (Thenurb1,glu_display_mode,glu_outline_polygon);
THENURB2 = Glunewnurbsrenderer ();//Create a NURBs object TheNurb2
Glunurbsproperty (thenurb2,glu_sampling_tolerance,25.0);
Glunurbsproperty (Thenurb2,glu_display_mode,glu_fill);
}
int spin = 0;
/* Receive keyboard instruction * *
static void MyKey (unsigned char key,int x,int y)
{
Switch (key)
{
Case ' d ':
Spin = spin + 1;
Glrotatef (spin,1.0,1.0,0.0);
Glutpostredisplay ();
Break
Case 27:
Exit (0);
Default
Break
}
}
/* Draw Surface * *
void Mydisplay (void)
{
Glfloat knots[10] = {0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0};
Glclear (Gl_color_buffer_bit|gl_depth_buffer_bit);
Glrotatef (50.0,1.0,1.0,0.0);
/* First Surface * *
Glpushmatrix ();
Gltranslatef (1.0,0.0,0.0);
Glubeginsurface (THENURB1);
/* Define surface shape * *
Glunurbssurface (Thenurb1,10,knots,10,knots,5*3,3,&ctrlpoints[0][0][0],5,5,gl_map2_vertex_3);
Gluendsurface (THENURB1);
Glpopmatrix ();
/* Second Surface * *
Glpushmatrix ();
Gltranslatef (7.0,0.0,0.0);
Glubeginsurface (THENURB2);
/* Define surface shape * *
Glunurbssurface (Thenurb2,10,knots,10,knots,5*3,3,&ctrlpoints[0][0][0],5,5,gl_map2_vertex_3);
Gluendsurface (THENURB2);
Glpopmatrix ();
Glutswapbuffers ();
}
void Myreshape (Glsizei w,glsizei h)
{
Glviewport (0,0,W,H);
Glmatrixmode (gl_projection);
Glloadidentity ();
Gluperspective (50.0, (Glfloat) w/(glfloat) h,1.0,15.0);
Glmatrixmode (Gl_modelview);
Glloadidentity ();
Gltranslatef (0.0,0.0,-9.0);
}
int main (int argc,char * * argv)
{
/* Initialize * *
Glutinit (&ARGC,ARGV);
Glutinitdisplaymode (glut_double| glut_rgb| Glut_depth);
Glutinitwindowsize (600,400);
Glutinitwindowposition (200,200);
/* Create window * *
Glutcreatewindow ("NURBS surface");
/* Draw and display * *
Myinit ();
Glutkeyboardfunc (MyKey);
Glutreshapefunc (Myreshape);
Glutdisplayfunc (Mydisplay);
/* Enter GLUT event handling cycle * *
Glutmainloop ();
return (0);
} |