4

I want to create a NurbsSurface in OpenGL. I use a grid of control points size of 40x48. Besides I create indices in order to determine the order of vertices.

enter image description here

In this way I created my surface of triangles. Just to avoid misunderstandings. I have float[] vertices=x1,y1,z1,x2,y2,z2,x3,y3,z3....... and float[] indices= 1,6,2,7,3,8.... Now I don't want to draw triangles. I would like to interpolate the surface points. I thought about nurbs or B-Splines.

The clue is: In order to determine the Nurbs algorithms I have to interpolate patch by patch. In my understanding one patch is defined as for example points 1,6,2,7 or 2,7,3,8(Please open the picture).

First of all I created the vertices and indices in order to use a vertexshader. But actually it would be enough to draw it on the old way. In this case I would determine vertices and indices as follows:

float[] vertices= v1,v2,v3... with v=x,y,z 

and

float[] indices= 1,6,2,7,3,8....

In OpenGL, there is a Nurbs function ready to use. glNewNurbsRenderer. So I can render a patch easily. Unfortunately, I fail at the point, how to stitch the patches together. I found an explanation Teapot example but (maybe I have become obsessed by this) I can't transfer the solution to my case. Can you help?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
TimDor
  • 49
  • 1
  • 8

1 Answers1

3

You have set of control points from which you want to draw surface.

There are two ways you can go about this

  1. Which is described in Teapot example link you have provided. Calculate the vertices from control points and pass then down the graphics pipeline with GL_TRIANGLE as topology. Please remember graphics hardware needs triangulated data in order to draw. Follow this link which shows how to evaluate vertices from control points http://www.glprogramming.com/red/chapter12.html

  2. You can prepare path of your control points and use tessellation shaders to triangulate and stitch those points.

    For this you prepare set of control points as patch use GL_PATCH primitive and pass it to tessellation control shader. In this you will specify what tessellation level you want. Depending on that your patch will be tessellated by another fixed function stage known as Primitive Generator. Then your generated vertices will be pass to tessellation evaluation shader in which you can fine tune. Here you can specify outer or inner tessellation level which will further subdivide your patch.

    I would suggest you put your VBO and IBO like you have with control points and when drawing use GL_PATCH primitive. Follow below tutorial about how to use tessellation shader to draw nurb surfaces.

Note : Second method I have suggested is kind of tricky and you will have to read lot of research papers.

I think if you dont want to go with modern pipeline then I suggest go with option 1.

  • Okay, I believe I mixed up vertices and control points. How do I need to use glNurbssurface after I sent my triangles down to graphics pipeline? Just follow the nurbs command and give all control points as a float in? Besides I found a geometry shader code http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.95.9155&rep=rep1&type=pdf, could I use this as well? Since I've understood, within the graphics pipeline, the geometry shader is located right after the vertex shader – TimDor Oct 12 '17 at 15:31
  • As mentioned in Option 1 you can use gluNurbSurface functionality. Also they have shown how to calculate vertex position from control points. Once you have vertex position fill them in VBO and just do normal drawing using GL_TRIANGLE. – Paritosh Kulkarni Oct 12 '17 at 15:33
  • Yes you can use geometry shader too. But please remember Geometry shaders are very bad for performance as Input assembly stage has to run before and after geometry shader. Geometry shader actually comes after tessellation shader but If you are not using them then yes Geometry shader is after vertex shader. – Paritosh Kulkarni Oct 12 '17 at 15:40
  • Thanks, I think you cleared it up. Just a last question do you have a nice tutorial for option 2, tessellation shaders? Because the program should run in real-time after some development time. – TimDor Oct 12 '17 at 15:46
  • Sure Please see following link. https://github.com/asylum2010/Asylum_Tutorials/tree/master/ShaderTutors/52_Tessellation – Paritosh Kulkarni Oct 12 '17 at 15:51