#include <windows.h>
#include <GL/glut.h>
Glunurbsobj *thenurb;
Glfloat Ctrlpoints[12][3] = {{4,0,0},{2.828,2.828,0},{0,4,0},{-2.828,2.828,0},
{ -4,0,0},{-2.828,-2.828,0},{0,-4,0},{2.828,-2.828,0},
{4,0,0},{2.828,2.828,0},{0,4,0},{2.828,2.828,0}};//Control point
Glfloat color[12][3]={{1.0,0.0,0.0},{1.0,1.0,0.0},{0.0,1.0,0.0},{-1.0,1.0,0.0},
{ -1.0,0.0,0.0},{-1.0,-1.0,0.0},{0.0,-1.0,0.0},{1.0,-1.0,0.0},
{1.0,0.0,0.0},{1.0,1.0,0.0},{0.0,1.0,0.0},{1.0,1.0,0.0}};
Glfloat knots[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
void Myinit (void)
{
Glclearcolor (1.0,1.0,1.0,0.0);/Set Background color
Thenurb = Glunewnurbsrenderer ();//Create a NURBs object thenurb
Glunurbsproperty (thenurb,glu_sampling_tolerance,10);
}
/* Draw Curve * *
void Mydisplay (void)
{
int i;
Glclear (Gl_color_buffer_bit|gl_depth_buffer_bit);
glcolor3f (0.0,0.0,0.0);
Gllinewidth (3.0);
/* Draw Curve * *
Glubegincurve (THENURB);
Glunurbscurve (Thenurb,15,knots,3,&ctrlpoints[0][0],3,gl_map1_vertex_3);
Glunurbscurve (thenurb,15,knots,3,&ctrlpoints[0][0],3,gl_map1_color_4);
Gluendcurve (THENURB);
/* Draw Point * *
glcolor3f (1.0,0.0,0.0);
Glpointsize (5.0);
Glbegin (gl_points);
for (i = 0;i < 8;i++)
GLVERTEX2FV (&ctrlpoints[i][0]);
Glend ();
Glutswapbuffers ();
}
void Myreshape (Glsizei w,glsizei h)
{
Glviewport (0,0,W,H);
Glmatrixmode (gl_projection);
Glloadidentity ();
if (w <=h)
Glortho ( -10.0,10.0,-10.0* (glfloat) h/(glfloat) w,10.0* glfloat (h/) glfloat);
Else
Glortho ( -10.0* (glfloat) w/(glfloat) h,10.0* glfloat (w/) glfloat);
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 curve");
/* Draw and display * *
Myinit ();
Glutreshapefunc (Myreshape);
Glutdisplayfunc (Mydisplay);
Glutmainloop ();
return (0);
} |