hi all ,
i’m going to create a nurbs surface in opengl with Qt. And I’m following the Chapter 12 - OpenGL Programming Guide
But when I implement in my project it only displays the points .not the surface. What would be the issue. Any clue. I’m taking values from geom_bsplineSurface
and giving it to the function.
Here is what i have done up to now.
void OpenGLView::init_surface1()
{
nbPolesU = bSplineSurfe->NbUPoles();
nbPolesV = bSplineSurfe->NbVPoles();
orderU = bSplineSurfe->UDegree() + 1;
orderV = bSplineSurfe->VDegree() + 1;
ctlpoi1 = new GLfloat * *[nbPolesU];
for (int iU = 0; iU < nbPolesU; iU++)
{
ctlpoi1[iU] = new GLfloat * [nbPolesV];
for (int iV = 0; iV < nbPolesV; iV++)
{
ctlpoi1[iU][iV] = new GLfloat[3];
}
}
for (int iU = 1; iU <= nbPolesU; iU++)
{
for (int iV = 1; iV <= nbPolesV; iV++)
{
gp_Pnt pnt = bSplineSurf->Pole(iU, iV);
ctlpoi1[iU - 1][iV - 1][0] = pnt.X();
ctlpoi1[iU - 1][iV - 1][1] = pnt.Y();
ctlpoi1[iU - 1][iV - 1][2] = pnt.Z();
}
}
nKnotsU = bSplineSurf->NbUKnots();
int totalU = 0;
//ukot = new float[nKnotsU];
std::vector<float>arr;
for (int i = 1; i <= nKnotsU; i++) {
totalU += bSplineSurf->UMultiplicity(i);
}
ukot = new float[totalU];
int currentIndex = 0;
for (int i = 1; i <= nKnotsU; i++)
{
double knotU = bSplineSurf->UKnot(i);
int multU = bSplineSurf->UMultiplicity(i);
for (int j = 0; j < multU; j++)
{
//arr[currentIndex] = knotU;
ukot[currentIndex] = knotU;
currentIndex++;
}
}
nKnotsV = bSplineSurf->NbVKnots();
int totalV = 0;
//ukot = new float[nKnotsU];
for (int i = 1; i <= nKnotsV; i++) {
totalV += bSplineSurf->VMultiplicity(i);
}
vkot = new float[totalV];
int currentIndexV = 0;
for (int i = 1; i <= nKnotsV; i++)
{
double knotV = bSplineSurf->VKnot(i);
int multV = bSplineSurf->VMultiplicity(i);
for (int j = 0; j < multV; j++)
{
//arr[currentIndex] = knotU;
vkot[currentIndexV] = knotV;
currentIndexV++;
}
}
}
void OpenGLView::initializeGL()
{
qglClearColor(Qt::black);
glEnable(GL_DEPTH_TEST);
///////////
glDepthFunc(GL_LEQUAL);
GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 100.0 };
glClearColor(0.0, 0.0, 0.0, 0.0);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
theNurb = gluNewNurbsRenderer();
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
//gluNurbsCallback(theNurb, GLU_ERROR,(GLvoid(*)()) errorCallback);
}
void OpenGLView::updatepoints()
{
init_surface1();
init_surface();
}
void OpenGLView::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glScaled(zoomScale, zoomScale, zoomScale);
glTranslatef(100 * panX, 100 * panY, 0.0f);
glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT_AND_BACK);
glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
int x = nbPolesV * 3;
draw(theNurb, nKnotsU, ukot, nKnotsV, vkot,x, 3, &ctlpoi1[0][0][0], orderU, orderV);
//draw1();
}
void OpenGLView::draw(GLUnurbs* theNurb, int nKnotsU, float* UKot, int nKnotsV, float* VKot, GLint u_stride, GLint v_stride, GLfloat* ctlpoi, int orderU, int orderV) {
GLfloat knots[8] = { 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 };
int i, j;
//int nbPolesU, nbPolesV;
//////////////
/////////////////
glPushMatrix();
gluBeginSurface(theNurb);
gluNurbsSurface(theNurb,
nKnotsU, UKot, nKnotsV, VKot,
u_stride, v_stride, &ctlpoi1[0][0][0],
orderU, orderV, GL_MAP2_VERTEX_3);
gluEndSurface(theNurb);
if (true) {
glPointSize(5);
//glDisable(GL_LIGHTING);
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_POINTS);
for (i = 0; i < nbPolesU; i++) {
for (j = 0; j < nbPolesV; j++) {
glVertex3f(ctlpoi1[i][j][0],
ctlpoi1[i][j][1], ctlpoi1[i][j][2]);
}
}
glEnd();
glEnable(GL_LIGHTING);
}
glPopMatrix();
glFlush();
}