I have created a C++ OpenGL application (Windows XP, Visual Studio 2005) that renders terrain with NURBS surfaces. Everything works fine when I use a true array of control points with fixed dimensions but the app would be much more flexible if I could change the array dimensions at run time. I have been able to create arrays of pointers to simulate true arrays with square bracket indexing (I can read and write these ‘arrays’ just fine). I can also pass the ‘array’ to gluNurbsSurface() as an argument with no complaint from the compiler. When I use these ‘arrays’ at run time, no errors are reported by the error callback function. However, although gluNurbsSurface() takes about the same amount of time to ‘come back’ from processing the fake array as it does the real one, nothing appears to be rendered on the screen. Since gluNurbsSurface appears to be doing something, I’m guessing that it is getting confused by my pointers. I
Here’s some code to help explain the problem. If I do this, assuming I load the m_sample array with u, v, and height data:
GLfloat m_sample[200][200][3];
m_sample[u][v][0] = uval;
m_sample[u][v][1] = elevationVal;
m_sample[u][v][2] = vval;
gluNurbsSurface(m_theNurb, numberOfArbGridUKnots, uKnots, numberOfArbGridVKnots, vKnots, arbGridRows*3, 3, &m_sample[0][0][0]), ORDER, ORDER, GL_MAP2_VERTEX_3);
everything works ok and I see a rendered surface.
If I do this instead:
GLfloat ***m_sample;
and use allocate_3D to set it up (m_sample is in scope):
bool allocate_3D(int d1, int d2, int d3) {
if (m_sample!=0) {
return false;
}
m_sample=new GLfloat** [d1];
for (int i=0; i<d1; ++i) {
m_sample[i]=new GLfloat* [d2];
for (int j=0; j<d2; ++j) {
m_sample[i][j]=new GLfloat [d3];
for (int k=0; k<d3; ++k)
m_sample[i][j][k]=0;
}
}
return true;
}
then I can write my x,y,z data just as I could with the fixed array. But when I pass the dynamic version to gluNurbsSurface(), nothing appears to happen (no errors, but no rendered surface, either). Will gluNurbsSurface work with anything but a fixed array? Any other options? Any insights would be very welcome!
Jim