#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include "glut.h"
#include <vector>
#include <iostream>
using namespace std;
GLUnurbsObj* nobj;
GLfloat ctlarray[][3] = { { -0.9, -0.8, 0.0 },
{ -0.2, 0.8, 0.0 },
{ 0.2, -0.5, 0.0 },
{ 0.9, 0.8, 0.0 } };
GLfloat knot[60];
int degree = 3;
int pointCount = 4;
int knotSize = 0;
void Init() {
glClearColor(1.0, 1.0, 1.0, 1.0);
nobj = gluNewNurbsRenderer();
gluNurbsProperty(nobj, GLU_SAMPLING_TOLERANCE, 25.0);
}
void generateKnot() {
int k = degree + 1;
int n = pointCount - 1;
for (int i = 0; i < n + k + 1; ++i) {
if (i < k)
knot[i] = 0;
else if (i < n + 1)
knot[i] = i - k + 1;
else
knot[i] = n - k + 2;
}
knotSize = n + k + 1;
}
void Display() {
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(3.0);
for (int i = 0; i < 4; ++i) {
degree = i;
generateKnot();
glColor3f(3. / (i + 1), 2. / (i + 1), 1. / (i + 1));
gluNurbsCurve(nobj, knotSize, knot, 3, &ctlarray[0][0], degree + 1, GL_MAP1_VERTEX_3);
}
glPointSize(4.0);
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POINTS);
for (int i = 0; i < 4; ++i) {
glVertex3fv(ctlarray[i]);
}
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutInitWindowSize(1024, 720);
glutInitWindowPosition(100, 100);
glutCreateWindow("olol");
Init();
glutDisplayFunc(Display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}