View Full Version : Create NurbsSurface

10-05-2017, 02:40 PM

I am OpenGL beginner and I try to create a Nurbssurface. I have some troubles to understand the idea behind Nurbs.

I've already created a surface grid with random height Values.
I tried two ways:


2) VertexShader
Just a clipping

gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, VBO[0]);
glBufferData(OpenGL.GL_ARRAY_BUFFER,arrayOfVertice s,OpenGL.GL_STATIC_DRAW);
glVertexAttribPointer(0, width * height * 3, OpenGL.GL_FLOAT, false, 3 * width*height, IntPtr.Zero);

gl.DrawArrays(OpenGL.GL_TRIANGLE_STRIP, 0, arrayOfVertices.Length);

Now my Question is:

Do I have to create a Vertex- and Fragmentshader and (I dont know how) to combine it with glBeginSurface(theNurb);
Maybe with
glVertexAttribPointer(1, 3, OpenGL.GL_FLOAT, false, 6 * 4, IntPtr.Zero//NurbsObject maybe???);

Or I have already created a nurbs surface:

private void Draw()

glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
float[,,] ctrlpoints = new float[4, 4, 3] {
{ { -1.5f, 0.0f, -1.5f}, { -0.5f, 0.0f,-1.5f}, { 0.5f, 0.0f,-1.5f }, { 1.5f, 0.0f, -1.5f} },
{ { -1.5f, 1.0f, -0.5f}, { -0.5f, 1.00f , -0.5f }, { 0.5f, 1.0f, -0.5f }, { 1.5f, 0.0f, -0.5f} },
{ { -1.5f, 0.0f, 0.5f}, { -0.5f, 1.0f, 0.5f} , { 0.5f, 0.5f, 0.5f }, { 1.5f, 0.0f, 0.5f} },
{ { -1.5f, 0.0f, 1.5f}, { -0.5f, 0.0f, 1.5f}, { 0.5f, 0.0f, 1.5f }, { 1.5f, 0.0f, 1.5f} }


theNurb = new GLUnurbsObj();

//CreateGrid(4, 4);
gl.Rotate(rot_PosX, rot_PosY, rot_PosZ);
gl.Translate(trans_PosX, trans_PosY, trans_PosZ);

theNurb = gl.NewNurbsRenderer();
gl.NurbsProperty(theNurb, (int)OpenGL.GLU_DISPLAY_MODE, (float)displayMode);
//Begin drawing a NURBS surface.
gl.Color(1, 5, 1);
//Draw the surface.
gl.NurbsSurface(theNurb, // The internal nurbs object.
sKnots.Length, // Number of s-knots.
sKnots, // The s-knots themselves.
tKnots.Length, // The number of t-knots.
tKnots, // The t-knots themselves.
/*rowCount*/4 * 3, // The size of a row of control points.
/*ColumnCount*/3, // The size of a control points.
ToFloatArray(), // The control points.
4, // The order, i.e degree + 1.
4, // The order, i.e degree + 1.
OpenGL.GL_MAP2_VERTEX_3); // Type of data to generate.
// End the surface.


Now here we have static controlpoints. I haven't understood what do you have to do if you have an surface with variable heights. Should I order the Controlpoints as an 1D array to exactly the same order how I would create 2 Triangles? Like (0.0,z,1.0), (0.0,z,0.0), (1.0,0.0), (1.0,1.0) ?
And where can I give my indices to the Nurbssurface that the vertices will draw in different colors?

Besides I understood if you have an surface grid for example 40x40 I have to divide it in 4x4 patches to use NurbsSurface ?

I just looking for some advices or good tutorials to create smooth NurbsSurfaces with different colors. Do we have an old way and new way to create it, like glBegin, glEnd and Shaders?

Thanks for every advice.